Skip to content

Commit b11e1d5

Browse files
heysion18202781743
authored andcommitted
fix: modernize CMake configuration for notification server tests
Replaced global CMAKE_CXX_FLAGS with target-specific compile options using target_compile_options() for better encapsulation. Removed redundant include(GoogleTest) since find_package(GTest) is already called. Log: Modernize CMake configuration for notification server tests Influence: 1. Verify notifyserverapplet_tests builds successfully 2. Confirm no CMake configuration warnings fix: 现代化通知服务器测试的 CMake 配置 使用 target_compile_options() 替代全局 CMAKE_CXX_FLAGS, 提供更好的封装性。移除冗余的 include(GoogleTest)。 Log: 现代化通知服务器测试的 CMake 配置 Influence: 1. 验证 notifyserverapplet_tests 构建成功 2. 确认没有 CMake 配置警告
1 parent 24e67c0 commit b11e1d5

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

tests/panels/notification/server/CMakeLists.txt

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
# SPDX-License-Identifier: GPL-3.0-or-later
44

55
find_package(GTest REQUIRED)
6-
find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core Test DBus)
7-
8-
include(GoogleTest)
6+
find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS
7+
Core
8+
Test
9+
DBus
10+
Sql
11+
)
912

1013
add_executable(notifyserverapplet_tests
1114
${CMAKE_SOURCE_DIR}/panels/notification/server/notifyserverapplet.h
@@ -16,6 +19,7 @@ add_executable(notifyserverapplet_tests
1619
${CMAKE_SOURCE_DIR}/panels/notification/server/dbusadaptor.cpp
1720
${CMAKE_SOURCE_DIR}/panels/notification/server/notificationsetting.h
1821
${CMAKE_SOURCE_DIR}/panels/notification/server/notificationsetting.cpp
22+
1923
${CMAKE_SOURCE_DIR}/panels/notification/common/notifyentity.h
2024
${CMAKE_SOURCE_DIR}/panels/notification/common/notifyentity.cpp
2125
${CMAKE_SOURCE_DIR}/panels/notification/common/dataaccessor.h
@@ -25,28 +29,43 @@ add_executable(notifyserverapplet_tests
2529
${CMAKE_SOURCE_DIR}/panels/notification/common/memoryaccessor.cpp
2630
${CMAKE_SOURCE_DIR}/panels/notification/common/notifysetting.h
2731
${CMAKE_SOURCE_DIR}/panels/notification/common/notifysetting.cpp
32+
2833
notifyserverapplet_test.cpp
2934
)
3035

31-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
36+
target_compile_options(notifyserverapplet_tests PRIVATE
37+
-fvisibility=hidden
38+
-fvisibility-inlines-hidden
39+
)
40+
41+
target_include_directories(notifyserverapplet_tests PRIVATE
42+
${CMAKE_SOURCE_DIR}/panels/notification/server
43+
${CMAKE_SOURCE_DIR}/panels/notification/common
44+
${CMAKE_SOURCE_DIR}/frame
45+
)
3246

3347
target_link_libraries(notifyserverapplet_tests PRIVATE
3448
GTest::GTest
3549
GTest::gmock
3650
GTest::gmock_main
3751
GTest::Main
52+
3853
Qt${QT_VERSION_MAJOR}::Core
3954
Qt${QT_VERSION_MAJOR}::Test
4055
Qt${QT_VERSION_MAJOR}::DBus
4156
Qt${QT_VERSION_MAJOR}::Sql
57+
4258
dde-shell-frame
4359
ds-notification-shared
4460
)
4561

46-
target_include_directories(notifyserverapplet_tests PRIVATE
47-
${CMAKE_SOURCE_DIR}/panels/notification/server/
48-
${CMAKE_SOURCE_DIR}/panels/notification/common/
49-
${CMAKE_SOURCE_DIR}/frame/
62+
# fix gtest not found runpath
63+
target_link_options(notifyserverapplet_tests PRIVATE
64+
"-Wl,-rpath,${CMAKE_BINARY_DIR}/frame"
65+
"-Wl,-rpath,${CMAKE_BINARY_DIR}/panels/notification"
5066
)
5167

52-
gtest_discover_tests(notifyserverapplet_tests)
68+
gtest_discover_tests(
69+
notifyserverapplet_tests
70+
DISCOVERY_MODE PRE_TEST
71+
)

0 commit comments

Comments
 (0)