From 7a9eb15812d1f0ab18219276b2de73080ae2137b Mon Sep 17 00:00:00 2001 From: Eric Flumerfelt Date: Mon, 20 Oct 2025 14:58:05 -0500 Subject: [PATCH 1/2] Add CMake target export language to automatically generate KinKalConfig.cmake, KinKalConfigVerison.cmake and KinKalTargets.cmake. This will allow find_package(KinKal) to work correctly in downstream packages, and enable target-style library includes. Add missing typename declarations for files used in ROOT dictionaries. --- CMakeLists.txt | 38 +++++++++++++++++++++++++++---- Detector/CMakeLists.txt | 4 +++- Examples/CMakeLists.txt | 4 +++- FindKinKal.cmake | 28 ----------------------- Fit/CMakeLists.txt | 4 +++- Fit/Track.hh | 2 +- General/CMakeLists.txt | 4 +++- Geometry/CMakeLists.txt | 4 +++- MatEnv/CMakeLists.txt | 4 +++- Trajectory/CMakeLists.txt | 4 +++- Trajectory/PiecewiseTrajectory.hh | 12 +++++----- cmake/KinKalConfig.cmake.in | 8 +++++++ 12 files changed, 70 insertions(+), 46 deletions(-) delete mode 100644 FindKinKal.cmake create mode 100755 cmake/KinKalConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e0c6046..097def2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) "Debug" "Release") endif() -if (CMAKE_BUILD_TYPE MATCHES "^((p|P)(rofile|rof))|(release)$") +if (CMAKE_BUILD_TYPE MATCHES "^((p|P)(rofile|rof))|(release)|(RelWithDebInfo)$") message(STATUS "Setting build type to 'Release' instead of '${CMAKE_BUILD_TYPE}'.") set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE) @@ -55,7 +55,7 @@ find_package(Git) if(GIT_FOUND) execute_process( COMMAND ${GIT_EXECUTABLE} describe --tags - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE _build_version ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE @@ -197,8 +197,12 @@ add_subdirectory(Tests) install(TARGETS General Trajectory Geometry Detector Fit MatEnv Examples + EXPORT KinKalTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) # install headers # Globbing here is fine because it does not influence build behaviour @@ -234,4 +238,30 @@ export KINKAL_LIBRARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/lib ") - +# Set up CMake exports for find_package +set(KinKal_IN_TREE TRUE CACHE BOOL "Whether KinKal is in the current tree") +include(CMakePackageConfigHelpers) +install(EXPORT KinKalTargets + FILE KinKalTargets.cmake + NAMESPACE KinKal:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} +) + + write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion) + + configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION + ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake) + +install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake) + +export(EXPORT KinKalTargets + FILE "${PROJECT_BINARY_DIR}/KinKalTargets.cmake" + NAMESPACE KinKal:: +) diff --git a/Detector/CMakeLists.txt b/Detector/CMakeLists.txt index 4fa8f4ca..d3897073 100644 --- a/Detector/CMakeLists.txt +++ b/Detector/CMakeLists.txt @@ -11,7 +11,9 @@ add_library(Detector SHARED #message( "source dir detector " ${CMAKE_SOURCE_DIR}/..) # set top-level directory as include root -target_include_directories(Detector PRIVATE ${PROJECT_SOURCE_DIR}/..) +target_include_directories(Detector PUBLIC + $ + $) # link this library with ROOT libraries and other KinKal libraries target_link_libraries(Detector Trajectory General ${ROOT_LIBRARIES}) diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt index 9661d486..f85aca48 100644 --- a/Examples/CMakeLists.txt +++ b/Examples/CMakeLists.txt @@ -17,8 +17,10 @@ add_library(Examples SHARED StrawMaterial.cc ExamplesDict ) -target_include_directories(Examples PRIVATE ${PROJECT_SOURCE_DIR}/..) target_include_directories(Examples PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(Examples PUBLIC + $ + $) # link ROOT libraries target_link_libraries(Examples ${ROOT_LIBRARIES}) diff --git a/FindKinKal.cmake b/FindKinKal.cmake deleted file mode 100644 index 9fd88d22..00000000 --- a/FindKinKal.cmake +++ /dev/null @@ -1,28 +0,0 @@ -#- Try to find the KinKal package -# Once done this will define -# KINKAL_FOUND - System has KinKal -# KINKAL_INCLUDE_DIR - The directory needed to compile against KinKal classes -# KINKAL_LIBRARIES - The libraries needed to use KinKal - - -MESSAGE(STATUS "Adding KinKal include path $ENV{KINKAL_SOURCE_DIR}") -set(KINKAL_INCLUDE_DIR $ENV{KINKAL_SOURCE_DIR}/..) -mark_as_advanced(KINKAL_INCLUDE_DIR) -MESSAGE(STATUS "Looking for KinKal libraries in directory $ENV{KINKAL_LIBRARY_DIR}") -foreach( KKLIB MatEnv Trajectory Detector Fit General ) - find_library(${KKLIB}_LIBRARY KinKal_${KKLIB} HINTS $ENV{KINKAL_LIBRARY_DIR}) - MESSAGE("Looking for KinKal library " ${KKLIB}) - if(${KKLIB}_LIBRARY) - mark_as_advanced(${KKLIB}_LIBRARY) - MESSAGE("Found KinKal library " ${KKLIB} " as " ${${KKLIB}_LIBRARY}) - list(APPEND KINKAL_LIBRARIES ${${KKLIB}_LIBRARY}) - endif() -endforeach() - -IF(KINKAL_LIBRARIES) - SET(KINKAL_FOUND TRUE) - MESSAGE(STATUS "Found KinKal libraries") -ENDIF() - -mark_as_advanced(KINKAL_LIBRARIES) - diff --git a/Fit/CMakeLists.txt b/Fit/CMakeLists.txt index ca69611b..60299016 100644 --- a/Fit/CMakeLists.txt +++ b/Fit/CMakeLists.txt @@ -12,7 +12,9 @@ add_library(Fit SHARED ) # set top-level directory as include root -target_include_directories(Fit PRIVATE ${PROJECT_SOURCE_DIR}/..) +target_include_directories(Fit PUBLIC + $ + $) # link this library with ROOT libraries target_link_libraries(Fit Detector Trajectory General ${ROOT_LIBRARIES}) diff --git a/Fit/Track.hh b/Fit/Track.hh index 1109f941..2230912a 100644 --- a/Fit/Track.hh +++ b/Fit/Track.hh @@ -324,7 +324,7 @@ namespace KinKal { // find the range of existing ptraj pieces that overlaps with this domain's range using KTRAJPTR = std::shared_ptr; using DKTRAJ = std::deque; - using DKTRAJCITER = DKTRAJ::const_iterator; + using DKTRAJCITER = typename DKTRAJ::const_iterator; DKTRAJCITER first,last; fittraj_->pieceRange(domain->range(),first,last); // loop over these pieces diff --git a/General/CMakeLists.txt b/General/CMakeLists.txt index a8bffffd..556b054b 100644 --- a/General/CMakeLists.txt +++ b/General/CMakeLists.txt @@ -34,7 +34,9 @@ ROOT_GENERATE_DICTIONARY(GeneralDict ) # set top-level directory as include root -target_include_directories(General PRIVATE ${PROJECT_SOURCE_DIR}/..) +target_include_directories(General PUBLIC + $ + $) # link this library with ROOT libraries target_link_libraries(General ${ROOT_LIBRARIES}) diff --git a/Geometry/CMakeLists.txt b/Geometry/CMakeLists.txt index b67fa591..2c706a64 100644 --- a/Geometry/CMakeLists.txt +++ b/Geometry/CMakeLists.txt @@ -21,7 +21,9 @@ add_library(Geometry SHARED set(CMAKE_SHARED_LIBRARY_PREFIX "libKinKal_") # set top-level directory as include root -target_include_directories(Geometry PRIVATE ${PROJECT_SOURCE_DIR}/..) +target_include_directories(Geometry PUBLIC + $ + $) # link this library with ROOT libraries target_link_libraries(Geometry General ${ROOT_LIBRARIES}) diff --git a/MatEnv/CMakeLists.txt b/MatEnv/CMakeLists.txt index 600aa20f..e3d5b22c 100644 --- a/MatEnv/CMakeLists.txt +++ b/MatEnv/CMakeLists.txt @@ -18,7 +18,9 @@ add_library(MatEnv SHARED ) # set top-level directory as include root -target_include_directories(MatEnv PRIVATE ${PROJECT_SOURCE_DIR}/..) +target_include_directories(MatEnv PUBLIC + $ + $) # set shared library version equal to project version set_target_properties(MatEnv PROPERTIES VERSION ${PROJECT_VERSION} PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX}) diff --git a/Trajectory/CMakeLists.txt b/Trajectory/CMakeLists.txt index 47697264..1042195c 100644 --- a/Trajectory/CMakeLists.txt +++ b/Trajectory/CMakeLists.txt @@ -24,7 +24,9 @@ ROOT_GENERATE_DICTIONARY(TrajectoryDict ) # set top-level directory as include root -target_include_directories(Trajectory PRIVATE ${PROJECT_SOURCE_DIR}/..) +target_include_directories(Trajectory PUBLIC + $ + $) # link this library with ROOT libraries target_link_libraries(Trajectory Geometry General ${ROOT_LIBRARIES}) diff --git a/Trajectory/PiecewiseTrajectory.hh b/Trajectory/PiecewiseTrajectory.hh index e7c6aa30..4d9cb365 100644 --- a/Trajectory/PiecewiseTrajectory.hh +++ b/Trajectory/PiecewiseTrajectory.hh @@ -21,8 +21,8 @@ namespace KinKal { public: using KTRAJPTR = std::shared_ptr; using DKTRAJ = std::deque; - using DKTRAJITER = DKTRAJ::iterator; - using DKTRAJCITER = DKTRAJ::const_iterator; + using DKTRAJITER = typename DKTRAJ::iterator; + using DKTRAJCITER = typename DKTRAJ::const_iterator; // forward calls to the pieces VEC3 position3(double time) const { return nearestPiece(time).position3(time); } VEC3 velocity(double time) const { return nearestPiece(time).velocity(time); } @@ -283,8 +283,8 @@ namespace KinKal { } template void PiecewiseTrajectory::pieceRange(TimeRange const& range, - std::deque>::const_iterator& first, - std::deque>::const_iterator& last ) const { + typename std::deque>::const_iterator &first, + typename std::deque>::const_iterator &last) const { first = last = pieces_.end(); // check for no overlap if(this->range().overlaps(range)){ @@ -298,8 +298,8 @@ namespace KinKal { } template void PiecewiseTrajectory::pieceRange(TimeRange const& range, - std::deque>::iterator& first, - std::deque>::iterator& last) { + typename std::deque>::iterator &first, + typename std::deque>::iterator &last) { first = last = pieces_.end(); // check for no overlap if(this->range().overlaps(range)){ diff --git a/cmake/KinKalConfig.cmake.in b/cmake/KinKalConfig.cmake.in new file mode 100755 index 00000000..e6740cac --- /dev/null +++ b/cmake/KinKalConfig.cmake.in @@ -0,0 +1,8 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/KinKalTargets.cmake") + +include(CMakeFindDependencyMacro) +find_dependency(ROOT) + +check_required_components(KinKal) \ No newline at end of file From 4a9904b436c59a6bb3ab4c54ea72e06c7297b462 Mon Sep 17 00:00:00 2001 From: eflumerf <61473357+eflumerf@users.noreply.github.com> Date: Tue, 21 Oct 2025 07:34:18 -0500 Subject: [PATCH 2/2] Fix install directories for cmake files --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 097def2d..e8782766 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,7 +244,7 @@ include(CMakePackageConfigHelpers) install(EXPORT KinKalTargets FILE KinKalTargets.cmake NAMESPACE KinKal:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} + DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake ) write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"