Skip to content

Commit

Permalink
fixup: use external gtest
Browse files Browse the repository at this point in the history
  • Loading branch information
streeve committed Jan 9, 2024
1 parent 62635b7 commit 3782492
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
29 changes: 10 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,6 @@ include(GNUInstallDirs)

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

##---------------------------------------------------------------------------##
# Download and unpack googletest
##---------------------------------------------------------------------------##
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.10.0
)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
endif()

# Prevent GoogleTest from overriding our compiler/linker options
# when building with Visual Studio
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

##---------------------------------------------------------------------------##
# Set up main options (inherit from Kokkos and Cabana CMake)
##---------------------------------------------------------------------------##
Expand Down Expand Up @@ -71,6 +52,16 @@ add_subdirectory(bin)
##---------------------------------------------------------------------------##
option(CabanaMD_ENABLE_TESTING "Build tests" OFF)
if(CabanaMD_ENABLE_TESTING)
find_package(GTest 1.10 REQUIRED)
# Workaround for FindGTest module in CMake older than 3.20
if(TARGET GTest::gtest)
set(gtest_target GTest::gtest)
elseif(TARGET GTest::GTest)
set(gtest_target GTest::GTest)
else()
message(FATAL_ERROR "bug in GTest find module workaround")
endif()

enable_testing()
add_subdirectory(unit_test)
endif()
Expand Down
4 changes: 1 addition & 3 deletions unit_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
set(gtest_args --gtest_color=yes)

##--------------------------------------------------------------------------##
## On-node tests
##--------------------------------------------------------------------------##
Expand Down Expand Up @@ -30,7 +28,7 @@ macro(CabanaMD_add_tests)
set(_target ${_test}_test_${_uppercase_device})
add_executable(${_target} ${_file} ${CABANAMD_UNIT_TEST_MAIN})
target_include_directories(${_target} PRIVATE ${_dir} ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(${_target} PRIVATE CabanaMD gtest CabanaMD)
target_link_libraries(${_target} PRIVATE CabanaMD ${gtest_target} CabanaMD)

foreach(_np ${CABANAMD_UNIT_TEST_MPIEXEC_NUMPROCS})
if(_device STREQUAL PTHREAD OR _device STREQUAL OPENMP)
Expand Down

0 comments on commit 3782492

Please sign in to comment.