Add option to build tests with external gtest, closes #130

This commit is contained in:
Jeremy 2024-05-28 20:56:54 -05:00
parent b2bff57d81
commit 2499fa4a67
No known key found for this signature in database
GPG Key ID: 19AA8270105E8EB4
2 changed files with 15 additions and 9 deletions

View File

@ -168,6 +168,7 @@ option(CPPTRACE_SANITIZER_BUILD "" OFF)
option(CPPTRACE_WERROR_BUILD "" OFF) option(CPPTRACE_WERROR_BUILD "" OFF)
option(CPPTRACE_POSITION_INDEPENDENT_CODE "" ON) option(CPPTRACE_POSITION_INDEPENDENT_CODE "" ON)
option(CPPTRACE_IS_GH_ACTIONS "" OFF) option(CPPTRACE_IS_GH_ACTIONS "" OFF)
option(CPPTRACE_USE_EXTERNAL_GTEST "" OFF)
mark_as_advanced( mark_as_advanced(
CPPTRACE_BACKTRACE_PATH CPPTRACE_BACKTRACE_PATH
@ -179,4 +180,5 @@ mark_as_advanced(
CPPTRACE_VCPKG CPPTRACE_VCPKG
CPPTRACE_CONDA_LIBDWARF_WEIRDNESS CPPTRACE_CONDA_LIBDWARF_WEIRDNESS
CPPTRACE_IS_GH_ACTIONS CPPTRACE_IS_GH_ACTIONS
CPPTRACE_USE_EXTERNAL_GTEST
) )

View File

@ -38,15 +38,19 @@ endif()
# primarily a workaround for github actions issue https://github.com/actions/runner-images/issues/8659 # primarily a workaround for github actions issue https://github.com/actions/runner-images/issues/8659
if(NOT CPPTRACE_IS_GH_ACTIONS) if(NOT CPPTRACE_IS_GH_ACTIONS)
include(FetchContent) if(CPPTRACE_USE_EXTERNAL_GTEST)
FetchContent_Declare( find_package(GTest)
googletest else()
GIT_REPOSITORY "https://github.com/google/googletest.git" include(FetchContent)
GIT_TAG f8d7d77c06936315286eb55f8de22cd23c188571 # v1.14.0 FetchContent_Declare(
) googletest
# For Windows: Prevent overriding the parent project's compiler/linker settings GIT_REPOSITORY "https://github.com/google/googletest.git"
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) GIT_TAG f8d7d77c06936315286eb55f8de22cd23c188571 # v1.14.0
FetchContent_MakeAvailable(googletest) )
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endif()
add_executable(unittest unittest.cpp) add_executable(unittest unittest.cpp)
target_compile_features(unittest PRIVATE cxx_std_20) target_compile_features(unittest PRIVATE cxx_std_20)