Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: Overhaul downstream config to properly export version and dependencies #230

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,26 @@ 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) # 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)
Expand All @@ -52,12 +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}/"
)

gaudi_install(CMAKE cmake/${PROJECT_NAME}Config.cmake)

include(cmake/k4FWCoreCreateConfig.cmake)
11 changes: 0 additions & 11 deletions cmake/k4FWCoreConfig.cmake

This file was deleted.

34 changes: 34 additions & 0 deletions cmake/k4FWCoreConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 22 additions & 0 deletions cmake/k4FWCoreCreateConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +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}/"
)
8 changes: 8 additions & 0 deletions test/downstream-project-cmake-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading