From d4d3c23f7844c7eaff70a9a5628a48392d23ac29 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Mon, 27 May 2024 08:37:15 -0400 Subject: [PATCH] Define test library macro to avoid installation --- cmake/CeleritasAddTest.cmake | 2 +- test/CMakeLists.txt | 27 ++++++++++++++++++++++++++- test/accel/CMakeLists.txt | 8 ++++---- test/celeritas/CMakeLists.txt | 16 ++++++++-------- test/corecel/CMakeLists.txt | 4 ++-- test/geocel/CMakeLists.txt | 9 ++++----- test/orange/CMakeLists.txt | 5 ++--- 7 files changed, 47 insertions(+), 24 deletions(-) diff --git a/cmake/CeleritasAddTest.cmake b/cmake/CeleritasAddTest.cmake index f0eba35049..8a2f748633 100644 --- a/cmake/CeleritasAddTest.cmake +++ b/cmake/CeleritasAddTest.cmake @@ -320,7 +320,7 @@ function(celeritas_add_test SOURCE_FILE) celeritas_target_link_libraries(${_TARGET} ${CELERITASTEST_LINK_LIBRARIES} ${PARSE_LINK_LIBRARIES} - Celeritas::testcel_harness + testcel_harness ) if(PARSE_ADD_DEPENDENCIES OR CELERITASTEST_ADD_DEPENDENCIES) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a7cf162cd2..a155056678 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,6 +6,31 @@ include(CeleritasAddTest) +#-----------------------------------------------------------------------------# + +function(celeritas_add_test_library target) + cuda_rdc_get_sources_and_options(_sources _cmake_options _options ${ARGN}) + cuda_rdc_sources_contains_cuda(_cuda_sources ${_sources}) + if(CELERITAS_USE_HIP AND _cuda_sources) + # When building Celeritas libraries, we put HIP/CUDA files in shared .cu + # suffixed files. Override the language if using HIP. + set_source_files_properties( + ${_cuda_sources} + PROPERTIES LANGUAGE HIP + ) + endif() + + celeritas_cuda_rdc_wrapper_add_library(${target} ${ARGN}) + + # We could hide this behind `if (CELERITAS_USE_ROOT)` + get_target_property(_tgt ${target} CUDA_RDC_OBJECT_LIBRARY) + if(_tgt) + set_target_properties(${_tgt} PROPERTIES + POSITION_INDEPENDENT_CODE ON + ) + endif() +endfunction() + #-----------------------------------------------------------------------------# # TEST HARNESS #-----------------------------------------------------------------------------# @@ -24,7 +49,7 @@ if(CELERITAS_USE_JSON) testdetail/JsonComparer.json.cc ) endif() -celeritas_add_library(testcel_harness ${_harness_sources}) +celeritas_add_test_library(testcel_harness ${_harness_sources}) target_compile_features(testcel_harness PUBLIC cxx_std_17) celeritas_target_link_libraries(testcel_harness PUBLIC Celeritas::corecel GTest::gtest diff --git a/test/accel/CMakeLists.txt b/test/accel/CMakeLists.txt index f2fbb040b0..36aa43a30b 100644 --- a/test/accel/CMakeLists.txt +++ b/test/accel/CMakeLists.txt @@ -4,20 +4,20 @@ # SPDX-License-Identifier: (Apache-2.0 OR MIT) #-----------------------------------------------------------------------------# -celeritas_add_library(testcel_accel +celeritas_add_test_library(testcel_accel SDTestBase.cc SimpleSensitiveDetector.cc ) celeritas_target_link_libraries(testcel_accel PUBLIC - Celeritas::testcel_celeritas Celeritas::testcel_harness + testcel_celeritas testcel_harness PRIVATE ${Geant4_LIBRARIES} ) celeritas_setup_tests(SERIAL PREFIX accel LINK_LIBRARIES - Celeritas::testcel_accel Celeritas::testcel_core Celeritas::accel + testcel_accel testcel_core Celeritas::accel ) #-----------------------------------------------------------------------------# @@ -36,7 +36,7 @@ if(CELERITAS_REAL_TYPE STREQUAL "double") # This test requires Geant4 *geometry* which is incompatible # with single-precision celeritas_add_test(detail/TouchableUpdater.test.cc - LINK_LIBRARIES Celeritas::testcel_geocel) + LINK_LIBRARIES testcel_geocel) endif() #-----------------------------------------------------------------------------# diff --git a/test/celeritas/CMakeLists.txt b/test/celeritas/CMakeLists.txt index 8c3e7f0e0a..17dc830f85 100644 --- a/test/celeritas/CMakeLists.txt +++ b/test/celeritas/CMakeLists.txt @@ -40,18 +40,18 @@ if(CELERITAS_CORE_GEO STREQUAL "ORANGE" AND NOT CELERITAS_USE_JSON endif() if(CELERITAS_CORE_GEO STREQUAL "ORANGE") - set(_core_geo_libs Celeritas::testcel_orange Celeritas::orange) + set(_core_geo_libs testcel_orange Celeritas::orange) elseif(CELERITAS_CORE_GEO STREQUAL "VecGeom") - set(_core_geo_libs Celeritas::testcel_geocel ${VecGeom_LIBRARIES}) + set(_core_geo_libs testcel_geocel ${VecGeom_LIBRARIES}) elseif(CELERITAS_CORE_GEO STREQUAL "Geant4") - set(_core_geo_libs Celeritas::testcel_geocel ${Geant4_LIBRARIES}) + set(_core_geo_libs testcel_geocel ${Geant4_LIBRARIES}) endif() set(_all_geo_libs # Geometry includes Celeritas::orange ${VecGeom_LIBRARIES} ${Geant4_LIBRARIES} # Test harness instantiations - Celeritas::testcel_geocel Celeritas::testcel_orange + testcel_geocel testcel_orange ) if(CELERITAS_UNITS STREQUAL "CGS") @@ -65,7 +65,7 @@ endif() # LIBRARY #-----------------------------------------------------------------------------# -celeritas_add_library(testcel_celeritas +celeritas_add_test_library(testcel_celeritas GeantTestBase.cc GlobalGeoTestBase.cc GlobalTestBase.cc @@ -94,9 +94,9 @@ celeritas_add_library(testcel_celeritas celeritas_target_link_libraries(testcel_celeritas PUBLIC - Celeritas::testcel_harness Celeritas::celeritas + testcel_harness Celeritas::celeritas PRIVATE - Celeritas::testcel_core Celeritas::testcel_orange Celeritas::testcel_geocel + testcel_core testcel_orange testcel_geocel ${nlohmann_json_LIBRARIES} ) @@ -105,7 +105,7 @@ celeritas_target_link_libraries(testcel_celeritas #-----------------------------------------------------------------------------# celeritas_setup_tests(SERIAL PREFIX celeritas - LINK_LIBRARIES Celeritas::testcel_celeritas Celeritas::testcel_core + LINK_LIBRARIES testcel_celeritas testcel_core ) #-----------------------------------------------------------------------------# diff --git a/test/corecel/CMakeLists.txt b/test/corecel/CMakeLists.txt index 705463d539..21ea0e68b6 100644 --- a/test/corecel/CMakeLists.txt +++ b/test/corecel/CMakeLists.txt @@ -4,11 +4,11 @@ # SPDX-License-Identifier: (Apache-2.0 OR MIT) #-----------------------------------------------------------------------------# -celeritas_add_library(testcel_core +celeritas_add_test_library(testcel_core ScopedLogStorer.cc ) celeritas_target_link_libraries(testcel_core - PRIVATE Celeritas::testcel_harness Celeritas::corecel + PRIVATE testcel_harness Celeritas::corecel ) celeritas_setup_tests(SERIAL PREFIX corecel diff --git a/test/geocel/CMakeLists.txt b/test/geocel/CMakeLists.txt index 5b0817e14d..862e4b85e0 100644 --- a/test/geocel/CMakeLists.txt +++ b/test/geocel/CMakeLists.txt @@ -38,13 +38,13 @@ if(CELERITAS_USE_VecGeom) list(APPEND PRIVATE_DEPS VecGeom::vecgeom) endif() -celeritas_add_library(testcel_geocel ${SOURCES}) +celeritas_add_test_library(testcel_geocel ${SOURCES}) celeritas_target_link_libraries(testcel_geocel PUBLIC - Celeritas::testcel_harness Celeritas::geocel + testcel_harness Celeritas::geocel PRIVATE - Celeritas::testcel_core ${_g4_geo_libs} ${VecGeom_LIBRARIES} + testcel_core ${_g4_geo_libs} ${VecGeom_LIBRARIES} ) #-----------------------------------------------------------------------------# @@ -53,8 +53,7 @@ celeritas_target_link_libraries(testcel_geocel celeritas_setup_tests(SERIAL PREFIX geocel - LINK_LIBRARIES Celeritas::testcel_geocel Celeritas::testcel_core - Celeritas::geocel + LINK_LIBRARIES testcel_geocel testcel_core Celeritas::geocel ) #-----------------------------------------------------------------------------# diff --git a/test/orange/CMakeLists.txt b/test/orange/CMakeLists.txt index 969223aca5..2f713ed266 100644 --- a/test/orange/CMakeLists.txt +++ b/test/orange/CMakeLists.txt @@ -4,7 +4,7 @@ # SPDX-License-Identifier: (Apache-2.0 OR MIT) #-----------------------------------------------------------------------------# -celeritas_add_library(testcel_orange +celeritas_add_test_library(testcel_orange OrangeGeoTestBase.cc OrangeTestBase.cc orangeinp/CsgTestUtils.cc @@ -12,8 +12,7 @@ celeritas_add_library(testcel_orange ) celeritas_target_link_libraries(testcel_orange PUBLIC - Celeritas::orange Celeritas::testcel_harness Celeritas::testcel_core - Celeritas::testcel_geocel + Celeritas::orange testcel_harness testcel_core testcel_geocel PRIVATE Celeritas::orange ${nlohmann_json_LIBRARIES} )