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:
- 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 - Use CMake's
CMakePackageConfigHelpers
module to generate theCLHEPConfig.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 whenfind_package
loadsCLHEPConfig.cmake
.
- 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.
- source =/= build can be checked directly in
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.