From: Gianfranco Costamagna Date: Sat, 14 Oct 2023 07:23:02 +0000 (+0200) Subject: [PATCH] Update cmakelists to use system googletest if available. X-Git-Tag: archive/raspbian/0.8.0+dfsg-6+rpi1^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=835c6e171e05b02b870a50a0e078f89b1f29b4fa;p=yaml-cpp.git [PATCH] Update cmakelists to use system googletest if available. There is no need to use the embedded gtest code copy in Linux systems, if they already provide the googletest framework system-wide. Search for it, and fallback to the embedded one if the system one is not detected. This patch has been also contributed by Simon Quigley Gbp-Pq: Name 1035.patch --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 46dc180..09b3a0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ option(YAML_CPP_BUILD_TOOLS "Enable parse tools" ON) option(YAML_BUILD_SHARED_LIBS "Build yaml-cpp shared library" ${BUILD_SHARED_LIBS}) option(YAML_CPP_INSTALL "Enable generation of yaml-cpp install targets" ${YAML_CPP_MAIN_PROJECT}) option(YAML_CPP_FORMAT_SOURCE "Format source" ON) +option(YAML_USE_SYSTEM_GTEST "Use system googletest if found" OFF) cmake_dependent_option(YAML_CPP_BUILD_TESTS "Enable yaml-cpp tests" OFF "BUILD_TESTING;YAML_CPP_MAIN_PROJECT" OFF) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 351b03f..895a44f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,11 +4,17 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) set(BUILD_MOCK ON CACHE BOOL "" FORCE) set(CMAKE_POLICY_DEFAULT_CMP0048 NEW) -add_subdirectory( - "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.11.0" - "${CMAKE_CURRENT_BINARY_DIR}/prefix") - -include_directories(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.11.0/googletest/include") +if(YAML_USE_SYSTEM_GTEST) + find_package(GTest) + if (NOT GTEST_FOUND) + message(FATAL_ERROR "system googletest was requested but not found") + endif() +else() + add_subdirectory( + "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.11.0" + "${CMAKE_CURRENT_BINARY_DIR}/prefix") + include_directories(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.11.0/googletest/include") +endif() set(test-new-api-pattern "new-api/*.cpp") set(test-source-pattern "*.cpp" "integration/*.cpp" "node/*.cpp") @@ -38,6 +44,7 @@ target_link_libraries(yaml-cpp-tests PRIVATE Threads::Threads yaml-cpp + gtest gmock) set_property(TARGET yaml-cpp-tests PROPERTY CXX_STANDARD_REQUIRED ON)