projects/guix·blob java-team · refs

103 lines · 3.9 KiB

1from https://github.com/google/cppdap/pull/124
2
3From 40d9eaf3b6eca2ab8d5558e8935d56a75bd97183 Mon Sep 17 00:00:00 2001
4From: topazus <[email protected]>
5Date: Wed, 27 Dec 2023 19:56:49 +0800
6Subject: [PATCH] CMake: add CPPDAP_USE_EXTERNAL_GTEST_PACKAGE option
7
8---
9 CMakeLists.txt | 35 +++++++++++++++++++++++++----------
10 1 file changed, 25 insertions(+), 10 deletions(-)
11
12diff --git a/CMakeLists.txt b/CMakeLists.txt
13index 1b3c321..7292f3c 100644
14--- a/CMakeLists.txt
15+++ b/CMakeLists.txt
16@@ -40,6 +40,7 @@ option_if_not_defined(CPPDAP_INSTALL_VSCODE_EXAMPLES "Build and install dap exam
17 option_if_not_defined(CPPDAP_USE_EXTERNAL_NLOHMANN_JSON_PACKAGE "Use nlohmann_json with find_package() instead of building internal submodule" OFF)
18 option_if_not_defined(CPPDAP_USE_EXTERNAL_RAPIDJSON_PACKAGE "Use RapidJSON with find_package()" OFF)
19 option_if_not_defined(CPPDAP_USE_EXTERNAL_JSONCPP_PACKAGE "Use JsonCpp with find_package()" OFF)
20+option_if_not_defined(CPPDAP_USE_EXTERNAL_GTEST_PACKAGE "Use googletest with find_package()" OFF)
21
22 ###########################################################
23 # Directories
24@@ -59,7 +60,7 @@ set_if_not_defined(CPPDAP_GOOGLETEST_DIR ${CPPDAP_THIRD_PARTY_DIR}/googletest)
25 ###########################################################
26 # Submodules
27 ###########################################################
28-if(CPPDAP_BUILD_TESTS)
29+if(CPPDAP_BUILD_TESTS AND NOT CPPDAP_USE_EXTERNAL_GTEST_PACKAGE)
30 if(NOT EXISTS ${CPPDAP_GOOGLETEST_DIR}/.git)
31 message(WARNING "third_party/googletest submodule missing.")
32 message(WARNING "Run: `git submodule update --init` to build tests.")
33@@ -161,7 +162,7 @@ function(cppdap_set_json_links target)
34 target_link_libraries(${target} PRIVATE JsonCpp::JsonCpp)
35 else()
36 target_include_directories(${target} PRIVATE "${CPPDAP_JSON_DIR}/include/")
37- endif()
38+ endif()
39 endfunction(cppdap_set_json_links)
40
41 function(cppdap_set_target_options target)
42@@ -247,7 +248,7 @@ write_basic_package_version_file(
43 )
44 configure_package_config_file(
45 ${CPPDAP_CMAKE_CONFIG_TEMPLATE}
46- "${CPPDAP_CMAKE_PROJECT_CONFIG_FILE}"
47+ "${CPPDAP_CMAKE_PROJECT_CONFIG_FILE}"
48 INSTALL_DESTINATION ${CPPDAP_CONFIG_INSTALL_DIR}
49 )
50
51@@ -276,6 +277,8 @@ DESTINATION ${CPPDAP_CONFIG_INSTALL_DIR})
52
53 # tests
54 if(CPPDAP_BUILD_TESTS)
55+ enable_testing()
56+
57 set(DAP_TEST_LIST
58 ${CPPDAP_SRC_DIR}/any_test.cpp
59 ${CPPDAP_SRC_DIR}/chan_test.cpp
60@@ -290,16 +293,24 @@ if(CPPDAP_BUILD_TESTS)
61 ${CPPDAP_SRC_DIR}/traits_test.cpp
62 ${CPPDAP_SRC_DIR}/typeinfo_test.cpp
63 ${CPPDAP_SRC_DIR}/variant_test.cpp
64- ${CPPDAP_GOOGLETEST_DIR}/googletest/src/gtest-all.cc
65 )
66
67- set(DAP_TEST_INCLUDE_DIR
68- ${CPPDAP_GOOGLETEST_DIR}/googlemock/include/
69- ${CPPDAP_GOOGLETEST_DIR}/googletest/
70- ${CPPDAP_GOOGLETEST_DIR}/googletest/include/
71- )
72+ if(CPPDAP_USE_EXTERNAL_GTEST_PACKAGE)
73+ find_package(GTest REQUIRED)
74+ else()
75+ list(APPEND DAP_TEST_LIST
76+ ${CPPDAP_GOOGLETEST_DIR}/googletest/src/gtest-all.cc
77+ )
78+
79+ set(DAP_TEST_INCLUDE_DIR
80+ ${CPPDAP_GOOGLETEST_DIR}/googlemock/include/
81+ ${CPPDAP_GOOGLETEST_DIR}/googletest/
82+ ${CPPDAP_GOOGLETEST_DIR}/googletest/include/
83+ )
84+ endif()
85
86 add_executable(cppdap-unittests ${DAP_TEST_LIST})
87+ add_test(NAME cppdap-unittests COMMAND cppdap-unittests)
88
89 target_include_directories(cppdap-unittests PUBLIC ${DAP_TEST_INCLUDE_DIR} )
90 set_target_properties(cppdap-unittests PROPERTIES
91@@ -312,7 +323,11 @@ if(CPPDAP_BUILD_TESTS)
92 endif()
93
94 cppdap_set_target_options(cppdap-unittests)
95- target_link_libraries(cppdap-unittests PRIVATE cppdap)
96+ if(CPPDAP_USE_EXTERNAL_GTEST_PACKAGE)
97+ target_link_libraries(cppdap-unittests PRIVATE cppdap GTest::gtest)
98+ else()
99+ target_link_libraries(cppdap-unittests PRIVATE cppdap)
100+ endif()
101 endif(CPPDAP_BUILD_TESTS)
102
103 # fuzzer