Skip to content

Commit 23396b6

Browse files
committed
Suppress boost warning with cmake policy, and add support for using installed gtest.
1 parent dc7a24f commit 23396b6

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

CMakeLists.txt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
2525
include(DetectVersion)
2626

2727
cmake_policy(SET CMP0048 NEW) ## set VERSION as documented by the project() command.
28-
cmake_policy(SET CMP0076 NEW) ## accept new policy
28+
cmake_policy(SET CMP0076 NEW) ## accept new policy for converting relative paths to absolute.
29+
cmake_policy(SET CMP0167 NEW) ## accept new policy to search for the upstream ``BoostConfig.cmake``
2930

3031
if(NOT CMAKE_CXX_STANDARD)
3132
set(CMAKE_CXX_STANDARD 20) ## compile with C++20 support
@@ -99,6 +100,7 @@ endif()
99100
option(GTL_BUILD_TESTS "Whether or not to build the tests" ${GTL_MASTER_PROJECT})
100101
option(GTL_BUILD_EXAMPLES "Whether or not to build the examples" ${GTL_MASTER_PROJECT})
101102
option(GTL_BUILD_BENCHMARKS "Whether or not to build the benchmarks" ${GTL_MASTER_PROJECT})
103+
option(GTL_DOWNLOAD_GTEST "Whether to download gtest or use installed version" ON)
102104

103105
if(MSVC)
104106
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/bigobj>")
@@ -112,12 +114,22 @@ endif()
112114
if (GTL_BUILD_TESTS)
113115

114116
if (NOT GTL_GTEST_LIBS)
115-
include(cmake/DownloadGTest.cmake)
117+
if (NOT GTL_DOWNLOAD_GTEST)
118+
find_package(GTest CONFIG)
119+
if (GTest_FOUND)
120+
set(GTL_GTEST_LIBS GTest::gmock_main)
121+
else()
122+
set(GTL_DOWNLOAD_GTEST ON)
123+
endif()
124+
endif()
125+
if (GTL_DOWNLOAD_GTEST)
126+
include(cmake/DownloadGTest.cmake)
116127

117-
gtl_check_target(gtest)
118-
gtl_check_target(gtest_main)
119-
gtl_check_target(gmock)
120-
set(GTL_GTEST_LIBS gmock_main)
128+
gtl_check_target(gtest)
129+
gtl_check_target(gtest_main)
130+
gtl_check_target(gmock)
131+
set(GTL_GTEST_LIBS gmock_main)
132+
endif()
121133
endif()
122134

123135
enable_testing()
@@ -206,7 +218,7 @@ endif()
206218
gtl_cc_app(ex_mt_memoize SRCS examples/memoize/mt_memoize.cpp ${natvis} LIBS Threads::Threads)
207219
gtl_cc_app(ex_mt_memoize_lru SRCS examples/memoize/mt_memoize_lru.cpp ${natvis} LIBS Threads::Threads)
208220

209-
find_package(Boost 1.70.0)
221+
find_package(Boost 1.70.0 QUIET)
210222
if (Boost_FOUND)
211223
gtl_cc_app(ex_custom_pointer SRCS examples/hmap/custom_pointer.cpp ${natvis})
212224
target_include_directories(ex_custom_pointer PRIVATE ${Boost_INCLUDE_DIRS})

0 commit comments

Comments
 (0)