From e207b4942f4ad175ee73a052a9d0783473a52970 Mon Sep 17 00:00:00 2001 From: topazus Date: Sat, 16 Dec 2023 17:59:12 +0800 Subject: [PATCH] CMake: add UNIFEX_USE_SYSTEM_GTEST option --- CMakeLists.txt | 19 +++++++++++++------ test/CMakeLists.txt | 10 +++++----- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc7a6547e..7046da4e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,8 @@ include(unifex_options) include(unifex_env) include(unifex_flags) +option(UNIFEX_USE_SYSTEM_GTEST "Use system GTest dependency" OFF) + # The library target is defined in the source subdirectory add_subdirectory(source) @@ -32,12 +34,17 @@ if (PROJECT_IS_TOP_LEVEL) endif(UNIFEX_BUILD_EXAMPLES) # Tests do use gtest if(BUILD_TESTING) - include(gtest) - target_compile_features(gtest PUBLIC cxx_std_17) - target_compile_features(gtest_main PUBLIC cxx_std_17) - if (UNIFEX_CXX_COMPILER_CLANGCL) - target_compile_options(gtest PRIVATE -Wno-error) - target_compile_options(gtest_main PRIVATE -Wno-error) + if(UNIFEX_USE_SYSTEM_GTEST) + find_package(GTest CONFIG REQUIRED) + # find_package(GMock REQUIRED) + else() + include(gtest) + target_compile_features(gtest PUBLIC cxx_std_17) + target_compile_features(gtest_main PUBLIC cxx_std_17) + if (UNIFEX_CXX_COMPILER_CLANGCL) + target_compile_options(gtest PRIVATE -Wno-error) + target_compile_options(gtest_main PRIVATE -Wno-error) + endif() endif() add_subdirectory(test) endif(BUILD_TESTING) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 942b8eb05..581981df4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,7 +8,7 @@ foreach(file-path ${test-sources}) string( REPLACE ".cpp" "" file-path-without-ext ${file-path} ) get_filename_component(file-name ${file-path-without-ext} NAME) add_executable( ${file-name} ${file-path}) - target_link_libraries(${file-name} PUBLIC unifex gtest_main) + target_link_libraries(${file-name} PUBLIC unifex GTest::gtest_main) add_test(NAME "test-${file-name}" COMMAND ${file-name}) endforeach() @@ -16,7 +16,7 @@ if(CXX_MEMORY_RESOURCE_HAVE_PMR) target_link_libraries(any_unique_test PUBLIC std::memory_resource) endif() -target_link_libraries(any_sender_of_test PUBLIC gmock) -target_link_libraries(async_manual_reset_event_test PUBLIC gmock) -target_link_libraries(async_scope_test PUBLIC gmock) -target_link_libraries(async_scope_v0_test PUBLIC gmock) +target_link_libraries(any_sender_of_test PUBLIC GTest::gmock_main) +target_link_libraries(async_manual_reset_event_test PUBLIC GTest::gmock_main) +target_link_libraries(async_scope_test PUBLIC GTest::gmock_main) +target_link_libraries(async_scope_v0_test PUBLIC GTest::gmock_main)