Skip to content

Commit

Permalink
Merge pull request #316 from sandialabs/update_gtest_target
Browse files Browse the repository at this point in the history
Update gtest target in CMake
  • Loading branch information
kuberry authored Dec 13, 2024
2 parents 1685d45 + 259e1ff commit 0e3c702
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,19 @@ else() # Raw CMake Project

if (Compadre_EXAMPLES AND Compadre_TESTS)
if (NOT Trilinos_PREFIX)
if (NOT TARGET gtest)
# gtest from kokkos
add_library(gtest
kokkos/tpls/gtest/gtest/gtest-all.cc
)
target_include_directories(gtest PUBLIC kokkos/tpls/gtest)
endif()
# gtest from kokkos
# based on kokkos-kernels/CMakeLists.txt
SET(GTEST_SOURCE_DIR ${PROJECT_SOURCE_DIR}/kokkos/tpls/gtest)
message(STATUS "GTEST:: ${GTEST_SOURCE_DIR}")
add_library(compadre_gtest
${GTEST_SOURCE_DIR}/gtest/gtest-all.cc
)
target_include_directories(compadre_gtest PUBLIC ${GTEST_SOURCE_DIR}/gtest)
# Disables pthreads, this is a problem for serial builds in Trilinos & Sierra if it's enabled.
TARGET_COMPILE_DEFINITIONS(compadre_gtest PUBLIC "-DGTEST_HAS_PTHREAD=0")
TARGET_INCLUDE_DIRECTORIES(compadre_gtest PUBLIC $<BUILD_INTERFACE:${GTEST_SOURCE_DIR}>)
#Gtest minimally requires C++11
TARGET_COMPILE_FEATURES(compadre_gtest PUBLIC cxx_std_11)
endif()
endif()

Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if (Compadre_EXAMPLES)
ENDIF()
else()
add_exe_w_compadre(UnitTests Compadre_UnitTests.cpp)
TARGET_LINK_LIBRARIES(UnitTests PRIVATE gtest)
TARGET_LINK_LIBRARIES(UnitTests PRIVATE compadre_gtest)
ADD_TEST(CompadreGtests UnitTests)
endif()
SET_TESTS_PROPERTIES(CompadreGtests PROPERTIES SKIP_REGULAR_EXPRESSION "MISSING_GTEST" LABELS "Gtest;UnitTest;unittest;Unit;unit")
Expand Down

0 comments on commit 0e3c702

Please sign in to comment.