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

Support external installation #432

Merged
merged 10 commits into from
May 31, 2022
Merged
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
.DS_Store
.nfs*
.vscode
/[bB][uU][iI][lL][dD]*
/install
/build*
/install*
/spack-build*
CMakeUserPresets.json
/CMakeUserPresets.json
Testing
compile_commands.json
cmake_install.cmake
Expand Down
101 changes: 101 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ if(CMAKE_VERSION VERSION_LESS 3.18)
endif()

include(GNUInstallDirs)
include(CeleritasLibrary)
include(CeleritasUtils)
include(CMakeDependentOption)
include(CMakePackageConfigHelpers)

#----------------------------------------------------------------------------#
# OPTIONS
Expand Down Expand Up @@ -261,3 +263,102 @@ if(CELERITAS_USE_Doxygen)
endif()

#----------------------------------------------------------------------------#
# CONFIG FILE INSTALLATION
#----------------------------------------------------------------------------#

# Where to configure cmake files
set(CELER_CMAKE_CONFIG_DIRECTORY "${PROJECT_BINARY_DIR}/lib/cmake")
# Where to install configured cmake files
set(CELER_INSTALL_CMAKECONFIGDIR
"${CMAKE_INSTALL_LIBDIR}/cmake/Celeritas")

# Build list of CMake files to install
set(_cmake_files
"${PROJECT_SOURCE_DIR}/cmake/CeleritasGen.cmake"
"${PROJECT_SOURCE_DIR}/cmake/CeleritasGen/gen-action.py"
"${PROJECT_SOURCE_DIR}/cmake/CeleritasLibrary.cmake"
)
foreach(_dep Geant4 HepMC3 ROOT VecGeom)
if(CELERITAS_USE_${_dep})
list(APPEND _cmake_files "${PROJECT_SOURCE_DIR}/cmake/Find${_dep}.cmake")
endif()
endforeach()
if(CELERITAS_BUILD_TESTS)
list(APPEND _cmake_files
"${PROJECT_SOURCE_DIR}/cmake/CeleritasAddTest.cmake"
)
endif()

install(FILES ${_cmake_files}
DESTINATION "${CELER_INSTALL_CMAKECONFIGDIR}"
COMPONENT devel
)
install(DIRECTORY "${PROJECT_SOURCE_DIR}/cmake/backport"
DESTINATION "${CELER_INSTALL_CMAKECONFIGDIR}"
COMPONENT devel
)

# Export all cache variables that start with CELERITAS_
set(CELER_EXPORT_VARIABLES)
get_directory_property(_cachevar_keys CACHE_VARIABLES)
foreach(_key IN LISTS _cachevar_keys)
if(_key MATCHES "^CELERITAS_")
list(APPEND CELER_EXPORT_VARIABLES "set(${_key} \"${${_key}}\")")
endif()
endforeach()

# Add other cache variables, prefixed with CELER_
foreach(_key BUILD_SHARED_LIBS)
list(APPEND CELER_EXPORT_VARIABLES "set(CELERITAS_${_key} \"${${_key}}\")")
endforeach()

# Add hints for direct dependencies and indirect geant dependencies
list(APPEND CELER_EXPORT_VARIABLES "# Hints for upstream dependencies")
foreach(_key
MPIEXEC_EXECUTABLE CUDAToolkit_BIN_DIR
Geant4_DIR HepMC3_DIR nlohmann_json_DIR Python_DIR ROOT_DIR
VecCore_DIR VecGeom_DIR
CLHEP_DIR ZLIB_DIR EXPAT_DIR XercesC_DIR PTL_DIR
EXPAT_INCLUDE_DIR EXPAT_LIBRARY
XercesC_LIBRARY XercesC_INCLUDE_DIR
)
set(_val "${${_key}}")
if(_val)
list(APPEND CELER_EXPORT_VARIABLES
"if(NOT DEFINED ${_key})"
" set(${_key} \"${_val}\")"
"endif()"
)
endif()
endforeach()
list(JOIN CELER_EXPORT_VARIABLES "\n" CELER_EXPORT_VARIABLES)

# Generate the file needed by downstream "find_package(CELER)"
configure_file(
"${PROJECT_SOURCE_DIR}/cmake/CeleritasConfig.cmake.in"
"${CELER_CMAKE_CONFIG_DIRECTORY}/CeleritasConfig.cmake"
@ONLY
)

# Export version info
write_basic_package_version_file(
"${CELER_CMAKE_CONFIG_DIRECTORY}/CeleritasConfigVersion.cmake"
COMPATIBILITY ExactVersion
)

# Install the config and version files
install(FILES
"${CELER_CMAKE_CONFIG_DIRECTORY}/CeleritasConfig.cmake"
"${CELER_CMAKE_CONFIG_DIRECTORY}/CeleritasConfigVersion.cmake"
DESTINATION ${CELER_INSTALL_CMAKECONFIGDIR}
)

# Install 'CeleritasTargets.cmake', included by CeleritasConfig.cmake, which
# references the targets we install.
install(EXPORT celeritas-targets
FILE CeleritasTargets.cmake
NAMESPACE Celeritas::
DESTINATION "${CELER_INSTALL_CMAKECONFIGDIR}"
)

#----------------------------------------------------------------------------#
4 changes: 0 additions & 4 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ endif()

if(CELERITAS_USE_HIP)
set_source_files_properties(
demo-loop/generated/AlongAndPostStepKernel.cu
demo-loop/generated/ProcessInteractionsKernel.cu
demo-loop/generated/PreStepKernel.cu
demo-loop/generated/CleanupKernel.cu
demo-loop/diagnostic/StepDiagnostic.cu
demo-loop/diagnostic/ParticleProcessDiagnostic.cu
demo-loop/diagnostic/EnergyDiagnostic.cu
Expand Down
123 changes: 123 additions & 0 deletions cmake/CeleritasConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#---------------------------------*-CMake-*----------------------------------#
# Copyright 2022 UT-Battelle, LLC, and other Celeritas developers.
# See the top-level COPYRIGHT file for details.
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
#----------------------------------------------------------------------------#

# Helper scripts, see CMakePackageConfigHelpers
set(Celeritas_VERSION @Celeritas_VERSION@)

#-----------------------------------------------------------------------------#
# Helper scripts
#-----------------------------------------------------------------------------#

get_filename_component(CELER_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)
list(APPEND CMAKE_MODULE_PATH
"${CELER_CMAKE_DIR}"
)
if(CMAKE_VERSION VERSION_LESS 3.18)
list(APPEND CMAKE_MODULE_PATH
"${CELER_CMAKE_DIR}/backport/3.18"
)
endif()

#-----------------------------------------------------------------------------#
# Variables
#-----------------------------------------------------------------------------#

@CELER_EXPORT_VARIABLES@

#-----------------------------------------------------------------------------#
# Dependencies
#-----------------------------------------------------------------------------#

include(CMakeFindDependencyMacro)

if(CELERITAS_USE_CUDA)
enable_language(CUDA)
find_dependency(CUDAToolkit REQUIRED QUIET)
elseif(CELERITAS_USE_HIP)
enable_language(HIP)
endif()

if(CELERITAS_USE_Geant4)
# Geant4 calls `include_directories` for CLHEP :( which is not what we want!
# Save and restore include directories around the call -- even though as a
# standalone project Celeritas will never have directory-level includes
get_directory_property(_include_dirs INCLUDE_DIRECTORIES)
find_dependency(Geant4 REQUIRED)
set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES "${_include_dirs}")
endif()

if(CELERITAS_USE_HepMC3)
find_dependency(HepMC3 REQUIRED)
endif()

if(CELERITAS_USE_JSON)
find_dependency(nlohmann_json 3.7.0 REQUIRED)
endif()

if(CELERITAS_USE_MPI)
find_dependency(MPI REQUIRED)
endif()

if(CELERITAS_USE_OpenMP)
find_dependency(OpenMP REQUIRED)
endif()

if(CELERITAS_USE_Python)
set(_components Interpreter)
if(CELERITAS_USE_SWIG)
list(APPEND _components Development)
endif()
find_dependency(Python 3.6 REQUIRED COMPONENTS ${_components})
endif()

if(CELERITAS_USE_ROOT)
find_dependency(ROOT REQUIRED)
endif()

if(CELERITAS_USE_VecGeom)
find_dependency(VecGeom 1.1.17 REQUIRED)

if((CELERITAS_USE_CUDA AND NOT VecGeom_CUDA_FOUND)
OR (NOT CELERITAS_USE_CUDA AND VecGeom_CUDA_FOUND))
message(SEND_ERROR "CUDA mismatch between the VecGeom installation "
"at ${VECGEOM_INSTALL_DIR} (VecGeom_CUDA_FOUND=${VecGeom_CUDA_FOUND}) "
"and Celeritas (CELERITAS_USE_CUDA=${CELERITAS_USE_CUDA})"
)
endif()
if(NOT VecGeom_GDML_FOUND)
message(SEND_ERROR "VecGeom GDML capability is required for Celeritas")
endif()
endif()

if(CELER_BUILD_TESTS)
if(CMAKE_VERSION VERSION_LESS 3.20)
# First look for standard CMake installation
# (automatically done for CMake >= 3.20)
find_dependency(GTest QUIET NO_MODULE)
endif()
if(NOT GTest_FOUND)
# If not found, try again
find_dependency(GTest)
endif()
endif()

#-----------------------------------------------------------------------------#
# Targets
#-----------------------------------------------------------------------------#

if(NOT TARGET celeritas)
include("${CELER_CMAKE_DIR}/CeleritasTargets.cmake")
add_library(Celeritas::Core ALIAS Celeritas::celeritas)
add_library(Celeritas::IO ALIAS Celeritas::celeritas_io)
endif()

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

foreach(_dep CUDA ROOT Geant4 VecGeom MPI OpenMP)
set(Celeritas_${_dep}_FOUND ${CELERITAS_USE_${_dep}})
endforeach()

#-----------------------------------------------------------------------------#
68 changes: 68 additions & 0 deletions cmake/CeleritasGen.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#----------------------------------*-CMake-*----------------------------------#
# Copyright 2020-2022 UT-Battelle, LLC, and other Celeritas developers.
# See the top-level COPYRIGHT file for details.
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
#[=======================================================================[.rst:

CeleritasGen
------------

Automatically generate headers and source files for dual CPU/GPU kernel launches.

.. command:: celeritas_gen

Generate from the given class and function name::

celeritas_gen(<var> <script> <subdir> <basename> [...])

``var``
Variable name to append created source file names in the parent scope.

``script``
Python script name inside ``cmake/CeleritasUtils/``

``subdir``
Local source subdirectory in which to generate files

``basename``
Name without exension.

#]=======================================================================]

include_guard(GLOBAL)

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

function(celeritas_gen var script basename)
set(_scriptdir "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/CeleritasGen")
set(script "${_scriptdir}/${script}")
set(_path_noext "${CMAKE_CURRENT_SOURCE_DIR}/${basename}")

if(Python_FOUND)
# Regenerate files on the fly
add_custom_command(
COMMAND "$<TARGET_FILE:Python::Interpreter>"
"${script}"
--basename ${basename} ${ARGN}
OUTPUT "${_path_noext}.cc" "${_path_noext}.cu" "${_path_noext}.hh"
DEPENDS
"${script}"
"${_scriptdir}/launchbounds.py"
"${_scriptdir}/launch-bounds.json"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
endif()

set(_sources ${${var}} "${_path_noext}.cc")
if(CELERITAS_USE_CUDA OR CELERITAS_USE_HIP)
list(APPEND _sources "${_path_noext}.cu")
endif()
if(CELERITAS_USE_HIP)
set_source_files_properties("${_path_noext}.cu"
PROPERTIES LANGUAGE HIP
)
endif()
set(${var} "${_sources}" PARENT_SCOPE)
endfunction()

#-----------------------------------------------------------------------------#
File renamed without changes.
Loading