Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit 7b69999

Browse files
pemensikjimmy-park
andauthored
Reuse gtest on system (yhirose#1493)
* Reuse gtest on the system Try to use gtest on the system if found. Avoid using recent CMake features. * Set CMP0135 only when using FetchContent * Add /bigobj option for MSVC * Support also cmake between 3.14 and 3.20 Older versions provided only GTest::Main target, not currently used gtest_main. Provide backward compatibility also to old cmake versions. * Remove redundant variable checking --------- Co-authored-by: Jiwoo Park <[email protected]>
1 parent c7e959a commit 7b69999

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

test/CMakeLists.txt

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
1-
cmake_policy(SET CMP0135 NEW)
1+
find_package(GTest)
22

3-
include(FetchContent)
4-
include(GoogleTest)
3+
if(GTest_FOUND)
4+
if(NOT TARGET GTest::gtest_main AND TARGET GTest::Main)
5+
# CMake <3.20
6+
add_library(GTest::gtest_main INTERFACE IMPORTED)
7+
target_link_libraries(GTest::gtest_main INTERFACE GTest::Main)
8+
endif()
9+
else()
10+
if(POLICY CMP0135)
11+
cmake_policy(SET CMP0135 NEW)
12+
endif()
513

6-
set(BUILD_GMOCK OFF)
7-
set(INSTALL_GTEST OFF)
8-
set(gtest_force_shared_crt ON)
14+
include(FetchContent)
915

10-
FetchContent_Declare(
11-
gtest
12-
URL https://github.com/google/googletest/archive/main.tar.gz
13-
)
14-
FetchContent_MakeAvailable(gtest)
16+
set(BUILD_GMOCK OFF)
17+
set(INSTALL_GTEST OFF)
18+
set(gtest_force_shared_crt ON)
19+
20+
FetchContent_Declare(
21+
gtest
22+
URL https://github.com/google/googletest/archive/main.tar.gz
23+
)
24+
FetchContent_MakeAvailable(gtest)
25+
endif()
1526

1627
add_executable(httplib-test test.cc)
17-
target_compile_options(httplib-test PRIVATE "$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
28+
target_compile_options(httplib-test PRIVATE "$<$<CXX_COMPILER_ID:MSVC>:/utf-8;/bigobj>")
1829
target_link_libraries(httplib-test PRIVATE httplib GTest::gtest_main)
1930
gtest_discover_tests(httplib-test)
2031

0 commit comments

Comments
 (0)