Skip to content

Commit

Permalink
Define test library macro to avoid installation
Browse files Browse the repository at this point in the history
  • Loading branch information
sethrj committed May 27, 2024
1 parent ffd031a commit d4d3c23
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 24 deletions.
2 changes: 1 addition & 1 deletion cmake/CeleritasAddTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 26 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
#-----------------------------------------------------------------------------#
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/accel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

#-----------------------------------------------------------------------------#
Expand All @@ -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()

#-----------------------------------------------------------------------------#
16 changes: 8 additions & 8 deletions test/celeritas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -65,7 +65,7 @@ endif()
# LIBRARY
#-----------------------------------------------------------------------------#

celeritas_add_library(testcel_celeritas
celeritas_add_test_library(testcel_celeritas
GeantTestBase.cc
GlobalGeoTestBase.cc
GlobalTestBase.cc
Expand Down Expand Up @@ -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}
)

Expand All @@ -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
)

#-----------------------------------------------------------------------------#
Expand Down
4 changes: 2 additions & 2 deletions test/corecel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions test/geocel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)

#-----------------------------------------------------------------------------#
Expand All @@ -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
)

#-----------------------------------------------------------------------------#
Expand Down
5 changes: 2 additions & 3 deletions test/orange/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
# 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
orangeinp/ObjectTestBase.cc
)
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}
)
Expand Down

0 comments on commit d4d3c23

Please sign in to comment.