| 1 |
# 方便 test 脚本中调用 |
| 2 |
set(BIN_NAME "ut-DtkCore") |
| 3 |
|
| 4 |
set(CMAKE_INCLUDE_CURRENT_DIR ON) |
| 5 |
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 6 |
|
| 7 |
set(CMAKE_AUTOMOC ON) |
| 8 |
set(CMAKE_AUTOUIC ON) |
| 9 |
set(CMAKE_AUTORCC ON) |
| 10 |
# dbus |
| 11 |
set(CMAKE_CXX_FLAGS "-fno-access-control") |
| 12 |
add_compile_options(-fsanitize=address) |
| 13 |
add_link_options(-fsanitize=address) |
| 14 |
|
| 15 |
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui) |
| 16 |
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) |
| 17 |
|
| 18 |
if(LINUX) |
| 19 |
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS DBus) |
| 20 |
find_package(PkgConfig REQUIRED) |
| 21 |
if("${QT_VERSION_MAJOR}" STREQUAL "5") |
| 22 |
pkg_check_modules(QGSettings REQUIRED IMPORTED_TARGET gsettings-qt) |
| 23 |
endif() |
| 24 |
endif() |
| 25 |
|
| 26 |
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Xml) |
| 27 |
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Concurrent) |
| 28 |
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Test) |
| 29 |
find_package(GTest REQUIRED) |
| 30 |
|
| 31 |
# for test.so |
| 32 |
set(TEST_SO_NAME vtabletest${DTK_VERSION_MAJOR}) |
| 33 |
add_subdirectory(./testso) |
| 34 |
|
| 35 |
# test |
| 36 |
file(GLOB TEST_HEADER ut_.*h) |
| 37 |
file(GLOB TEST_SOURCE *.cpp) |
| 38 |
|
| 39 |
file(GLOB FackDBus |
| 40 |
"./fakedbus/*.h" |
| 41 |
"./fakedbus/*.cpp" |
| 42 |
) |
| 43 |
|
| 44 |
if(DTK_VERSION_MAJOR) |
| 45 |
list(REMOVE_ITEM TEST_SOURCE "${CMAKE_CURRENT_LIST_DIR}/ut_gsettingsbackend.cpp") |
| 46 |
list(REMOVE_ITEM TEST_SOURCE "${CMAKE_CURRENT_LIST_DIR}/ut_dasync.cpp") |
| 47 |
endif() |
| 48 |
|
| 49 |
set(test_SRC |
| 50 |
${TEST_HEADER} |
| 51 |
${TEST_SOURCE} |
| 52 |
${FackDBus} |
| 53 |
) |
| 54 |
# end test |
| 55 |
|
| 56 |
add_executable(${BIN_NAME} |
| 57 |
${test_SRC} |
| 58 |
./data.qrc |
| 59 |
) |
| 60 |
|
| 61 |
target_compile_definitions(${BIN_NAME} PUBLIC |
| 62 |
PREFIX="${DSG_PREFIX_PATH}" |
| 63 |
DSYSINFO_PREFIX="${DSYSINFO_PREFIX}" |
| 64 |
) |
| 65 |
|
| 66 |
add_dependencies(${BIN_NAME} ${TEST_SO_NAME}) |
| 67 |
target_link_libraries( |
| 68 |
${BIN_NAME} PRIVATE |
| 69 |
Qt${QT_VERSION_MAJOR}::Gui |
| 70 |
Qt${QT_VERSION_MAJOR}::Core |
| 71 |
Qt${QT_VERSION_MAJOR}::CorePrivate |
| 72 |
Qt${QT_VERSION_MAJOR}::Xml |
| 73 |
Qt${QT_VERSION_MAJOR}::Concurrent |
| 74 |
Qt${QT_VERSION_MAJOR}::Test |
| 75 |
${GTEST_LIBRARIES} |
| 76 |
${LIB_NAME} |
| 77 |
-l${TEST_SO_NAME} |
| 78 |
) |
| 79 |
|
| 80 |
if(LINUX) |
| 81 |
if(${QT_VERSION_MAJOR} STREQUAL "5") |
| 82 |
target_link_libraries( |
| 83 |
${BIN_NAME} PRIVATE |
| 84 |
PkgConfig::QGSettings |
| 85 |
) |
| 86 |
endif() |
| 87 |
|
| 88 |
target_link_libraries( |
| 89 |
${BIN_NAME} PRIVATE |
| 90 |
Qt${QT_VERSION_MAJOR}::DBus |
| 91 |
-lpthread |
| 92 |
-lm |
| 93 |
-lgcov |
| 94 |
-ldl |
| 95 |
) |
| 96 |
endif() #end LINUX |
| 97 |
|
| 98 |
target_link_directories(${BIN_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/testso/) |
| 99 |
target_include_directories( ${BIN_NAME} PUBLIC |
| 100 |
../include/util/ |
| 101 |
../include/dci/ |
| 102 |
../include/log/ |
| 103 |
../include/base/ |
| 104 |
../include/base/private/ |
| 105 |
../include/global/ |
| 106 |
../include/DtkCore/ |
| 107 |
../include/settings/ |
| 108 |
../include/filesystem/ |
| 109 |
../include/ |
| 110 |
./testso/ |
| 111 |
) |
| 112 |
|
| 113 |
add_test(NAME ${BIN_NAME} COMMAND ${BIN_NAME}) |