Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f8e23e9

Browse files
authoredJun 2, 2025··
Print Celeritas configuration options when loading downstream (#1802)
* Add packages to components list and always print installed components when finding Celeritas * Add options to componentslist
1 parent 6bfcffe commit f8e23e9

File tree

3 files changed

+65
-17
lines changed

3 files changed

+65
-17
lines changed
 

‎CMakeLists.txt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ if(NOT CELERITAS_USE_CUDA)
3232
endif()
3333

3434
# Optional dependencies
35-
# NOTE: when adding a new dependency, update the CMakeConfig "COMPONENTS"
3635
celeritas_optional_package(covfie "Use Covfie field integrator")
3736
celeritas_optional_package(Geant4 "Enable Geant4 adapter tools")
3837
celeritas_optional_package(HepMC3 "Enable HepMC3 event record reader")
@@ -86,8 +85,8 @@ if(CELERITAS_BUILD_TESTS)
8685
endif()
8786

8887
# Automatic options
89-
set(CELERITAS_USE_CLI11 ${CELERITAS_BUILD_APPS})
90-
set(CELERITAS_USE_GTest ${CELERITAS_BUILD_TESTS})
88+
celeritas_force_package(CLI11 ${CELERITAS_BUILD_APPS})
89+
celeritas_force_package(GTest ${CELERITAS_BUILD_TESTS})
9190

9291
#----------------------------------------------------------------------------#
9392
# CELERITAS CORE IMPLEMENTATION OPTIONS
@@ -337,7 +336,7 @@ if(CELERITAS_USE_CUDA)
337336
find_package(Thrust)
338337
endif()
339338
# Unconditionally set Thrust availability for downstream configuration
340-
set(CELERITAS_USE_Thrust "${Thrust_FOUND}")
339+
celeritas_force_package(Thrust "${Thrust_FOUND}")
341340

342341
if(CELERITAS_USE_Geant4 AND NOT Geant4_FOUND)
343342
find_package(Geant4 REQUIRED)
@@ -619,6 +618,7 @@ set(_cmake_files
619618
# For now, include in case downstream projects do `include(CudaRdcUtils)`.
620619
"${_LOCAL_RDCUTILS_FILENAME}"
621620
)
621+
# Add packages with custom Celeritas-provided FindX scripts
622622
foreach(_dep CLI11 covfie Geant4 G4VG HepMC3 Perfetto ROOT Thrust VecGeom)
623623
if(CELERITAS_USE_${_dep} AND NOT CELERITAS_BUILTIN_${_dep})
624624
list(APPEND _cmake_files "${PROJECT_SOURCE_DIR}/cmake/Find${_dep}.cmake")
@@ -643,18 +643,22 @@ file(COPY ${_cmake_files}
643643
# Export all cache variables that start with CELERITAS_
644644
set(CELERITAS_EXPORT_VARIABLES)
645645
macro(celeritas_export_var varname)
646-
list(APPEND CELERITAS_EXPORT_VARIABLES "set(${varname} \"${${varname}}\")")
646+
# Value of _key may be ;-separated list, so we need to escape the ; if present
647+
string(REPLACE ";" "\;" _key_val "${${varname}}")
648+
list(APPEND CELERITAS_EXPORT_VARIABLES "set(${varname} \"${_key_val}\")")
647649
endmacro()
648650
celeritas_export_var(Celeritas_VERSION_STRING)
651+
list(APPEND CELERITAS_EXPORT_VARIABLES "\n# Components")
652+
celeritas_export_var(CELERITAS_COMPONENTS)
653+
celeritas_export_var(CELERITAS_ENABLED_COMPONENTS)
654+
celeritas_export_var(CELERITAS_OPTION_VARS)
649655
list(APPEND CELERITAS_EXPORT_VARIABLES "\n# Configuration options")
650656
get_directory_property(_cachevar_keys CACHE_VARIABLES)
651657
foreach(_key IN LISTS _cachevar_keys)
652658
if(_key MATCHES "^CELERITAS_")
653659
celeritas_export_var(${_key})
654660
endif()
655661
endforeach()
656-
# Thrust dependency is not a cache variable
657-
celeritas_export_var(CELERITAS_USE_Thrust)
658662

659663
# Save whether we need GDML requirement
660664
if(Geant4_gdml_FOUND OR VecGeom_GDML_FOUND)
@@ -663,8 +667,11 @@ else()
663667
set(CELERITAS_USE_GDML OFF)
664668
endif()
665669
celeritas_export_var(CELERITAS_USE_GDML)
670+
foreach(_key IN LISTS CELERITAS_FORCED_PACKAGE_VARS)
671+
celeritas_export_var(${_key})
672+
endforeach()
666673

667-
# Export defaulted variables
674+
# Export defaulted CMake variables
668675
list(APPEND CELERITAS_EXPORT_VARIABLES "\n# Defaulted local variables")
669676
set(_celer_other_cmake_variables)
670677
if(CELERITAS_USE_CUDA)

‎cmake/CeleritasConfig.cmake.in

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ endif()
134134

135135
if(CELERITAS_USE_Python)
136136
find_dependency(Python 3.6 REQUIRED COMPONENTS Interpreter)
137-
unset(_components)
138137
endif()
139138

140139
if(CELERITAS_USE_ROOT)
@@ -193,20 +192,29 @@ endif()
193192

194193
#-----------------------------------------------------------------------------#
195194
# Set components for use by the caller
196-
197-
foreach(_dep
198-
CUDA HIP # Languages
199-
covfie Geant4 HepMC3 MPI OpenMP Perfetto PNG ROOT VecGeom # Packages
200-
)
195+
foreach(_dep IN LISTS CELERITAS_COMPONENTS)
201196
set(@PROJECT_NAME@_${_dep}_FOUND ${CELERITAS_USE_${_dep}})
202197
endforeach()
203198
unset(_dep)
204199

200+
foreach(_var IN LISTS CELERITAS_OPTION_VARS)
201+
set(@PROJECT_NAME@_${_var}=${CELERITAS_${_var}}_FOUND TRUE)
202+
endforeach()
203+
204+
if(NOT @PROJECT_NAME@_FIND_COMPONENTS)
205+
set(@PROJECT_NAME@_FIND_COMPONENTS @CELERITAS_ENABLED_COMPONENTS@)
206+
foreach(_var IN LISTS CELERITAS_OPTION_VARS)
207+
list(APPEND @PROJECT_NAME@_FIND_COMPONENTS
208+
"${_var}=${CELERITAS_${_var}}")
209+
endforeach()
210+
endif()
211+
unset(_var)
212+
205213
#-----------------------------------------------------------------------------#
206214
# Print a pretty message if the caller doesn't have a FindCeleritas.cmake
207215

208216
include(FindPackageHandleStandardArgs)
209217
set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG "${CMAKE_CURRENT_LIST_FILE}")
210-
find_package_handle_standard_args(@PROJECT_NAME@ CONFIG_MODE)
218+
find_package_handle_standard_args(@PROJECT_NAME@ CONFIG_MODE HANDLE_COMPONENTS)
211219

212220
#-----------------------------------------------------------------------------#

‎cmake/CeleritasOptionUtils.cmake

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,29 @@ include_guard(GLOBAL)
127127

128128
include(CheckLanguage)
129129

130+
# List of available components
131+
set(CELERITAS_COMPONENTS)
132+
# List of enabled components
133+
set(CELERITAS_ENABLED_COMPONENTS)
134+
# List of forced packages
135+
set(CELERITAS_FORCED_PACKAGE_VARS)
136+
# List of configurable options
137+
set(CELERITAS_OPTION_VARS)
130138
# List of variables configured via `celeritas_set_default`
131139
set(CELERITAS_DEFAULT_VARIABLES)
132140
# True if any CELERITAS_BUILTIN_XXX
133141
set(CELERITAS_BUILTIN FALSE)
134142

135143
#-----------------------------------------------------------------------------#
144+
macro(_celeritas_append_optional_component var val)
145+
# Append to list of components
146+
list(APPEND CELERITAS_COMPONENTS ${var})
147+
if("${val}")
148+
list(APPEND CELERITAS_ENABLED_COMPONENTS ${var})
149+
endif()
150+
endmacro()
136151

137-
function(celeritas_optional_language lang)
152+
macro(celeritas_optional_language lang)
138153
set(_var "CELERITAS_USE_${lang}")
139154
if(DEFINED "${_var}")
140155
set(_val "${_var}")
@@ -147,8 +162,11 @@ function(celeritas_optional_language lang)
147162
message(STATUS "Set ${_var}=${_val} based on compiler availability")
148163
endif()
149164

165+
# Create option
150166
option("${_var}" "Enable the ${lang} language" "${_val}" )
151-
endfunction()
167+
# Append to list of components
168+
_celeritas_append_optional_component("${lang}" "${${_var}}")
169+
endmacro()
152170

153171
#-----------------------------------------------------------------------------#
154172

@@ -230,7 +248,19 @@ macro(celeritas_optional_package package)
230248
endif()
231249
endif()
232250

251+
# Create option
233252
option("${_var}" "${_docstring}" "${_val}")
253+
# Append to list of components
254+
_celeritas_append_optional_component(${package} "${${_var}}")
255+
endmacro()
256+
257+
macro(celeritas_force_package package value)
258+
set(_var "CELERITAS_USE_${package}")
259+
set(${_var} ${value})
260+
# Append to list of components
261+
_celeritas_append_optional_component(${package} "${value}")
262+
# Append to list of forced packages for export
263+
list(APPEND CELERITAS_FORCED_PACKAGE_VARS ${_var})
234264
endmacro()
235265

236266
#-----------------------------------------------------------------------------#
@@ -344,6 +374,9 @@ function(celeritas_define_options var doc)
344374
endif()
345375
endif()
346376
set(${_last_var} "${_val}" CACHE INTERNAL "")
377+
378+
string(REGEX REPLACE "^CELERITAS_" "" _shortvar "${var}")
379+
set(CELERITAS_OPTION_VARS ${CELERITAS_OPTION_VARS} ${_shortvar} PARENT_SCOPE)
347380
endfunction()
348381

349382
#-----------------------------------------------------------------------------#

0 commit comments

Comments
 (0)
Please sign in to comment.