Skip to content

Commit

Permalink
Switch to target based cmake approach for LCIO targets
Browse files Browse the repository at this point in the history
- Use SIO targets
- Define LCIO targets and export them properly for downstream usage
- Keep some package specific install variables to keep backwards
compatibility
  • Loading branch information
tmadlener committed Jun 4, 2021
1 parent 355ad9a commit a5ea102
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 143 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ SET( LCIO_VERSION_MAJOR 2 )
SET( LCIO_VERSION_MINOR 16 )
SET( LCIO_VERSION_PATCH 1 )

SET( ${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}" )

### set correct LCIO version in relevant files ############################

configure_file (
Expand Down Expand Up @@ -312,7 +314,6 @@ MESSAGE( STATUS "SIO_PRINT_DEBUG = ${SIO_PRINT_DEBUG}" )
MESSAGE( STATUS "" )


# generate and install following configuration files
GENERATE_PACKAGE_CONFIGURATION_FILES( LCIOConfig.cmake LCIOConfigVersion.cmake )

INSTALL( FILES cmake/MacroCheckPackageLibs.cmake cmake/MacroCheckPackageVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
# generate and install the cmake configuration files for downstream consuming
# packages
include(cmake/lcioCreateConfig.cmake)
89 changes: 35 additions & 54 deletions cmake/LCIOConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,77 +1,58 @@
##############################################################################
# cmake configuration file for LCIO
#
# requires:
# MacroCheckPackageLibs.cmake for checking package libraries
# Exported Targets:
#
# returns following variables:
# LCIO::lcio Base LCIO library
# LCIO::lcioF77 Fortran77 bindings library
# SIO::sio The SIO library (ONLY if builtin SIO is used)
#
# LCIO_FOUND : set to TRUE if LCIO found
# if FIND_PACKAGE called with REQUIRED and COMPONENTS arguments
# LCIO_FOUND is only set to TRUE if ALL components are also found
# if REQUIRED is NOT set components may or may not be available
#
# LCIO_ROOT : path to this LCIO installation
# LCIO_VERSION : package version
# Exported Variables:
# The following variables are exported to keep a bit of backward compatibility
#
# LCIO_LIBRARIES : list of LCIO libraries (NOT including COMPONENTS)
# LCIO_INCLUDE_DIRS : list of paths to be used with INCLUDE_DIRECTORIES
# LCIO_LIBRARY_DIRS : list of paths to be used with LINK_DIRECTORIES
# LCIO_COMPONENT_LIBRARIES : list of LCIO component libraries
# LCIO_${COMPONENT}_FOUND : set to TRUE or FALSE for each library
# LCIO_${COMPONENT}_LIBRARY : path to individual libraries
# LCIO_${COMPONENT}_LIB_DEPENDS : individual library dependencies
# LCIO_LIBRARY_DIRS : list of paths to be used with LINK_DIRECTORIES#
#
# @author Jan Engels, Desy
##############################################################################
@PACKAGE_INIT@

SET( LCIO_ROOT "@CMAKE_INSTALL_PREFIX@" )
SET( LCIO_VERSION "@LCIO_VERSION@" )


# ---------- include dirs -----------------------------------------------------
# do not store find results in cache
SET( LCIO_INCLUDE_DIRS LCIO_INCLUDE_DIRS-NOTFOUND )
MARK_AS_ADVANCED( LCIO_INCLUDE_DIRS )

FIND_PATH( LCIO_INCLUDE_DIRS
NAMES EVENT/MCParticle.h
PATHS ${LCIO_ROOT}/include
NO_DEFAULT_PATH
)


set_and_check(LCIO_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
mark_as_advanced( LCIO_INCLUDE_DIRS )

# ---------- libraries --------------------------------------------------------
INCLUDE( "${LCIO_ROOT}/@CMAKE_INSTALL_LIBDIR@/cmake/MacroCheckPackageLibs.cmake" )
include(CMakeFindDependencyMacro)
find_dependency(Threads)

# only standard libraries should be passed as arguments to CHECK_PACKAGE_LIBS
# additional components are set by cmake in variable PKG_FIND_COMPONENTS
# first argument should be the package name
CHECK_PACKAGE_LIBS( LCIO lcio @CHECK_PACKAGE_SIO_LIBRARY@ )
# Other dependencies depend on the configuration we are using
if(@BUILD_ROOTDICT@)
find_dependency(ROOT @ROOT_VERSION@)
endif()

if(@SIO_FOUND@)
find_dependency(SIO)
else()
# If we have builtin SIO make the targets available
if(NOT TARGET SIO::sio)
include("${CMAKE_CURRENT_LIST_DIR}/SIOTargets.cmake")
endif()
endif()

if(NOT TARGET LCIO::lcio)
include("${CMAKE_CURRENT_LIST_DIR}/LCIOTargets.cmake")
endif()

check_required_components(LCIO)

# ---------- libraries dependencies -------------------------------------------
# this sets LCIO_${COMPONENT}_LIB_DEPENDS variables
#INCLUDE( "${LCIO_ROOT}/@CMAKE_INSTALL_LIBDIR@/cmake/LCIOLibDeps.cmake" )



## ------- zlib dependency ---------------------------------------
# better to install zlib together with lcio libraries
#FIND_PACKAGE( ZLIB QUIET )
#SET( LCIO_DEPENDS_LIBRARIES ${ZLIB_LIBRARIES} )
#INCLUDE( "@ILCSOFT_CMAKE_MODULES_ROOT@/MacroExportPackageDeps.cmake" )
#EXPORT_PACKAGE_DEPENDENCIES( LCIO ) # append ZLIB_LIBRARIES to LCIO_LIBRARIES unless FIND_PACKAGE_SKIP_DEPENDENCIES is set
## ---------------------------------------------------------------



# Make the target based approach backwards compatible by also exporting
# something in LCIO_LIBRARIES
get_target_property(LCIO_LIBRARY_DIRS TARGET LCIO::lcio PROPERTY LOCATION)
set(LCIO_LIBRARIES LCIO::lcio)
mark_as_advanced(LCIO_LIBRARIES LCIO_LIBRARY_DIRS)

# ---------- final checking ---------------------------------------------------
INCLUDE( FindPackageHandleStandardArgs )
# set LCIO_FOUND to TRUE if all listed variables are TRUE and not empty
# LCIO_COMPONENT_VARIABLES will be set if FIND_PACKAGE is called with REQUIRED argument
FIND_PACKAGE_HANDLE_STANDARD_ARGS( LCIO DEFAULT_MSG LCIO_ROOT LCIO_INCLUDE_DIRS LCIO_LIBRARIES ${LCIO_COMPONENT_VARIABLES} ) #ZLIB_LIBRARIES )

FIND_PACKAGE_HANDLE_STANDARD_ARGS( LCIO DEFAULT_MSG LCIO_INCLUDE_DIRS LCIO_LIBRARIES ${LCIO_COMPONENT_VARIABLES} )
16 changes: 0 additions & 16 deletions cmake/LCIOConfigVersion.cmake.in

This file was deleted.

39 changes: 0 additions & 39 deletions cmake/MacroGeneratePackageConfigFiles.cmake

This file was deleted.

1 change: 0 additions & 1 deletion cmake/ilcsoft_default_settings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ INCLUDE( MacroAddSharedLibrary )
INCLUDE( MacroInstallSharedLibrary )
INCLUDE( MacroInstallDirectory )
INCLUDE( MacroDisplayStandardVariables )
INCLUDE( MacroGeneratePackageConfigFiles )


# include ilcsoft default settings
Expand Down
38 changes: 38 additions & 0 deletions cmake/lcioCreateConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake")

include(CMakePackageConfigHelpers)

# Write a version file
write_basic_package_version_file(
${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${LCIO_VERSION}
# LCIO is fully backwards compatible, so any newer version should work
COMPATIBILITY AnyNewerVersion)

if(NOT SIO_FOUND)
# Install the SIOTargets similarly to the standalone version to make it easy
# to use them via the SIO::sio target in dependent projects
install(EXPORT SIOTargets
NAMESPACE SIO::
FILE SIOTargets.cmake
DESTINATION ${CMAKE_INSTALL_CMAKEDIR}/${PROJECT_NAME})
endif()

# Export the LCIO targets
install(EXPORT LCIOTargets
NAMESPACE LCIO::
FILE LCIOTargets.cmake
DESTINATION ${CMAKE_INSTALL_CMAKEDIR}/${PROJECT_NAME})

# Build the package config file
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/LCIOConfig.cmake.in
${PROJECT_BINARY_DIR}/cmake/LCIOConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_CMAKEDIR}/${PROJECT_NAME}
PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR)


# # install all the necessary config files
# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/LCIOConfigVersion.cmake
# INSTALL_DESTINATION ${CMAKE_INSTALL_CMAKEDIR}/${PROJECT_NAME}
# )
6 changes: 4 additions & 2 deletions sio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ SET_TARGET_PROPERTIES(sio PROPERTIES
SOVERSION ${${PROJECT_NAME}_SOVERSION}
)


# Install the targets and the headers
INSTALL(TARGETS sio
EXPORT SIOTargets
DESTINATION ${CMAKE_INSTALL_LIBDIR})

INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/sio DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SIO)

# mimic the SIOConfig.cmake variables for the LCIO project
SET( SIO_VERSION "${SIO_VERSION}" CACHE STRING "The SIO version" )
SET( CHECK_PACKAGE_SIO_LIBRARY "sio" CACHE STRING "The name of the builtin SIO library to check when searching for LCIO package" )
SET( CHECK_PACKAGE_SIO_LIBRARY "SIO::sio" CACHE STRING "The name of the builtin SIO library to check when searching for LCIO package" )
42 changes: 25 additions & 17 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,8 @@ SET_SOURCE_FILES_PROPERTIES(
)
# ----------------------------------------------------------------------------




# -------- include directories -----------------------------------------------
INCLUDE_DIRECTORIES( BEFORE "${LCIO_AID_HEADERS_OUTPUT_DIR}" )
INCLUDE_DIRECTORIES( BEFORE "${LCIO_CXX_HEADERS_DIR}" )

# install public headers
INSTALL_DIRECTORY( ${LCIO_CXX_HEADERS_DIR}/ DESTINATION include
INSTALL_DIRECTORY( ${LCIO_CXX_HEADERS_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PATTERN "*.txt" EXCLUDE
#PATTERN "*empty_ignore.h" EXCLUDE
PATTERN "*/SIO/*" EXCLUDE
Expand All @@ -277,28 +270,43 @@ INSTALL_DIRECTORY( ${LCIO_CXX_HEADERS_DIR}/ DESTINATION include
)

# install aid generated c++ headers
INSTALL_DIRECTORY( ${LCIO_AID_HEADERS_OUTPUT_DIR}/ DESTINATION include )
INSTALL_DIRECTORY( ${LCIO_AID_HEADERS_OUTPUT_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
# ----------------------------------------------------------------------------



# ------- libraries lcio + lcioF77 -------------------------------------------
ADD_LIBRARY( lcioF77 STATIC ${LCIO_CPPFORT_SRCS} )
INSTALL( TARGETS lcioF77 DESTINATION ${CMAKE_INSTALL_LIBDIR} )

ADD_SHARED_LIBRARY( lcio

ADD_LIBRARY(lcio SHARED
${LCIO_IMPL_SRCS}
${LCIO_IOIMPL_SRCS}
${LCIO_UTIL_SRCS}
${LCIO_SIO_SRCS}
${LCIO_MT_SRCS}
)
INSTALL_SHARED_LIBRARY( lcio DESTINATION ${CMAKE_INSTALL_LIBDIR} )
)
ADD_LIBRARY(LCIO::lcio ALIAS lcio)

TARGET_LINK_LIBRARIES( lcio ${CMAKE_THREAD_LIBS_INIT} )
TARGET_LINK_LIBRARIES( lcio PUBLIC Threads::Threads )
TARGET_LINK_LIBRARIES( lcio PUBLIC SIO::sio )
target_include_directories(lcio
PUBLIC
$<BUILD_INTERFACE:${LCIO_AID_HEADERS_OUTPUT_DIR}>
$<BUILD_INTERFACE:${LCIO_CXX_HEADERS_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

SET_TARGET_PROPERTIES(lcio PROPERTIES
# create *nix style library versions + symbolic links
VERSION ${${PROJECT_NAME}_VERSION}
SOVERSION ${${PROJECT_NAME}_SOVERSION}
)

ADD_LIBRARY( lcioF77 STATIC ${LCIO_CPPFORT_SRCS} )
TARGET_LINK_LIBRARIES( lcioF77 lcio )

INSTALL(TARGETS lcio lcioF77
EXPORT LCIOTargets
DESTINATION ${CMAKE_INSTALL_LIBDIR})

ADD_CUSTOM_TARGET( lib DEPENDS lcio lcioF77 )
# ----------------------------------------------------------------------------

Expand Down
10 changes: 0 additions & 10 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,6 @@ ENDIF()
#ADD_DEFINITIONS( "-Wno-long-long -fno-strict-aliasing" )


# -------- include directories -----------------------------------------------
INCLUDE_DIRECTORIES( BEFORE "${LCIO_AID_HEADERS_OUTPUT_DIR}" )
INCLUDE_DIRECTORIES( BEFORE "${LCIO_SOURCE_DIR}/sio/include" )
INCLUDE_DIRECTORIES( BEFORE "${LCIO_CXX_HEADERS_DIR}" )






# ==== add tests from the TESTS directory ====================================
MACRO( ADD_LCIO_TEST file )
IF( BUILD_TESTING )
Expand Down

0 comments on commit a5ea102

Please sign in to comment.