From 259e1ff45f7d86a08d2073f3c21ded50e086ef38 Mon Sep 17 00:00:00 2001 From: Paul Kuberry Date: Fri, 13 Dec 2024 12:54:21 -0500 Subject: [PATCH] Update gtest target in CMake --- CMakeLists.txt | 20 +++++++++++++------- examples/CMakeLists.txt | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc1f2ed14..0b703154e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 $) + #Gtest minimally requires C++11 + TARGET_COMPILE_FEATURES(compadre_gtest PUBLIC cxx_std_11) endif() endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index a7d73faca..4c7ff27be 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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")