diff --git a/CMakeLists.txt b/CMakeLists.txt index e7ec0029f83..fd382754b24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,13 +137,34 @@ if(OPENDDS_BUILD_EXAMPLES OR OPENDDS_BUILD_TESTS) add_subdirectory(DevGuideExamples/DCPS/Messenger) endif() if(OPENDDS_BUILD_TESTS) - find_package(GTest QUIET) + find_package(GTest QUIET PATHS "${OPENDDS_GTEST}") if(NOT GTest_FOUND) - message("GTest not found, falling back to local copy") + set(gtestsm "${OPENDDS_SOURCE_DIR}/tests/googletest") + if(EXISTS "${gtestsm}/CMakeLists.txt") + message("GTest not found, using submodule") + set(fetch_args SOURCE_DIR "${gtestsm}") + else() + message("GTest not found, using clone") + set(fetch_args + GIT_REPOSITORY "https://github.com/OpenDDS/googletest" + GIT_TAG "v1.8.x" + GIT_SHALLOW TRUE + GIT_PROGRESS TRUE + USES_TERMINAL_DOWNLOAD TRUE + ) + endif() + FetchContent_Declare(googletest ${fetch_args}) # Prevent overriding the parent project's compiler/linker # settings on Windows set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - add_subdirectory(tests/googletest) + FetchContent_MakeAvailable(googletest) + endif() + if(TARGET GTest::gtest) + get_target_property(google_test_bin_dir GTest::gtest BINARY_DIR) + set(_OPENDDS_GOOGLE_TEST_DIR "${google_test_bin_dir}" CACHE INTERNAL "") + elseif(TARGET gtest) + get_target_property(google_test_bin_dir gtest BINARY_DIR) + set(_OPENDDS_GOOGLE_TEST_DIR "${google_test_bin_dir}" CACHE INTERNAL "") endif() add_subdirectory(tests/cmake/ace_tao_only) diff --git a/cmake/opendds_testing.cmake b/cmake/opendds_testing.cmake index 45a52a6b0a4..457435cbeeb 100644 --- a/cmake/opendds_testing.cmake +++ b/cmake/opendds_testing.cmake @@ -27,6 +27,13 @@ function(opendds_add_test) else() set(env_var_name LD_LIBRARY_PATH) endif() + if(DEFINED _OPENDDS_GOOGLE_TEST_DIR) + _opendds_path_list(lib_dir_list APPEND "${_OPENDDS_GOOGLE_TEST_DIR}") + if(CMAKE_CONFIGURATION_TYPES) + _opendds_path_list(lib_dir_list APPEND + "${_OPENDDS_GOOGLE_TEST_DIR}$<$>:/$>") + endif() + endif() _opendds_path_list(lib_dir_list "$ENV{${env_var_name}}" "${TAO_LIB_DIR}") foreach(lib_dir "${OPENDDS_LIB_DIR}" ${arg_EXTRA_LIB_DIRS}) _opendds_path_list(lib_dir_list APPEND "${lib_dir}")