Skip to content

Commit b7a2745

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

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

CMakeLists.txt

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ 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+
if(POLICY CMP0167)
30+
cmake_policy(SET CMP0167 NEW) ## accept new policy to search for the upstream ``BoostConfig.cmake``
31+
endif()
2932

3033
if(NOT CMAKE_CXX_STANDARD)
3134
set(CMAKE_CXX_STANDARD 20) ## compile with C++20 support
@@ -99,6 +102,7 @@ endif()
99102
option(GTL_BUILD_TESTS "Whether or not to build the tests" ${GTL_MASTER_PROJECT})
100103
option(GTL_BUILD_EXAMPLES "Whether or not to build the examples" ${GTL_MASTER_PROJECT})
101104
option(GTL_BUILD_BENCHMARKS "Whether or not to build the benchmarks" ${GTL_MASTER_PROJECT})
105+
option(GTL_DOWNLOAD_GTEST "Whether to download gtest or use installed version" ON)
102106

103107
if(MSVC)
104108
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/bigobj>")
@@ -112,12 +116,22 @@ endif()
112116
if (GTL_BUILD_TESTS)
113117

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

117-
gtl_check_target(gtest)
118-
gtl_check_target(gtest_main)
119-
gtl_check_target(gmock)
120-
set(GTL_GTEST_LIBS gmock_main)
130+
gtl_check_target(gtest)
131+
gtl_check_target(gtest_main)
132+
gtl_check_target(gmock)
133+
set(GTL_GTEST_LIBS gmock_main)
134+
endif()
121135
endif()
122136

123137
enable_testing()
@@ -206,7 +220,7 @@ endif()
206220
gtl_cc_app(ex_mt_memoize SRCS examples/memoize/mt_memoize.cpp ${natvis} LIBS Threads::Threads)
207221
gtl_cc_app(ex_mt_memoize_lru SRCS examples/memoize/mt_memoize_lru.cpp ${natvis} LIBS Threads::Threads)
208222

209-
find_package(Boost 1.70.0)
223+
find_package(Boost 1.70.0 QUIET)
210224
if (Boost_FOUND)
211225
gtl_cc_app(ex_custom_pointer SRCS examples/hmap/custom_pointer.cpp ${natvis})
212226
target_include_directories(ex_custom_pointer PRIVATE ${Boost_INCLUDE_DIRS})

0 commit comments

Comments
 (0)