Skip to content

CMake improvements: Out-of-source builds, Generation of CLHEPConfig.cmake

These changes were originally proposed by Seth Johnson from ORNL through my GitHub fork, with some updates from me as well (but want to ensure due credit to Seth!):

The changes should not result in any change in behaviour:

  1. Use the range form of cmake_minimum_required so that newer versions can be used with appropriate policies set. This is fully back compatible with CLHEP's min requirement of CMake 3.2
  2. Use CMake's CMakePackageConfigHelpers module to generate the CLHEPConfig.cmake file
    • Simplifies the setup/generation a little
    • Avoids -I/relative/../path potentially appearing in flags for clients using CLHEP. Seth reported this caused some issues in certain builds. This still retains full relative/relocatable paths, just that CMake will now resolve them to absolute when find_package loads CLHEPConfig.cmake.
  3. Simplification to the out-of-source build check
    • source =/= build can be checked directly in if()
    • Preventing use of a subdirectory can be checked by requiring the binary directory (string) does not contain the source directory (string) starting at index 0 of the binary dir string. This is more robust than the regex check.

It may be worth reviewing whether the "full" out of source build requirement could be reduced to allowing subdirectory builds. If that's still a requirement though, the above check should enforce this better.

Merge request reports