From 659d3250ac8ada44d8a8d4f3a6075f001ff42c74 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Tue, 3 Sep 2024 11:07:52 +0200 Subject: [PATCH 1/5] Make sure to not continue without any podio --- CMakeLists.txt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce736d80..181bdd7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,11 +22,18 @@ project(k4FWCore) find_package(ROOT COMPONENTS RIO Tree REQUIRED) find_package(Gaudi REQUIRED) - find_package(podio 0.16.3) # this will not find 1.0 and newer - if(NOT podio_FOUND) - # we try to find a newer version now - find_package(podio 1.0 REQUIRED) - endif() +find_package(podio 0.16.3 QUIET) # this will not find 1.0 and newer +if(NOT podio_FOUND) + # we try to find a newer version now + find_package(podio 1.0 REQUIRED) +else() + message(WARNING "Found podio < 1.0. This should still work, but consider moving to a newer version") +endif() + +if(NOT podio_FOUND) + message(FATAL_ERROR "Could not find a suitable version of podio") +endif() + find_package(EDM4HEP REQUIRED) include(cmake/Key4hepConfig.cmake) From e0759400464fd317cac4c2894f94706f04da46ad Mon Sep 17 00:00:00 2001 From: tmadlener Date: Tue, 3 Sep 2024 11:30:38 +0200 Subject: [PATCH 2/5] Configure the cmake config for downstream consumption - Make sure all required dependencies are also detected in downstream users - Add some legacy variables --- CMakeLists.txt | 3 ++- cmake/k4FWCoreConfig.cmake | 11 ----------- cmake/k4FWCoreConfig.cmake.in | 34 ++++++++++++++++++++++++++++++++ cmake/k4FWCoreCreateConfig.cmake | 6 ++++++ 4 files changed, 42 insertions(+), 12 deletions(-) delete mode 100644 cmake/k4FWCoreConfig.cmake create mode 100644 cmake/k4FWCoreConfig.cmake.in create mode 100644 cmake/k4FWCoreCreateConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 181bdd7a..dcb14ba8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,5 +66,6 @@ install(EXPORT ${PROJECT_NAME}Targets DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/" ) -gaudi_install(CMAKE cmake/${PROJECT_NAME}Config.cmake) +include(cmake/k4FWCoreCreateConfig.cmake) +gaudi_install(CMAKE ${PROJECT_BINARY_DIR}/k4FWCoreConfig.cmake) diff --git a/cmake/k4FWCoreConfig.cmake b/cmake/k4FWCoreConfig.cmake deleted file mode 100644 index 50a30cc7..00000000 --- a/cmake/k4FWCoreConfig.cmake +++ /dev/null @@ -1,11 +0,0 @@ - -include(CMakeFindDependencyMacro) -find_dependency(podio REQUIRED) -find_dependency(Gaudi REQUIRED) - -# - Include the targets file to create the imported targets that a client can -# link to (libraries) or execute (programs) -include("${CMAKE_CURRENT_LIST_DIR}/k4FWCoreTargets.cmake") - -get_property(TEST_K4FWCORE_LIBRARY TARGET k4FWCore::k4FWCore PROPERTY LOCATION) -find_package_handle_standard_args(k4FWCore DEFAULT_MSG CMAKE_CURRENT_LIST_FILE TEST_K4FWCORE_LIBRARY) diff --git a/cmake/k4FWCoreConfig.cmake.in b/cmake/k4FWCoreConfig.cmake.in new file mode 100644 index 00000000..3478680f --- /dev/null +++ b/cmake/k4FWCoreConfig.cmake.in @@ -0,0 +1,34 @@ +############################################################################### +# k4FWCore CMake Config +# +# Exported Targets +# - k4FWCore::k4FWCore The core library containing the PodioDataSvc +# and the KeepDropSwitch +# - k4FWCore::k4FWCorePlugins The plugin library for the core plugins +# provided by k4FWCore. Includes all major +# services for I/O and as well as some utility +# algorithms +# - k4FWCore::k4Interface The (header-only) target containing all +# interface definitions +# +############################################################################### +@PACKAGE_INIT@ + +set_and_check(k4FWCore_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@") +set_and_check(k4FWCore_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@") + +include(CMakeFindDependencyMacro) +find_dependency(podio @podio_VERSION@) +find_dependency(Gaudi @Gaudi_VERSION@) +find_dependency(EDM4HEP @EDM4HEP_VERSION@) +find_dependency(ROOT @ROOT_VERSION@ COMPONENTS RIO Tree) + +if(NOT TARGET k4FWCore::k4FWCore) + include("${CMAKE_CURRENT_LIST_DIR}/k4FWCoreTargets.cmake") +endif() + +check_required_components(k4FWCore) + +include(FindPackageHandleStandardArgs) +get_property(TEST_K4FWCORE_LIBRARY TARGET k4FWCore::k4FWCore PROPERTY LOCATION) +find_package_handle_standard_args(k4FWCore DEFAULT_MSG CMAKE_CURRENT_LIST_FILE TEST_K4FWCORE_LIBRARY) diff --git a/cmake/k4FWCoreCreateConfig.cmake b/cmake/k4FWCoreCreateConfig.cmake new file mode 100644 index 00000000..a80ae942 --- /dev/null +++ b/cmake/k4FWCoreCreateConfig.cmake @@ -0,0 +1,6 @@ +include(CMakePackageConfigHelpers) + +configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/k4FWCoreConfig.cmake.in + ${PROJECT_BINARY_DIR}/k4FWCoreConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/k4FWCore + PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR) From f97f1adcd0e20d7a90370cdb3cf53a4be3ffe944 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Tue, 8 Oct 2024 12:44:48 +0200 Subject: [PATCH 3/5] Add version information to CMakeLists --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index dcb14ba8..88375707 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,12 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.15) project(k4FWCore) +set(${PROJECT_NAME}_VERSION_MAJOR 1) +set(${PROJECT_NAME}_VERSION_MINOR 1) +set(${PROJECT_NAME}_VERSION_PATCH 0) + +set( ${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}" ) + find_package(ROOT COMPONENTS RIO Tree REQUIRED) find_package(Gaudi REQUIRED) find_package(podio 0.16.3 QUIET) # this will not find 1.0 and newer From cff6168d5924b096f3eec4e5d45bfea71bc892f6 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Tue, 8 Oct 2024 14:58:04 +0200 Subject: [PATCH 4/5] Export version for downstream usage Move all downstream related config to one file --- CMakeLists.txt | 9 --------- cmake/k4FWCoreCreateConfig.cmake | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 88375707..1dd78959 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,13 +65,4 @@ if(ENABLE_CPACK) include(cmake/${PROJECT_NAME}CPack.cmake) endif() - -install(EXPORT ${PROJECT_NAME}Targets - NAMESPACE ${PROJECT_NAME}:: - FILE "${PROJECT_NAME}Targets.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/" - ) - include(cmake/k4FWCoreCreateConfig.cmake) - -gaudi_install(CMAKE ${PROJECT_BINARY_DIR}/k4FWCoreConfig.cmake) diff --git a/cmake/k4FWCoreCreateConfig.cmake b/cmake/k4FWCoreCreateConfig.cmake index a80ae942..4f027e44 100644 --- a/cmake/k4FWCoreCreateConfig.cmake +++ b/cmake/k4FWCoreCreateConfig.cmake @@ -1,6 +1,22 @@ include(CMakePackageConfigHelpers) +# Version file is same wherever we are +write_basic_package_version_file(${PROJECT_BINARY_DIR}/k4FWCoreConfigVersion.cmake + VERSION ${k4FWCore_VERSION} + COMPATIBILITY SameMajorVersion) + + configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/k4FWCoreConfig.cmake.in ${PROJECT_BINARY_DIR}/k4FWCoreConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/k4FWCore PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/k4FWCoreConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/k4FWCoreConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) + +install(EXPORT ${PROJECT_NAME}Targets + NAMESPACE ${PROJECT_NAME}:: + FILE "${PROJECT_NAME}Targets.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/" +) From 1776700d9317a626db8dfa33490349c6990e02c7 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Tue, 8 Oct 2024 15:04:08 +0200 Subject: [PATCH 5/5] Add downstream tests to make sure version is usable --- test/downstream-project-cmake-test/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/downstream-project-cmake-test/CMakeLists.txt b/test/downstream-project-cmake-test/CMakeLists.txt index f316e8ef..6eda9cc2 100644 --- a/test/downstream-project-cmake-test/CMakeLists.txt +++ b/test/downstream-project-cmake-test/CMakeLists.txt @@ -23,5 +23,13 @@ project(DownstreamProjectUsingk4FWCore) find_package(k4FWCore) +if (NOT DEFINED ${k4FWCore_VERSION}) + message(FATAL_ERROR "CAnnot find k4FWCore version information") +endif() + +if (NOT ${k4FWCore_VERSION} MATCHES "^[0-9]+\\.[0-9+](\\.[0-9]+)?$") + message(FATEL_ERROR "Exported k4FWCore version cannot be used as a version: " ${k4FWCore_VERSION}) +endif() + add_executable(appUsingk4FWCore main.cxx) target_link_libraries(appUsingk4FWCore k4FWCore::k4FWCore)