diff --git a/CMakeLists.txt b/CMakeLists.txt index 0408aac7..5aa67331 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -212,14 +212,19 @@ if(UNITS_BUILD_FUZZ_TARGETS) add_subdirectory(FuzzTargets) elseif(UNITS_ENABLE_TESTS AND NOT CMAKE_VERSION VERSION_LESS 3.13) include(updateGitSubmodules) - enable_testing() - if(NOT EXISTS "${PROJECT_SOURCE_DIR}/ThirdParty/googletest/CMakeLists.txt") - submod_update(ThirdParty/googletest) + if(UNITS_ENABLE_SUBMODULE_UPDATE) + enable_testing() + if(NOT EXISTS "${PROJECT_SOURCE_DIR}/ThirdParty/googletest/CMakeLists.txt") + submod_update(ThirdParty/googletest) + endif() + else() + include(FindPkgConfig) + find_package(GTest REQUIRED) + pkg_check_modules(GMock gmock REQUIRED) endif() if(BUILD_TESTING) add_subdirectory(test) endif() - elseif(UNITS_ENABLE_TESTS) message(WARNING "UNITS unit tests only supported under cmake 3.13 or greater") endif() diff --git a/config/AddGoogletest.cmake b/config/AddGoogletest.cmake index feb302db..681184aa 100644 --- a/config/AddGoogletest.cmake +++ b/config/AddGoogletest.cmake @@ -35,20 +35,26 @@ set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS CACHE INTERNAL "" ) -add_subdirectory( - ${CMAKE_SOURCE_DIR}/ThirdParty/googletest ${CMAKE_BINARY_DIR}/ThirdParty/googletest - EXCLUDE_FROM_ALL -) - -if(NOT MSVC) - target_compile_options(gtest PUBLIC "-Wno-undef" "-Wno-c++17-attribute-extensions") - target_compile_options(gmock PUBLIC "-Wno-undef" "-Wno-c++17-attribute-extensions") - target_compile_options( - gtest_main PUBLIC "-Wno-undef" "-Wno-c++17-attribute-extensions" - ) - target_compile_options( - gmock_main PUBLIC "-Wno-undef" "-Wno-c++17-attribute-extensions" +if(NOT GTest_FOUND) + add_subdirectory( + ${CMAKE_SOURCE_DIR}/ThirdParty/googletest + ${CMAKE_BINARY_DIR}/ThirdParty/googletest EXCLUDE_FROM_ALL ) + + if(NOT MSVC) + target_compile_options( + gtest PUBLIC "-Wno-undef" "-Wno-c++17-attribute-extensions" + ) + target_compile_options( + gmock PUBLIC "-Wno-undef" "-Wno-c++17-attribute-extensions" + ) + target_compile_options( + gtest_main PUBLIC "-Wno-undef" "-Wno-c++17-attribute-extensions" + ) + target_compile_options( + gmock_main PUBLIC "-Wno-undef" "-Wno-c++17-attribute-extensions" + ) + endif() endif() if(GOOGLE_TEST_INDIVIDUAL) @@ -90,7 +96,9 @@ hide_variable(BUILD_GTEST) hide_variable(INSTALL_GTEST) hide_variable(GTEST_HAS_ABSL) -set_target_properties(gtest gtest_main gmock gmock_main PROPERTIES FOLDER "Extern") +if(NOT GTest_FOUND) + set_target_properties(gtest gtest_main gmock gmock_main PROPERTIES FOLDER "Extern") +endif() if(MSVC) # add_compile_options( /wd4459)