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

[wip] Update cmake configuraton to targets based approach #140

Open
wants to merge 6 commits into
base: master
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
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app

# Default build ans install directory
/build
/install
22 changes: 12 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# cmake file for building LCIO
# @author Frank Gaede, DESY
# @author Jan Engels, DESY
CMAKE_MINIMUM_REQUIRED( VERSION 2.8 FATAL_ERROR )
CMAKE_MINIMUM_REQUIRED( VERSION 3.14 FATAL_ERROR )
########################################################


Expand All @@ -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 @@ -164,13 +166,12 @@ FIND_PACKAGE( SIO QUIET )
IF( NOT SIO_FOUND )
MESSAGE( STATUS "SIO not found on your system. Using builtin sio" )
ADD_SUBDIRECTORY( sio )
ELSE()
GET_TARGET_PROPERTY(_sio_lib_dir SIO::sio LOCATION)
MESSAGE(STATUS "Found SIO: " ${_sio_lib_dir})
ENDIF()

MESSAGE( STATUS "Using SIO (${SIO_VERSION})" )
MESSAGE( STATUS "SIO library: ${SIO_LIBRARIES}" )
MESSAGE( STATUS "SIO includes: ${SIO_INCLUDE_DIRS}" )

INCLUDE_DIRECTORIES( SYSTEM ${SIO_INCLUDE_DIRS} )

FIND_PACKAGE( Threads REQUIRED )

Expand Down Expand Up @@ -288,7 +289,9 @@ ENDIF()


# directory containing lcio tests
ADD_SUBDIRECTORY( ./tests )
IF( BUILD_TESTING )
ADD_SUBDIRECTORY( ./tests )
ENDIF()


### DOCUMENTATION ###########################################################
Expand All @@ -313,7 +316,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 LCIO::lcio 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.

25 changes: 0 additions & 25 deletions cmake/MacroAddSharedLibrary.cmake

This file was deleted.

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

This file was deleted.

14 changes: 0 additions & 14 deletions cmake/MacroInstallSharedLibrary.cmake

This file was deleted.

3 changes: 0 additions & 3 deletions cmake/ilcsoft_default_settings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ SET( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE ) # default in cmake 2.6
#SET( BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS}" CACHE BOOL "Set to OFF to build static libraries" FORCE )

# include helper macros
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}/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
${CMAKE_CURRENT_BINARY_DIR}/LCIOConfig.cmake
DESTINATION ${CMAKE_INSTALL_CMAKEDIR}/${PROJECT_NAME})
Loading