From f8fddac56b65ff8fd2f3e9b7b2ff25072cd13e92 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Sun, 7 Jul 2024 17:46:49 -0700 Subject: [PATCH] [build] Add DART_USE_SYSTEM_GOOGLETEST option --- CHANGELOG.md | 3 +++ CMakeLists.txt | 1 + tests/CMakeLists.txt | 28 ++++++++++++++++------------ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3265976c2718c..c08d6ec438bd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ * macOS 14 / Clang 15 / arm64 * Windows / MSVC 19.40 / x86_64 +* Build + * Added DART_USE_SYSTEM_GOOGLETEST option + ### [DART 6.14.4 (TBD)](https://github.com/dartsim/dart/milestone/81?closed=1) * Tested Platforms diff --git a/CMakeLists.txt b/CMakeLists.txt index 84c9c1c7b0fee..b0efc701fe04a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,7 @@ dart_option(DART_FAST_DEBUG "Add -O1 option for DEBUG mode build" OFF) dart_option(DART_FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." OFF) dart_option(DART_USE_SYSTEM_IMGUI "Use system ImGui" OFF) +dart_option(DART_USE_SYSTEM_GOOGLETEST "Use system GoogleTest" OFF) #=============================================================================== # Print intro diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3e8bf1d65de7f..9cb838943e7ee 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -31,17 +31,21 @@ # # Set up GoogleTest -include(FetchContent) -FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest - GIT_TAG v1.14.0 -) -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -set(gtest_disable_pthreads ON CACHE BOOL "" FORCE) -set(BUILD_GMOCK ON CACHE BOOL "" FORCE) -set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) -FetchContent_MakeAvailable(googletest) +if(DART_USE_SYSTEM_GOOGLETEST) + find_package(GTest MODULE REQUIRED) +else() + include(FetchContent) + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest + GIT_TAG v1.14.0 + ) + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + set(gtest_disable_pthreads ON CACHE BOOL "" FORCE) + set(BUILD_GMOCK ON CACHE BOOL "" FORCE) + set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(googletest) +end() #=============================================================================== # This function uses following global properties: @@ -65,7 +69,7 @@ function(dart_add_test test_type target_name) # ARGN for source files add_executable(${target_name} ${sources}) add_test(${target_name} ${target_name}) - target_link_libraries(${target_name} dart gtest gtest_main) + target_link_libraries(${target_name} dart GTest::gtest GTest::gtest_main) dart_format_add(${sources})