diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fab298..41ad5a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,14 @@ g4vg_set_default(BUILD_TESTING ${G4VG_BUILD_TESTS}) g4vg_set_default(CMAKE_CXX_EXTENSIONS OFF) +#----------------------------------------------------------------------------# +# Dependencies +# Found here because we need the targets visible to both import Celeritas and +# to declare them as-needed in g4vg itself for correct downstream use + +find_package(Geant4 REQUIRED) +find_package(VecGeom REQUIRED) + #----------------------------------------------------------------------------# # Add code @@ -45,15 +53,6 @@ if(G4VG_BUILD_TESTS) if(NOT GTest_FOUND) find_package(GTest 1.10 REQUIRED) endif() - if(NOT VecGeom_FOUND) - # Note: using the same version as celeritas to silence cmake config - # messages - find_package(VecGeom 1.2.4 REQUIRED) - endif() - if(NOT Geant4_FOUND) - find_package(Geant4 REQUIRED) - endif() - add_subdirectory(test) endif() diff --git a/cmake/G4VGConfig.cmake.in b/cmake/G4VGConfig.cmake.in index ec29d36..277cfa3 100644 --- a/cmake/G4VGConfig.cmake.in +++ b/cmake/G4VGConfig.cmake.in @@ -1,4 +1,9 @@ @PACKAGE_INIT@ +# Refind dependencies in case linker needs paths to resolve +include(CMakeFindDependencyMacro) +find_dependency(Geant4) +find_depencency(VecGeom) + include("${CMAKE_CURRENT_LIST_DIR}/G4VGTargets.cmake") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f09aff0..83f0740 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,8 +9,15 @@ cuda_rdc_add_library(g4vg SHARED G4VG.cc ) +# Whilst geocel contains the primary Geant4/VecGeom dependency, we must also +# declare the geometry/gdml deps explicitly so that clients can pick them +# up correctly through LINK_DEPENDENT_LIBRARIES should the linker require it. +# See: https://discourse.cmake.org/t/use-cases-for-imported-link-dependent-libraries cuda_rdc_target_link_libraries(g4vg - PRIVATE Celeritas::geocel + PRIVATE + Celeritas::geocel + Geant4::G4geometry + $,Geant4::G4gdml,Geant4::G4persistency> ) cuda_rdc_target_include_directories(g4vg PUBLIC diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8e1a5bc..c924ea6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,6 +4,12 @@ # SPDX-License-Identifier: (Apache-2.0 OR MIT) #-----------------------------------------------------------------------------# +# - Raw link test +add_executable(g4vg_link_test G4VG.link.test.cc) +target_link_libraries(g4vg_link_test PRIVATE G4VG::g4vg) +return() + +# - Primary code test file(TO_CMAKE_PATH "${PROJECT_SOURCE_DIR}" G4VG_SOURCE_DIR) configure_file(g4vg_test_config.h.in g4vg_test_config.h @ONLY) diff --git a/test/G4VG.link.test.cc b/test/G4VG.link.test.cc new file mode 100644 index 0000000..f0bfe30 --- /dev/null +++ b/test/G4VG.link.test.cc @@ -0,0 +1,11 @@ +//----------------------------------*-C++-*----------------------------------// +// Copyright 2024 UT-Battelle, LLC, and other Celeritas developers. +// See the top-level COPYRIGHT file for details. +// SPDX-License-Identifier: (Apache-2.0 OR MIT) +//---------------------------------------------------------------------------// +//! \file G4VG.link.test.cc +//---------------------------------------------------------------------------// + +#include "G4VG.hh" + +int main() {}