Skip to content

Commit

Permalink
Fixes for CMake Google Test on Windows
Browse files Browse the repository at this point in the history
Also make use of fetch content
  • Loading branch information
iguessthislldo committed Nov 21, 2023
1 parent 6d807de commit 2b2a9c1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
27 changes: 24 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions cmake/opendds_testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}$<$<BOOL:$<CONFIG>>:/$<CONFIG>>")
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}")
Expand Down

0 comments on commit 2b2a9c1

Please sign in to comment.