mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-10 01:33:53 +00:00
Reuse gtest on system (#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 <jiwoo_90@naver.com>
This commit is contained in:
parent
c7e959a948
commit
7b69999c37
@ -1,20 +1,31 @@
|
|||||||
cmake_policy(SET CMP0135 NEW)
|
find_package(GTest)
|
||||||
|
|
||||||
include(FetchContent)
|
if(GTest_FOUND)
|
||||||
include(GoogleTest)
|
if(NOT TARGET GTest::gtest_main AND TARGET GTest::Main)
|
||||||
|
# CMake <3.20
|
||||||
|
add_library(GTest::gtest_main INTERFACE IMPORTED)
|
||||||
|
target_link_libraries(GTest::gtest_main INTERFACE GTest::Main)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
if(POLICY CMP0135)
|
||||||
|
cmake_policy(SET CMP0135 NEW)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(BUILD_GMOCK OFF)
|
include(FetchContent)
|
||||||
set(INSTALL_GTEST OFF)
|
|
||||||
set(gtest_force_shared_crt ON)
|
|
||||||
|
|
||||||
FetchContent_Declare(
|
set(BUILD_GMOCK OFF)
|
||||||
gtest
|
set(INSTALL_GTEST OFF)
|
||||||
URL https://github.com/google/googletest/archive/main.tar.gz
|
set(gtest_force_shared_crt ON)
|
||||||
)
|
|
||||||
FetchContent_MakeAvailable(gtest)
|
FetchContent_Declare(
|
||||||
|
gtest
|
||||||
|
URL https://github.com/google/googletest/archive/main.tar.gz
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(gtest)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_executable(httplib-test test.cc)
|
add_executable(httplib-test test.cc)
|
||||||
target_compile_options(httplib-test PRIVATE "$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
|
target_compile_options(httplib-test PRIVATE "$<$<CXX_COMPILER_ID:MSVC>:/utf-8;/bigobj>")
|
||||||
target_link_libraries(httplib-test PRIVATE httplib GTest::gtest_main)
|
target_link_libraries(httplib-test PRIVATE httplib GTest::gtest_main)
|
||||||
gtest_discover_tests(httplib-test)
|
gtest_discover_tests(httplib-test)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user