chore: tweak CMakeLists

- use DtkBuildHelper functions
- tests/CMakeLists.txt tweak
This commit is contained in:
ck 2023-08-14 17:01:22 +08:00 committed by mike
parent 4c50be9afb
commit b9cf2a22be
2 changed files with 61 additions and 97 deletions

View File

@ -23,8 +23,7 @@ if(LINUX)
endif()
endif()
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Xml)
find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED)
find_package(DtkBuildHelper REQUIRED)
# start text encoding
find_package(ICU REQUIRED COMPONENTS uc)

View File

@ -14,15 +14,16 @@ add_link_options(-fsanitize=address)
add_definitions(-DPREFIX="${CMAKE_INSTALL_PREFIX}")
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
if(LINUX)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS DBus)
find_package(PkgConfig REQUIRED)
if("${QT_VERSION_MAJOR}" STREQUAL "5")
pkg_check_modules(QGSettings REQUIRED IMPORTED_TARGET gsettings-qt)
endif()
if(BUILD_WITH_SYSTEMD)
pkg_check_modules(Systemd REQUIRED IMPORTED_TARGET libsystemd)
endif()
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS DBus)
find_package(PkgConfig REQUIRED)
if("${QT_VERSION_MAJOR}" STREQUAL "5")
pkg_check_modules(QGSettings REQUIRED IMPORTED_TARGET gsettings-qt)
endif()
if(BUILD_WITH_SYSTEMD)
pkg_check_modules(Systemd REQUIRED IMPORTED_TARGET libsystemd)
endif()
endif()
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Xml)
@ -30,112 +31,77 @@ find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Concurrent)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Test)
find_package(GTest REQUIRED)
# for test.so
set(TEST_SO_NAME vtabletest${DTK_VERSION_MAJOR})
add_subdirectory(./testso)
# test
file(GLOB TEST_HEADER
ut_.*h
)
file(GLOB TEST_SOURCE
*.cpp
)
file(GLOB TEST_HEADER ut_.*h)
file(GLOB TEST_SOURCE *.cpp)
file(GLOB FackDBus
"./fakedbus/*.h"
"./fakedbus/*.cpp"
"./fakedbus/*.h"
"./fakedbus/*.cpp"
)
if(DTK_VERSION_MAJOR)
list(REMOVE_ITEM TEST_SOURCE "${CMAKE_CURRENT_LIST_DIR}/ut_gsettingsbackend.cpp")
list(REMOVE_ITEM TEST_SOURCE "${CMAKE_CURRENT_LIST_DIR}/ut_dasync.cpp")
list(REMOVE_ITEM TEST_SOURCE "${CMAKE_CURRENT_LIST_DIR}/ut_gsettingsbackend.cpp")
list(REMOVE_ITEM TEST_SOURCE "${CMAKE_CURRENT_LIST_DIR}/ut_dasync.cpp")
endif()
set(test_SRC
${TEST_HEADER}
${TEST_SOURCE}
${FackDBus}
${TEST_HEADER}
${TEST_SOURCE}
${FackDBus}
)
# end test
add_executable(${BIN_NAME}
${test_SRC}
./data.qrc
)
add_dependencies(${BIN_NAME} ${TEST_SO_NAME})
target_link_libraries(
${BIN_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::CorePrivate
Qt${QT_VERSION_MAJOR}::Xml
Qt${QT_VERSION_MAJOR}::Concurrent
Qt${QT_VERSION_MAJOR}::Test
${GTEST_LIBRARIES}
${LIB_NAME}
-l${TEST_SO_NAME}
)
# end test
if(LINUX)
add_executable(${BIN_NAME}
${test_SRC}
./data.qrc
)
add_dependencies(${BIN_NAME} ${TEST_SO_NAME})
target_link_libraries(
${BIN_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::CorePrivate
Qt${QT_VERSION_MAJOR}::DBus
Qt${QT_VERSION_MAJOR}::Xml
Qt${QT_VERSION_MAJOR}::Concurrent
Qt${QT_VERSION_MAJOR}::Test
${GTEST_LIBRARIES}
${LIB_NAME}
-lpthread
-lm
-lgcov
-l${TEST_SO_NAME}
-ldl
)
if(${QT_VERSION_MAJOR} STREQUAL "5")
target_link_libraries(
${BIN_NAME} PRIVATE
PkgConfig::QGSettings
)
endif()
if(${QT_VERSION_MAJOR} STREQUAL "5")
target_link_libraries(
${BIN_NAME} PRIVATE
PkgConfig::QGSettings
)
endif()
if(BUILD_WITH_SYSTEMD)
target_link_libraries(
${BIN_NAME} PRIVATE
PkgConfig::Systemd
)
endif()
if(BUILD_WITH_SYSTEMD)
target_link_libraries(
${BIN_NAME} PRIVATE
PkgConfig::Systemd
${BIN_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::DBus
-lpthread
-lm
-lgcov
-ldl
)
endif()
endif() #end LINUX
target_link_directories(${BIN_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/testso/)
target_include_directories(${BIN_NAME} PUBLIC
../include/util/
../include/dci/
../include/log/
../include/base/
../include/base/private/
../include/global/
../include/DtkCore/
../include/settings/
../include/filesystem/
../include/
../src/filesystem/private/
./testso/
)
else()
add_executable(${BIN_NAME}
${test_SRC}
./data.qrc
)
add_dependencies(${BIN_NAME} ${TEST_SO_NAME})
target_link_libraries(
${BIN_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::CorePrivate
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Xml
Qt${QT_VERSION_MAJOR}::Concurrent
Qt${QT_VERSION_MAJOR}::Test
${GTEST_LIBRARIES}
${LIB_NAME}
-lpthread
-lm
-l${TEST_SO_NAME}
)
target_link_directories(${BIN_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/testso/)
target_include_directories( ${BIN_NAME} PUBLIC
target_link_directories(${BIN_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/testso/)
target_include_directories( ${BIN_NAME} PUBLIC
../include/util/
../include/dci/
../include/log/
@ -147,7 +113,6 @@ else()
../include/filesystem/
../include/
./testso/
)
endif()
)
add_test(NAME ${BIN_NAME} COMMAND ${BIN_NAME})