Skip to content

Commit

Permalink
build: Add cmake helper function for header compilation (#4083)
Browse files Browse the repository at this point in the history
This PR adds a CMake function that will

- Take all headers given explicitly either by glob or explicitly
- The first argument is a sort of scope target
- The function creates a new target with the suffix `_HEADERS`
- It loops over all input headers, creates a `.cpp` file which includes that header, and adds it to the `_HEADERS` target for compilation
- The target is excluded from the "default" build to not slow it down.

This will help static analysis tools like clang-tidy, because the `compile_commands.json` will be populated.

This PR also removes a leftover `ACTS_BUILD_NONCOMPILE_TESTS` that was unused.
  • Loading branch information
paulgessinger authored Feb 13, 2025
1 parent 9b97473 commit 316a385
Show file tree
Hide file tree
Showing 42 changed files with 127 additions and 268 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ else()
set(_default_examples_unit_tests OFF)
endif()
option(ACTS_BUILD_EXAMPLES_UNITTESTS "Build unit tests" ${_default_examples_unit_tests}) # default: ACTS_BUILD_UNITTESTS AND ACTS_BUILD_EXAMPLES
option(ACTS_BUILD_NONCOMPILE_TESTS "Build tests that check build failure invariants" OFF)
option(ACTS_RUN_CLANG_TIDY "Run clang-tidy static analysis" OFF)
# other options
option(ACTS_BUILD_DOCS "Build documentation" OFF)
Expand All @@ -128,6 +127,7 @@ set(ACTS_GPERF_INSTALL_DIR "" CACHE STRING "Hint to help find gperf if profiling

option(ACTS_ENABLE_LOG_FAILURE_THRESHOLD "Enable failing on log messages with level above certain threshold" OFF)
set(ACTS_LOG_FAILURE_THRESHOLD "" CACHE STRING "Log level above which an exception should be automatically thrown. If ACTS_ENABLE_LOG_FAILURE_THRESHOLD is set and this is unset, this will enable a runtime check of the log level.")
option(ACTS_COMPILE_HEADERS "Generate targets to compile header files" ON)
# gersemi: on

# handle option inter-dependencies and the everything flag
Expand Down Expand Up @@ -280,6 +280,9 @@ set(_acts_annoy_version 1.17.3)
# this version we will try so.
set(_acts_boost_recommended_version 1.78.0)

# Help with compiler flags discovery
include(ActsFunctions)

# Include the sources for the external dependencies.
include(ActsExternSources)

Expand Down
4 changes: 4 additions & 0 deletions Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,7 @@ add_subdirectory(src/Utilities)
add_subdirectory(src/Vertexing)
add_subdirectory(src/Visualization)
add_subdirectory(src/AmbiguityResolution)

acts_compile_headers(ActsCore GLOB
include/Acts/**/*.hpp
)
2 changes: 2 additions & 0 deletions Core/include/Acts/Propagator/detail/LoopStepperUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <Acts/Surfaces/Surface.hpp>
#include <Acts/Utilities/Result.hpp>

#include <type_traits>

namespace Acts::detail {

/// A helper type for providinig a propagation state which can be used with
Expand Down
2 changes: 2 additions & 0 deletions Examples/Algorithms/Digitization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ target_link_libraries(
PUBLIC ActsCore ActsExamplesFramework
)

acts_compile_headers(ActsExamplesDigitization GLOB "include/**/*.hpp")

install(
TARGETS ActsExamplesDigitization
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include "Acts/Utilities/AxisDefinitions.hpp"
#include "Acts/Utilities/BinningData.hpp"
#include "Acts/Utilities/Result.hpp"
#include "ActsExamples/Framework/RandomNumbers.hpp"
#include "ActsFatras/Digitization/DigitizationError.hpp"
Expand Down
2 changes: 2 additions & 0 deletions Examples/Algorithms/MaterialMapping/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ target_link_libraries(
PUBLIC ActsCore ActsExamplesFramework
)

acts_compile_headers(ActsExamplesMaterialMapping GLOB "include/**/*.hpp")

install(
TARGETS ActsExamplesMaterialMapping
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#pragma once

#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/Geometry/TrackingVolume.hpp"
#include "Acts/Material/IMaterialDecorator.hpp"
#include "Acts/Material/ISurfaceMaterial.hpp"
Expand Down
2 changes: 2 additions & 0 deletions Examples/Algorithms/Propagation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ target_link_libraries(
PUBLIC ActsCore ActsExamplesFramework
)

acts_compile_headers(ActsExamplesPropagation GLOB "include/**/*.hpp")

install(
TARGETS ActsExamplesPropagation
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
149 changes: 0 additions & 149 deletions Examples/Algorithms/Propagation/src/SimHitToSummaryConversion.cpp

This file was deleted.

2 changes: 2 additions & 0 deletions Examples/Algorithms/Traccc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ target_link_libraries(
ActsPluginDetray
)

acts_compile_headers(ActsExamplesTraccc GLOB "include/**/*.hpp")

install(TARGETS ActsExamplesTraccc LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
8 changes: 3 additions & 5 deletions Examples/Algorithms/TrackFinding/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ target_include_directories(

target_link_libraries(
ActsExamplesTrackFinding
PUBLIC
ActsCore
ActsExamplesFramework
ActsExamplesIoJson
ActsExamplesMagneticField
PUBLIC ActsCore ActsExamplesFramework ActsExamplesMagneticField
PRIVATE ROOT::Core ROOT::Geom ROOT::Graf ROOT::Hist ROOT::Gpad
)

acts_compile_headers(ActsExamplesTrackFinding GLOB "include/**/*.hpp")

# If Hashing examples are enabled, add them to the build
if(ACTS_BUILD_EXAMPLES_HASHING)
target_sources(
Expand Down

This file was deleted.

2 changes: 2 additions & 0 deletions Examples/Algorithms/TrackFindingML/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ target_link_libraries(
PUBLIC ActsCore ActsPluginOnnx ActsExamplesFramework
)

acts_compile_headers(ActsExamplesTrackFindingML GLOB "include/**/*.hpp")

install(
TARGETS ActsExamplesTrackFindingML
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
2 changes: 2 additions & 0 deletions Examples/Algorithms/TrackFitting/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ target_link_libraries(
PUBLIC ActsCore ActsExamplesFramework ActsExamplesMagneticField
)

acts_compile_headers(ActsExamplesTrackFitting GLOB "include/**/*.hpp")

install(
TARGETS ActsExamplesTrackFitting
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
2 changes: 2 additions & 0 deletions Examples/Detectors/ContextualDetector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ target_link_libraries(
ActsExamplesDetectorGeneric
)

acts_compile_headers(ActsExamplesDetectorContextual GLOB "include/**/*.hpp")

install(
TARGETS ActsExamplesDetectorContextual
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
2 changes: 2 additions & 0 deletions Examples/Detectors/GenericDetector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ add_library(
src/GenericDetectorElement.cpp
)

acts_compile_headers(ActsExamplesDetectorGeneric GLOB "include/**/*.hpp")

target_include_directories(
ActsExamplesDetectorGeneric
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand Down
2 changes: 2 additions & 0 deletions Examples/Detectors/MagneticField/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ target_link_libraries(
PRIVATE std::filesystem
)

acts_compile_headers(ActsExamplesMagneticField GLOB "include/**/*.hpp")

install(
TARGETS ActsExamplesMagneticField
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
2 changes: 2 additions & 0 deletions Examples/Detectors/TGeoDetector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ target_link_libraries(
ActsExamplesITkModuleSplitting
)

acts_compile_headers(ActsExamplesDetectorTGeo GLOB "include/**/*.hpp")

install(
TARGETS ActsExamplesDetectorTGeo
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
2 changes: 2 additions & 0 deletions Examples/Framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ if(NOT TBB_FOUND)
endif()
target_link_libraries(ActsExamplesFramework PUBLIC TBB::tbb)

acts_compile_headers(ActsExamplesFramework GLOB "include/**/*.hpp")

install(
TARGETS ActsExamplesFramework
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
1 change: 1 addition & 0 deletions Examples/Io/Csv/src/CsvOutputData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include <ActsExamples/EventData/Index.hpp>
#include <ActsExamples/Io/Csv/CsvInputOutput.hpp>

#include <cstdint>

Expand Down
3 changes: 3 additions & 0 deletions Examples/Io/Json/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ target_link_libraries(
ActsExamplesDigitization
ActsExamplesFramework
ActsExamplesMaterialMapping
ActsExamplesTrackFinding
)

acts_compile_headers(ActsExamplesIoJson GLOB "include/**/*.hpp")

install(TARGETS ActsExamplesIoJson LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
2 changes: 2 additions & 0 deletions Examples/Io/Obj/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ target_link_libraries(
PUBLIC ActsCore ActsExamplesFramework Threads::Threads
)

acts_compile_headers(ActsExamplesIoObj GLOB "include/**/*.hpp")

install(TARGETS ActsExamplesIoObj LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
Loading

0 comments on commit 316a385

Please sign in to comment.