Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export full Celeritas version string as well as defaulted CMake variables #870

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -424,20 +424,26 @@ install(DIRECTORY "${PROJECT_SOURCE_DIR}/cmake/backport"

# Export all cache variables that start with CELERITAS_
set(CELERITAS_EXPORT_VARIABLES)
macro(celeritas_export_var varname)
list(APPEND CELERITAS_EXPORT_VARIABLES "set(${varname} \"${${varname}}\")")
endmacro()
celeritas_export_var(Celeritas_VERSION_STRING)
list(APPEND CELERITAS_EXPORT_VARIABLES "\n# Configuration options")
get_directory_property(_cachevar_keys CACHE_VARIABLES)
foreach(_key IN LISTS _cachevar_keys)
if(_key MATCHES "^CELERITAS_")
list(APPEND CELERITAS_EXPORT_VARIABLES "set(${_key} \"${${_key}}\")")
celeritas_export_var(${_key})
endif()
endforeach()

# Add other cache variables, prefixed with CELERITAS_
foreach(_key BUILD_SHARED_LIBS)
# Export defaulted variables
list(APPEND CELERITAS_EXPORT_VARIABLES "\n# Defaulted variables")
foreach(_key IN LISTS CELERITAS_DEFAULT_VARIABLES)
list(APPEND CELERITAS_EXPORT_VARIABLES "set(CELERITAS_${_key} \"${${_key}}\")")
endforeach()

# Add hints for direct dependencies and indirect geant dependencies
list(APPEND CELERITAS_EXPORT_VARIABLES "# Hints for upstream dependencies")
list(APPEND CELERITAS_EXPORT_VARIABLES "\n# Hints for upstream dependencies")
foreach(_key
MPIEXEC_EXECUTABLE CUDAToolkit_BIN_DIR
Geant4_DIR GTest_DIR HepMC3_DIR nlohmann_json_DIR Python_DIR ROOT_DIR
Expand Down
9 changes: 6 additions & 3 deletions cmake/CeleritasUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ include_guard(GLOBAL)

include(CheckLanguage)

set(CELERITAS_DEFAULT_VARIABLES)

#-----------------------------------------------------------------------------#

function(celeritas_optional_language lang)
Expand Down Expand Up @@ -199,12 +201,13 @@ endmacro()

#-----------------------------------------------------------------------------#

function(celeritas_set_default name value)
macro(celeritas_set_default name value)
if(NOT DEFINED ${name})
message(VERBOSE "Celeritas: set default ${name}=${value}")
set(${name} "${value}" PARENT_SCOPE)
set(${name} "${value}")
endif()
endfunction()
list(APPEND CELERITAS_DEFAULT_VARIABLES ${name})
endmacro()

#-----------------------------------------------------------------------------#

Expand Down
6 changes: 5 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ endforeach()

foreach(_var CLHEP_VERSION Geant4_VERSION VecGeom_VERSION)
string(TOLOWER "${_var}" _lower)
if(DEFINED ${_var}_STRING)
set(_var "${_var}_STRING")
endif()
set(_value "${${_var}}")
string(APPEND CELERITAS_CMAKE_STRINGS
"static const char celeritas_${_lower}[] = \"${${_var}}\";\n"
"static const char celeritas_${_lower}[] = \"${_value}\";\n"
)
endforeach()
celeritas_configure_file("celeritas_cmake_strings.h.in" "celeritas_cmake_strings.h" @ONLY)
Expand Down