diff --git a/cmake/OptionVariables.cmake b/cmake/OptionVariables.cmake index f65ac4f..0d2366a 100644 --- a/cmake/OptionVariables.cmake +++ b/cmake/OptionVariables.cmake @@ -168,6 +168,7 @@ option(CPPTRACE_SANITIZER_BUILD "" OFF) option(CPPTRACE_WERROR_BUILD "" OFF) option(CPPTRACE_POSITION_INDEPENDENT_CODE "" ON) option(CPPTRACE_IS_GH_ACTIONS "" OFF) +option(CPPTRACE_USE_EXTERNAL_GTEST "" OFF) mark_as_advanced( CPPTRACE_BACKTRACE_PATH @@ -179,4 +180,5 @@ mark_as_advanced( CPPTRACE_VCPKG CPPTRACE_CONDA_LIBDWARF_WEIRDNESS CPPTRACE_IS_GH_ACTIONS + CPPTRACE_USE_EXTERNAL_GTEST ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9ee7be0..785cf68 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -38,15 +38,19 @@ endif() # primarily a workaround for github actions issue https://github.com/actions/runner-images/issues/8659 if(NOT CPPTRACE_IS_GH_ACTIONS) - include(FetchContent) - FetchContent_Declare( - googletest - GIT_REPOSITORY "https://github.com/google/googletest.git" - GIT_TAG f8d7d77c06936315286eb55f8de22cd23c188571 # v1.14.0 - ) - # For Windows: Prevent overriding the parent project's compiler/linker settings - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - FetchContent_MakeAvailable(googletest) + if(CPPTRACE_USE_EXTERNAL_GTEST) + find_package(GTest) + else() + include(FetchContent) + FetchContent_Declare( + googletest + GIT_REPOSITORY "https://github.com/google/googletest.git" + GIT_TAG f8d7d77c06936315286eb55f8de22cd23c188571 # v1.14.0 + ) + # 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) target_compile_features(unittest PRIVATE cxx_std_20)