Skip to content

Commit

Permalink
build: CMake find directives, policy grouping (acts-project#4026)
Browse files Browse the repository at this point in the history
This changes:

- The way Python is found through `CMP0094`, which sets `Python_STRATEGY=LOCATION`:
  > LOCATION: Stops lookup as soon as a version satisfying version constraints is founded. This is the default if policy [CMP0094](https://cmake.org/cmake/help/latest/policy/CMP0094.html#policy:CMP0094) is set to NEW.
- Sets `CMAKE_FIND_FRAMEWORK=LAST` which instructs CMake to consider macOS *frameworks* after all other sources, which is e.g. relevant for Python (see above)
- Groups all policy decisions into one block in the main `CMakeLists.txt`.
  • Loading branch information
paulgessinger authored Jan 16, 2025
1 parent dd0a9d4 commit 58b1361
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
50 changes: 30 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,36 @@ include(ActsRetrieveVersion)

project(Acts VERSION ${_acts_version} LANGUAGES CXX)

# policy settings

# Steers how project() handles the VERSION option
cmake_policy(SET CMP0048 NEW)

# the `<project_name>_VERSION` variables set by `setup(... VERSION ...)` have
# only local scope, i.e. they are not accessible her for dependencies added
# via `add_subdirectory`. this overrides the `project(...)` function for
# sub-projects such that the resulting `<project_name>_VERSION` has
# global scope and is accessible within the main project later on.
macro(project)
_project(${ARGN})
set(${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION}" CACHE INTERNAL "")
endmacro()

# Controls the way python is located
if(POLICY CMP0094)
cmake_policy(SET CMP0094 NEW)
endif()

# Controls behavior of DOWNLOAD_EXTRACT_TIMESTAMP
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()

# Use boost's cmake config files
if(POLICY CMP0167)
cmake_policy(SET CMP0167 NEW)
endif()

# build options

# all options and compile-time parameters must be defined here for clear
Expand Down Expand Up @@ -253,17 +283,8 @@ set(_acts_boost_recommended_version 1.78.0)
# Include the sources for the external dependencies.
include(ActsExternSources)

# Controls behavior of DOWNLOAD_EXTRACT_TIMESTAMP
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()

# required packages
if(ACTS_SETUP_BOOST)
if(POLICY CMP0167)
cmake_policy(SET CMP0167 NEW)
endif()

# Enable both program_options and unit_test_framework to reduce complexity
# Also Cuda tests seem to use program_options
if(
Expand Down Expand Up @@ -311,17 +332,6 @@ endif()

find_package(Filesystem REQUIRED)

# the `<project_name>_VERSION` variables set by `setup(... VERSION ...)` have
# only local scope, i.e. they are not accessible her for dependencies added
# via `add_subdirectory`. this overrides the `project(...)` function for
# sub-projects such that the resulting `<project_name>_VERSION` has
# global scope and is accessible within the main project later on.
cmake_policy(SET CMP0048 NEW)
macro(project)
_project(${ARGN})
set(${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION}" CACHE INTERNAL "")
endmacro()

# CUDA settings are collected here in a macro, so that they can be reused by different plugins
macro(enable_cuda)
enable_language(CUDA)
Expand Down
1 change: 1 addition & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_COMPILE_WARNING_AS_ERROR": "ON",
"CMAKE_FIND_FRAMEWORK": "LAST",
"ACTS_FORCE_ASSERTIONS": "ON",
"ACTS_ENABLE_LOG_FAILURE_THRESHOLD": "ON",
"ACTS_BUILD_BENCHMARKS": "ON",
Expand Down

0 comments on commit 58b1361

Please sign in to comment.