Skip to content

WIP: Modernize VecGeom's CMake usage

Benjamin Morgan requested to merge bmorgan/VecGeom:modernize-cmake-config into master

This is a WIP to address some issues identified through preparation of Geant4's 10.6 release and more generally for VecGeom usage by other clients.

The primary aim is to modernize the VecGeomConfig.cmake file installed by the package. At present, it uses variables to specify usage requirements to CMake-based clients, meaning that they must do:

find_package(VecGeom REQUIRED)
# there's a hidden add_definitions(${VECGEOM_DEFINITIONS}) in there...
include_directories(${VECGEOM_INCLUDE_DIRS})
add_library(foo foo.cc)
target_link_libraries(foo ${VECGEOM_LIBRARIES})

This MR updates the config file and install to use full exported/imported targets, so that a CMake-based client only need do

find_package(VecGeom REQUIRED)
add_library(foo foo.cc)
target_link_libraries(foo PUBLIC VecGeom::vecgeom)

Use of an imported target ensures correct include paths, definitions, and dependent libraries are used by foo and subsequently by clients of foo. At present, this is only tested for the basic Scalar backend so likely needs updating for VC/CUDA etc, based on test results.

The secondary aim is to improve the robustness and portability of the build by simplifying the main CMakeLists.txt. At present, only the above build updates and some minor rationalisation have been done. Before proceeding further, I'd like to discuss the ideas, specifically:

  • Use of target_compile_features(vecgeom PUBLIC cxx_std_{11,14,17}) which would ensure clients use the same (or newer) standard to compile against.
  • Use of target_compile_options for the -m flags?
  • Removal of the "builtin" options for VecCore and VMC. Whilst I guess it'll need some updates to testing, this would massively simplify the build, especially for packaging in Spack/Homebrew/etc.
  • Update directory structure to have a "VecGeom|vecgeom" base directory. Not really a build thing, just makes installs and use cleaner and more reliable as it'll fully prevent name clashes.

These are all straightforward to implement, though the last implies a minor interface change due to the different (but clearer) #include paths.

Merge request reports