From 71553d00d563e9d8f2737ea03115eb4d71bae96b Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Wed, 5 May 2021 13:06:21 +0200 Subject: [PATCH 1/6] Bump minimum required cmake version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e52415bb..689df0c01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ) ######################################################## From 54df0abdde167bf204d871c4bc9e71091de77274 Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Thu, 6 May 2021 11:36:35 +0200 Subject: [PATCH 2/6] Make SIO cmake config more similar to standalone version --- CMakeLists.txt | 7 +++---- sio/CMakeLists.txt | 33 ++++++++++++++++++++++----------- src/cpp/CMakeLists.txt | 6 +++--- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 689df0c01..f0efb2788 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,13 +164,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 ) diff --git a/sio/CMakeLists.txt b/sio/CMakeLists.txt index 686e8eafa..c7fa389c5 100644 --- a/sio/CMakeLists.txt +++ b/sio/CMakeLists.txt @@ -21,22 +21,33 @@ FIND_PACKAGE( ZLIB REQUIRED ) INCLUDE( TestBigEndian ) TEST_BIG_ENDIAN( BIG_ENDIAN ) +# Build the SIO library +FILE( GLOB_RECURSE SIO_SRCS src/*.cc ) + +ADD_LIBRARY(sio SHARED ${SIO_SRCS}) +ADD_LIBRARY(SIO::sio ALIAS sio) + +TARGET_LINK_LIBRARIES(sio PRIVATE ZLIB::ZLIB) +TARGET_INCLUDE_DIRECTORIES(sio PUBLIC + $ + $ + ) +TARGET_COMPILE_DEFINITIONS(sio PUBLIC "-DSIO_LOGLVL=0") IF( NOT BIG_ENDIAN ) - ADD_DEFINITIONS( "-D__LITTLE_ENDIAN__" ) + TARGET_COMPILE_DEFINITIONS(sio PUBLIC "-D__LITTLE_ENDIAN__") ENDIF() -# Build the SIO library -FILE( GLOB_RECURSE SIO_SRCS src/*.cc ) +SET_TARGET_PROPERTIES(sio PROPERTIES + # create *nix style library versions + symbolic links + VERSION ${${PROJECT_NAME}_VERSION} + SOVERSION ${${PROJECT_NAME}_SOVERSION} + ) + -ADD_DEFINITIONS( "-DSIO_LOGLVL=0" ) -ADD_SHARED_LIBRARY( sio ${SIO_SRCS} ) -TARGET_INCLUDE_DIRECTORIES( sio PUBLIC include ) -TARGET_INCLUDE_DIRECTORIES( sio SYSTEM PUBLIC ${ZLIB_INCLUDE_DIR} ) -TARGET_LINK_LIBRARIES( sio ${ZLIB_LIBRARIES} ) -INSTALL_SHARED_LIBRARY( sio DESTINATION ${CMAKE_INSTALL_LIBDIR} ) +INSTALL(TARGETS sio + EXPORT SIOTargets + DESTINATION ${CMAKE_INSTALL_LIBDIR}) # mimic the SIOConfig.cmake variables for the LCIO project SET( SIO_VERSION "${SIO_VERSION}" CACHE STRING "The SIO version" ) -SET( SIO_LIBRARIES "sio" CACHE STRING "The SIO library" ) -SET( SIO_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" CACHE STRING "The path to SIO include directories" ) SET( CHECK_PACKAGE_SIO_LIBRARY "sio" CACHE STRING "The name of the builtin SIO library to check when searching for LCIO package" ) diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index 313afb1c4..51e54dda7 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -296,15 +296,13 @@ ADD_SHARED_LIBRARY( lcio INSTALL_SHARED_LIBRARY( lcio DESTINATION ${CMAKE_INSTALL_LIBDIR} ) TARGET_LINK_LIBRARIES( lcio ${CMAKE_THREAD_LIBS_INIT} ) -TARGET_LINK_LIBRARIES( lcio ${SIO_LIBRARIES} ) +TARGET_LINK_LIBRARIES( lcio PUBLIC SIO::sio ) TARGET_LINK_LIBRARIES( lcioF77 lcio ) ADD_CUSTOM_TARGET( lib DEPENDS lcio lcioF77 ) # ---------------------------------------------------------------------------- - - # -------- rootdict library -------------------------------------------------- IF( BUILD_ROOTDICT ) @@ -318,6 +316,8 @@ IF( BUILD_ROOTDICT ) # load MacroRootDict.cmake from ILCSOFT_CMAKE_MODULES INCLUDE(MacroRootDict) + GET_TARGET_PROPERTY(SIO_INCLUDE_DIRS SIO::sio INTERFACE_INCLUDE_DIRECTORIES) + # include directories to be passed over to rootcint SET( ROOT_DICT_INCLUDE_DIRS ${LCIO_AID_HEADERS_OUTPUT_DIR} From fcf43d81adc49645f2ad5e86658992e34402848a Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Thu, 6 May 2021 12:18:52 +0200 Subject: [PATCH 3/6] Switch to target based cmake approach for LCIO targets - Use SIO targets - Define LCIO targets and export them properly for downstream usage - Keep some package specific install variables to keep backwards compatibility --- CMakeLists.txt | 9 ++- cmake/LCIOConfig.cmake.in | 89 ++++++++------------- cmake/LCIOConfigVersion.cmake.in | 16 ---- cmake/MacroGeneratePackageConfigFiles.cmake | 39 --------- cmake/ilcsoft_default_settings.cmake | 1 - cmake/lcioCreateConfig.cmake | 38 +++++++++ sio/CMakeLists.txt | 6 +- src/cpp/CMakeLists.txt | 42 ++++++---- tests/CMakeLists.txt | 10 --- 9 files changed, 107 insertions(+), 143 deletions(-) delete mode 100644 cmake/LCIOConfigVersion.cmake.in delete mode 100644 cmake/MacroGeneratePackageConfigFiles.cmake create mode 100644 cmake/lcioCreateConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f0efb2788..cea52c3b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ( @@ -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) diff --git a/cmake/LCIOConfig.cmake.in b/cmake/LCIOConfig.cmake.in index ee589b236..3e1d7b5e3 100644 --- a/cmake/LCIOConfig.cmake.in +++ b/cmake/LCIOConfig.cmake.in @@ -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} ) diff --git a/cmake/LCIOConfigVersion.cmake.in b/cmake/LCIOConfigVersion.cmake.in deleted file mode 100644 index 87ecbd6cf..000000000 --- a/cmake/LCIOConfigVersion.cmake.in +++ /dev/null @@ -1,16 +0,0 @@ -############################################################################## -# this file is parsed when FIND_PACKAGE is called with version argument -# -# @author Jan Engels, Desy IT -############################################################################## -SET( LCIO_ROOT "@CMAKE_INSTALL_PREFIX@" ) - - -SET( ${PACKAGE_FIND_NAME}_VERSION_MAJOR @LCIO_VERSION_MAJOR@ ) -SET( ${PACKAGE_FIND_NAME}_VERSION_MINOR @LCIO_VERSION_MINOR@ ) -SET( ${PACKAGE_FIND_NAME}_VERSION_PATCH @LCIO_VERSION_PATCH@ ) - - -INCLUDE( "${LCIO_ROOT}/@CMAKE_INSTALL_LIBDIR@/cmake/MacroCheckPackageVersion.cmake" ) -CHECK_PACKAGE_VERSION( ${PACKAGE_FIND_NAME} @LCIO_VERSION@ ) - diff --git a/cmake/MacroGeneratePackageConfigFiles.cmake b/cmake/MacroGeneratePackageConfigFiles.cmake deleted file mode 100644 index e4a7b1259..000000000 --- a/cmake/MacroGeneratePackageConfigFiles.cmake +++ /dev/null @@ -1,39 +0,0 @@ -#GET_FILENAME_COMPONENT( _current_dir ${CMAKE_CURRENT_LIST_FILE} PATH ) - -# helper macro for generating project configuration file -MACRO( GENERATE_PACKAGE_CONFIGURATION_FILES ) - - FOREACH( arg ${ARGN} ) - IF( ${arg} MATCHES "Config.cmake" ) - IF( EXISTS "${PROJECT_SOURCE_DIR}/cmake/${arg}.in" ) - CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/cmake/${arg}.in" - "${PROJECT_BINARY_DIR}/${arg}" @ONLY - ) - INSTALL( FILES "${PROJECT_BINARY_DIR}/${arg}" DESTINATION . ) - #IF( EXISTS "${_current_dir}/MacroCheckPackageLibs.cmake" ) - # INSTALL( FILES "${_current_dir}/MacroCheckPackageLibs.cmake" DESTINATION cmake ) - #ENDIF() - #IF( EXISTS "${_current_dir}/MacroExportPackageDeps.cmake" ) - # INSTALL( FILES "${_current_dir}/MacroExportPackageDeps.cmake" DESTINATION cmake ) - #ENDIF() - ENDIF() - ENDIF() - - - IF( ${arg} MATCHES "ConfigVersion.cmake" ) - # version configuration file - IF( EXISTS "${PROJECT_SOURCE_DIR}/cmake/${arg}.in" ) - CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/cmake/${arg}.in" - "${PROJECT_BINARY_DIR}/${arg}" @ONLY - ) - INSTALL( FILES "${PROJECT_BINARY_DIR}/${arg}" DESTINATION . ) - #IF( EXISTS "${_current_dir}/MacroCheckPackageVersion.cmake" ) - # INSTALL( FILES "${_current_dir}/MacroCheckPackageVersion.cmake" DESTINATION cmake ) - #ENDIF() - ENDIF( EXISTS "${PROJECT_SOURCE_DIR}/cmake/${arg}.in" ) - ENDIF() - - ENDFOREACH() - -ENDMACRO( GENERATE_PACKAGE_CONFIGURATION_FILES ) - diff --git a/cmake/ilcsoft_default_settings.cmake b/cmake/ilcsoft_default_settings.cmake index de2eeb0a7..02088a165 100644 --- a/cmake/ilcsoft_default_settings.cmake +++ b/cmake/ilcsoft_default_settings.cmake @@ -10,7 +10,6 @@ INCLUDE( MacroAddSharedLibrary ) INCLUDE( MacroInstallSharedLibrary ) INCLUDE( MacroInstallDirectory ) INCLUDE( MacroDisplayStandardVariables ) -INCLUDE( MacroGeneratePackageConfigFiles ) # include ilcsoft default settings diff --git a/cmake/lcioCreateConfig.cmake b/cmake/lcioCreateConfig.cmake new file mode 100644 index 000000000..9b46a1c59 --- /dev/null +++ b/cmake/lcioCreateConfig.cmake @@ -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}) diff --git a/sio/CMakeLists.txt b/sio/CMakeLists.txt index c7fa389c5..125c85d40 100644 --- a/sio/CMakeLists.txt +++ b/sio/CMakeLists.txt @@ -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" ) diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index 51e54dda7..c767ea0dd 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -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 @@ -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 + $ + $ + $ + ) + +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 ) # ---------------------------------------------------------------------------- diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 064da0185..a07ade9c0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 ) From fab7f25dc67acc495e25b281ae7a5cdb03bbede5 Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Fri, 4 Jun 2021 17:57:29 +0200 Subject: [PATCH 4/6] Add .gitignore with some defaults --- .gitignore | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..39e2a3a45 --- /dev/null +++ b/.gitignore @@ -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 From ef18cb99c28b06d2138beabc356e42abc64215e5 Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Mon, 7 Jun 2021 12:07:14 +0200 Subject: [PATCH 5/6] Make root dicts use target based definitions --- cmake/MacroAddSharedLibrary.cmake | 25 ------------------------- cmake/MacroInstallSharedLibrary.cmake | 14 -------------- cmake/ilcsoft_default_settings.cmake | 2 -- src/cpp/CMakeLists.txt | 21 ++++++++++----------- 4 files changed, 10 insertions(+), 52 deletions(-) delete mode 100644 cmake/MacroAddSharedLibrary.cmake delete mode 100644 cmake/MacroInstallSharedLibrary.cmake diff --git a/cmake/MacroAddSharedLibrary.cmake b/cmake/MacroAddSharedLibrary.cmake deleted file mode 100644 index 840d92d95..000000000 --- a/cmake/MacroAddSharedLibrary.cmake +++ /dev/null @@ -1,25 +0,0 @@ -# create symbolic lib target for calling library targets -#ADD_CUSTOM_TARGET( lib ) - -MACRO( ADD_SHARED_LIBRARY _name ) - - ADD_LIBRARY( ${_name} SHARED ${ARGN} ) - - #ADD_DEPENDENCIES( lib ${_name} ) - - # change lib_target properties - SET_TARGET_PROPERTIES( ${_name} PROPERTIES - # create *nix style library versions + symbolic links - VERSION ${${PROJECT_NAME}_VERSION} - SOVERSION ${${PROJECT_NAME}_SOVERSION} - ) - - # install library - #INSTALL( TARGETS ${_name} DESTINATION lib PERMISSIONS - # OWNER_READ OWNER_WRITE OWNER_EXECUTE - # GROUP_READ GROUP_EXECUTE - # WORLD_READ WORLD_EXECUTE - #) - -ENDMACRO( ADD_SHARED_LIBRARY ) - diff --git a/cmake/MacroInstallSharedLibrary.cmake b/cmake/MacroInstallSharedLibrary.cmake deleted file mode 100644 index 37c0995b6..000000000 --- a/cmake/MacroInstallSharedLibrary.cmake +++ /dev/null @@ -1,14 +0,0 @@ -# wrapper macro for installing a shared library with -# correct permissions -MACRO( INSTALL_SHARED_LIBRARY ) - - # install library - INSTALL( TARGETS ${ARGN} - PERMISSIONS - OWNER_READ OWNER_WRITE OWNER_EXECUTE - GROUP_READ GROUP_EXECUTE - WORLD_READ WORLD_EXECUTE - ) - -ENDMACRO( INSTALL_SHARED_LIBRARY ) - diff --git a/cmake/ilcsoft_default_settings.cmake b/cmake/ilcsoft_default_settings.cmake index 02088a165..feb3ec352 100644 --- a/cmake/ilcsoft_default_settings.cmake +++ b/cmake/ilcsoft_default_settings.cmake @@ -6,8 +6,6 @@ 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 ) diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index c767ea0dd..902d3b42d 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -315,9 +315,6 @@ ADD_CUSTOM_TARGET( lib DEPENDS lcio lcioF77 ) IF( BUILD_ROOTDICT ) - #fg: for ROOT 6 we need the .src/cpp as include directory - INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ) - # special rootcint definitions for lcio # SET( ROOT_DICT_CINT_DEFINITIONS -DHANDLE_LCIO_EXCEPTIONS=IGNORED_FOR_CINT ) @@ -346,7 +343,7 @@ IF( BUILD_ROOTDICT ) # FILE( GLOB_RECURSE UTIL_CXX_HEADERS_LIST ${LCIO_CXX_HEADERS_DIR}/UTIL/*.h ) # list of headers to exclude - FILE( GLOB_RECURSE exclude_headers + SET( exclude_headers ${LCIO_CXX_HEADERS_DIR}/empty_ignore.h ${LCIO_CXX_HEADERS_DIR}/UTIL/LCWarning.h ${LCIO_CXX_HEADERS_DIR}/UTIL/LCFourVector.h @@ -409,12 +406,13 @@ IF( BUILD_ROOTDICT ) # ------ build lcioDict library --------------------------------- + ADD_LIBRARY( lcioDict ${lcio_rootdict_sources} ) + SET_TARGET_PROPERTIES( lcioDict PROPERTIES + # create *nix style library versions + symbolic links + VERSION ${${PROJECT_NAME}_VERSION} + SOVERSION ${${PROJECT_NAME}_SOVERSION}) - INCLUDE_DIRECTORIES( "${ROOT_DICT_OUTPUT_DIR}" ) - INCLUDE_DIRECTORIES( SYSTEM "${ROOT_INCLUDE_DIRS}" ) - - ADD_SHARED_LIBRARY( lcioDict ${lcio_rootdict_sources} ) - TARGET_LINK_LIBRARIES( lcioDict ${ROOT_LIBRARIES} lcio ) + TARGET_LINK_LIBRARIES(lcioDict LCIO::lcio ROOT::Core) IF( APPLE ) @@ -433,8 +431,9 @@ IF( BUILD_ROOTDICT ) ADD_CUSTOM_TARGET( dict DEPENDS lcioDict ) - - INSTALL_SHARED_LIBRARY( lcioDict DESTINATION ${CMAKE_INSTALL_LIBDIR} ) + INSTALL( TARGETS lcioDict + EXPORT LCIOTargets + DESTINATION ${CMAKE_INSTALL_LIBDIR}) #fg: for root6 we also need to install the pcm files ... SET( ROOT_DICT_PCM_FILES From 09b26541f90bfdb74921f1a2037e9d4d5abe1395 Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Mon, 7 Jun 2021 13:05:50 +0200 Subject: [PATCH 6/6] Only build tests if asked for it --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cea52c3b6..00bea8e16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -289,7 +289,9 @@ ENDIF() # directory containing lcio tests -ADD_SUBDIRECTORY( ./tests ) +IF( BUILD_TESTING ) + ADD_SUBDIRECTORY( ./tests ) +ENDIF() ### DOCUMENTATION ###########################################################