include_guard() include(FetchContent) set(INSTALL_GTEST OFF CACHE BOOL "Install GoogleTest" FORCE) set(gtest_force_shared_crt ON CACHE BOOL "Use the shared MSVC runtime for GoogleTest" FORCE) FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.18.0 GIT_SHALLOW TRUE ) FetchContent_MakeAvailable(googletest) set_property(TARGET gtest gtest_main gmock gmock_main PROPERTY FOLDER third_party/GoogleTest) # GoogleTest adds exception flags of its own; keep it aligned with project targets. foreach(_test_dependency IN ITEMS gtest gtest_main gmock gmock_main) get_target_property(_test_compile_flags ${_test_dependency} COMPILE_FLAGS) string(REGEX REPLACE "[-/]EHsc|[-/]D_HAS_EXCEPTIONS=1|-fexceptions" "" _test_compile_flags "${_test_compile_flags}") set_property(TARGET ${_test_dependency} PROPERTY COMPILE_FLAGS "${_test_compile_flags}") endforeach()