From 6e9831a9b8e8c1bc93ecc06148c8577d343ffc89 Mon Sep 17 00:00:00 2001 From: Zhang Dingyuan Date: Sun, 25 Jun 2023 11:47:18 +0800 Subject: [PATCH] port to macOS --- CMakeLists.txt | 12 +++++ dtkcore.cmake | 2 +- src/CMakeLists.txt | 82 ++++++++++++----------------------- src/glob.cmake | 8 +--- tools/CMakeLists.txt | 6 ++- tools/settings/CMakeLists.txt | 10 +++-- 6 files changed, 54 insertions(+), 66 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bce068c9..1ee43f55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,4 +24,16 @@ else() message(SEND_ERROR "not support Prject Version ${PROJECT_VERSION}.") endif() +if(APPLE) + # Force use qt6 on macOS + set(QT_VERSION_MAJOR "6") + set(DTK_VERSION_MAJOR "6") + + set(CMAKE_THREAD_LIBS_INIT "-lpthread") + set(CMAKE_HAVE_THREADS_LIBRARY 1) + set(CMAKE_USE_WIN32_THREADS_INIT 0) + set(CMAKE_USE_PTHREADS_INIT 1) + set(THREADS_PREFER_PTHREAD_FLAG ON) +endif() + include(dtkcore.cmake) diff --git a/dtkcore.cmake b/dtkcore.cmake index 9e6a2e41..9f69aec8 100644 --- a/dtkcore.cmake +++ b/dtkcore.cmake @@ -39,7 +39,7 @@ if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() -if(NOT MSVC) +if(LINUX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Wextra") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--as-needed") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed -pie") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 55d73bdc..8fe6a5f9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,10 +9,9 @@ set(CMAKE_AUTORCC ON) set (DSG_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}" CACHE STRING "PREFIX of DSG_DATA_DIRS") add_definitions(-DPREFIX="${DSG_PREFIX_PATH}") add_definitions(-DLIBDTKCORE_LIBRARY) -find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core DBus Xml) +find_package(PkgConfig REQUIRED) if(LINUX) - find_package(PkgConfig REQUIRED) - find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS DBus) if("${QT_VERSION_MAJOR}" STREQUAL "5") pkg_check_modules(QGSettings REQUIRED IMPORTED_TARGET gsettings-qt) #Dtk6 removed. endif() @@ -21,11 +20,11 @@ if(LINUX) pkg_check_modules(Systemd REQUIRED IMPORTED_TARGET libsystemd) endif() endif() -find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Xml) # start text encoding find_package(ICU REQUIRED COMPONENTS uc) -pkg_check_modules(uchardet REQUIRED uchardet) +find_package(Iconv REQUIRED) +pkg_check_modules(uchardet REQUIRED IMPORTED_TARGET uchardet) # end text encoding # start base @@ -53,27 +52,30 @@ include(util/util.cmake) #GLOB include(glob.cmake) #endGLOG + +add_library(${LIB_NAME} SHARED + ${base_SRCS} + ${dci_SRCS} + ${filesystem_SRCS} + ${log_SRCS} + ${settings_SRC} + ${utils_SRC} + ${glob_SRC} +) +target_link_libraries( + ${LIB_NAME} PUBLIC + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::DBus + Qt${QT_VERSION_MAJOR}::Xml +) +target_link_libraries(${LIB_NAME} PRIVATE + ICU::uc + Qt${QT_VERSION_MAJOR}::CorePrivate + PkgConfig::uchardet + Iconv +) + if(LINUX) - add_library(${LIB_NAME} SHARED - ${base_SRCS} - ${dci_SRCS} - ${filesystem_SRCS} - ${log_SRCS} - ${settings_SRC} - ${utils_SRC} - ${glob_SRC} - ) - target_link_libraries( - ${LIB_NAME} PUBLIC - Qt${QT_VERSION_MAJOR}::Core - Qt${QT_VERSION_MAJOR}::DBus - Qt${QT_VERSION_MAJOR}::Xml - ) - target_link_libraries(${LIB_NAME} PRIVATE - ICU::uc - Qt${QT_VERSION_MAJOR}::CorePrivate - uchardet - ) if("${QT_VERSION_MAJOR}" STREQUAL "5") target_link_libraries(${LIB_NAME} PRIVATE PkgConfig::QGSettings @@ -85,41 +87,13 @@ if(LINUX) ) add_definitions(-DBUILD_WITH_SYSTEMD) endif() - -else() - add_library(${LIB_NAME} SHARED - ${base_SRCS} - ${dci_SRCS} - ${filesystem_SRCS} - ${log_SRCS} - ${settings_SRC} - ${utils_SRC} - ${glob_SRC} - ) - target_link_libraries( - ${LIB_NAME} PUBLIC - Qt${QT_VERSION_MAJOR}::Core - Qt${QT_VERSION_MAJOR}::Xml - ) - target_link_libraries(${LIB_NAME} PRIVATE - ICU::uc - Qt${QT_VERSION_MAJOR}::CorePrivate - uchardet - ) - if("${QT_VERSION_MAJOR}" STREQUAL "5") - target_link_libraries(${LIB_NAME} PRIVATE - PkgConfig::QGSettings - ) - endif() endif() + set_target_properties(${LIB_NAME} PROPERTIES VERSION ${CMAKE_PROJECT_VERSION} SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR} EXPORT_NAME Core ) -target_include_directories(${LIB_NAME} PRIVATE - ${uchardet_INCLUDE_DIRS} -) target_include_directories(${LIB_NAME} PUBLIC $ $ diff --git a/src/glob.cmake b/src/glob.cmake index c1ad6dd2..d98c3070 100644 --- a/src/glob.cmake +++ b/src/glob.cmake @@ -6,6 +6,7 @@ set(OUTER_SOURCE ${CMAKE_CURRENT_LIST_DIR}/dsecurestring.cpp ${CMAKE_CURRENT_LIST_DIR}/ddesktopentry.cpp ${CMAKE_CURRENT_LIST_DIR}/dtkcore_global.cpp + ${CMAKE_CURRENT_LIST_DIR}/dconfigfile.cpp ) set(OUTER_HEADER ${CMAKE_CURRENT_LIST_DIR}/../include/global/dtkcore_global.h @@ -15,18 +16,13 @@ set(OUTER_HEADER ${CMAKE_CURRENT_LIST_DIR}/../include/global/dlicenseinfo.h ${CMAKE_CURRENT_LIST_DIR}/../include/global/dsecurestring.h ${CMAKE_CURRENT_LIST_DIR}/../include/global/ddesktopentry.h + ${CMAKE_CURRENT_LIST_DIR}/../include/global/dconfigfile.h ) if(LINUX) if(DEFINED D_DSG_APP_DATA_FALLBACK) add_definitions(-DD_DSG_APP_DATA_FALLBACK="${D_DSG_APP_DATA_FALLBACK}") endif() - list(APPEND OUTER_SOURCE - ${CMAKE_CURRENT_LIST_DIR}/dconfigfile.cpp - ) - list(APPEND OUTER_HEADER - ${CMAKE_CURRENT_LIST_DIR}/../include/global/dconfigfile.h - ) # generic dbus interfaces if(NOT DEFINED DTK_DISABLE_DBUS_CONFIG) include(${CMAKE_CURRENT_LIST_DIR}/dbus/dbus.cmake) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index f3ef2a58..e7777267 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,5 +1,7 @@ add_subdirectory(dci) -add_subdirectory(deepin-os-release) -add_subdirectory(qdbusxml2cpp) +if(LINUX) + add_subdirectory(deepin-os-release) + add_subdirectory(qdbusxml2cpp) +endif() add_subdirectory(settings) add_subdirectory(ch2py) diff --git a/tools/settings/CMakeLists.txt b/tools/settings/CMakeLists.txt index c56bbed8..0a82b047 100644 --- a/tools/settings/CMakeLists.txt +++ b/tools/settings/CMakeLists.txt @@ -5,8 +5,12 @@ find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Xml) if(${QT_VERSION_MAJOR} STREQUAL "5") - find_package(PkgConfig REQUIRED) - pkg_check_modules(QGSettings REQUIRED IMPORTED_TARGET gsettings-qt) + if(LINUX) + find_package(PkgConfig REQUIRED) + pkg_check_modules(QGSettings REQUIRED IMPORTED_TARGET gsettings-qt) + elseif(APPLE) + find_package(PkgConfig REQUIRED) + endif() endif() add_executable(${BIN_NAME} @@ -22,7 +26,7 @@ target_link_libraries( if(${QT_VERSION_MAJOR} STREQUAL "5") target_link_libraries( ${BIN_NAME} PRIVATE - PkgConfig::QGSettings + # PkgConfig::QGSettings ) endif()