From a723c55e0ddd2370b110d68e3d36e38fccd9e970 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 18 Sep 2023 10:20:19 +0200 Subject: [PATCH 1/6] Export targets and make sure they can be used by other projects --- CMakeLists.txt | 6 ++++++ cmake/LCIOConfig.cmake.in | 6 ++++++ cmake/MacroGeneratePackageConfigFiles.cmake | 4 ++-- cmake/MacroInstallSharedLibrary.cmake | 1 + sio/CMakeLists.txt | 1 + src/cpp/CMakeLists.txt | 1 + 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27c344eef..01a7e0c03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -313,3 +313,9 @@ MESSAGE( STATUS "" ) GENERATE_PACKAGE_CONFIGURATION_FILES( LCIOConfig.cmake LCIOConfigVersion.cmake ) INSTALL( FILES cmake/MacroCheckPackageLibs.cmake cmake/MacroCheckPackageVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake) + +install(EXPORT ${PROJECT_NAME}Targets + NAMESPACE ${PROJECT_NAME}:: + FILE "${PROJECT_NAME}Targets.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/" + ) diff --git a/cmake/LCIOConfig.cmake.in b/cmake/LCIOConfig.cmake.in index ee589b236..cd83ea53f 100644 --- a/cmake/LCIOConfig.cmake.in +++ b/cmake/LCIOConfig.cmake.in @@ -67,6 +67,12 @@ CHECK_PACKAGE_LIBS( LCIO lcio @CHECK_PACKAGE_SIO_LIBRARY@ ) ## --------------------------------------------------------------- +include(CMakeFindDependencyMacro) +find_dependency(SIO) + +# Include the targets file to create the imported targets that a client can link +# to or execute +include("${CMAKE_CURRENT_LIST_DIR}/LCIOTargets.cmake") # ---------- final checking --------------------------------------------------- diff --git a/cmake/MacroGeneratePackageConfigFiles.cmake b/cmake/MacroGeneratePackageConfigFiles.cmake index e4a7b1259..683829eee 100644 --- a/cmake/MacroGeneratePackageConfigFiles.cmake +++ b/cmake/MacroGeneratePackageConfigFiles.cmake @@ -9,7 +9,7 @@ MACRO( GENERATE_PACKAGE_CONFIGURATION_FILES ) CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/cmake/${arg}.in" "${PROJECT_BINARY_DIR}/${arg}" @ONLY ) - INSTALL( FILES "${PROJECT_BINARY_DIR}/${arg}" DESTINATION . ) + INSTALL( FILES "${PROJECT_BINARY_DIR}/${arg}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) #IF( EXISTS "${_current_dir}/MacroCheckPackageLibs.cmake" ) # INSTALL( FILES "${_current_dir}/MacroCheckPackageLibs.cmake" DESTINATION cmake ) #ENDIF() @@ -26,7 +26,7 @@ MACRO( GENERATE_PACKAGE_CONFIGURATION_FILES ) CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/cmake/${arg}.in" "${PROJECT_BINARY_DIR}/${arg}" @ONLY ) - INSTALL( FILES "${PROJECT_BINARY_DIR}/${arg}" DESTINATION . ) + INSTALL( FILES "${PROJECT_BINARY_DIR}/${arg}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) #IF( EXISTS "${_current_dir}/MacroCheckPackageVersion.cmake" ) # INSTALL( FILES "${_current_dir}/MacroCheckPackageVersion.cmake" DESTINATION cmake ) #ENDIF() diff --git a/cmake/MacroInstallSharedLibrary.cmake b/cmake/MacroInstallSharedLibrary.cmake index 37c0995b6..4e54d1aa3 100644 --- a/cmake/MacroInstallSharedLibrary.cmake +++ b/cmake/MacroInstallSharedLibrary.cmake @@ -4,6 +4,7 @@ MACRO( INSTALL_SHARED_LIBRARY ) # install library INSTALL( TARGETS ${ARGN} + EXPORT LCIOTargets PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE diff --git a/sio/CMakeLists.txt b/sio/CMakeLists.txt index 707dbb1dd..5158a5201 100644 --- a/sio/CMakeLists.txt +++ b/sio/CMakeLists.txt @@ -38,6 +38,7 @@ TARGET_INCLUDE_DIRECTORIES( sio PUBLIC TARGET_INCLUDE_DIRECTORIES( sio SYSTEM PUBLIC ${ZLIB_INCLUDE_DIR} ) TARGET_LINK_LIBRARIES( sio ${ZLIB_LIBRARIES} ) INSTALL_SHARED_LIBRARY( sio DESTINATION ${CMAKE_INSTALL_LIBDIR} ) +ADD_LIBRARY( SIO::sio ALIAS sio ) # Install the sio headers as well. Necessary for the python bindings and also # for cases where others want to link against LCIO / this version of SIO diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index 035ba2385..730b6bfcb 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -263,6 +263,7 @@ TARGET_LINK_LIBRARIES( lcio ${CMAKE_THREAD_LIBS_INIT} ) TARGET_LINK_LIBRARIES( lcio ${SIO_LIBRARIES} ) ADD_CUSTOM_TARGET( lib DEPENDS lcio ) +ADD_LIBRARY( LCIO::lcio ALIAS lcio ) # ---------------------------------------------------------------------------- From 1e419ae239e52e3e7ae5aca6eb78007a8dbf18cc Mon Sep 17 00:00:00 2001 From: Juan Miguel Carceller <22276694+jmcarcell@users.noreply.github.com> Date: Mon, 25 Sep 2023 08:43:19 +0200 Subject: [PATCH 2/6] Apply suggestions from code review Co-authored-by: Andre Sailer --- sio/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sio/CMakeLists.txt b/sio/CMakeLists.txt index 5158a5201..4afb279af 100644 --- a/sio/CMakeLists.txt +++ b/sio/CMakeLists.txt @@ -35,8 +35,7 @@ TARGET_INCLUDE_DIRECTORIES( sio PUBLIC $ $ ) -TARGET_INCLUDE_DIRECTORIES( sio SYSTEM PUBLIC ${ZLIB_INCLUDE_DIR} ) -TARGET_LINK_LIBRARIES( sio ${ZLIB_LIBRARIES} ) +TARGET_LINK_LIBRARIES( sio PUBLIC ZLIB::ZLIB ) INSTALL_SHARED_LIBRARY( sio DESTINATION ${CMAKE_INSTALL_LIBDIR} ) ADD_LIBRARY( SIO::sio ALIAS sio ) From 76ba73610d6c5830d50424e51919ef9a3dbd130a Mon Sep 17 00:00:00 2001 From: Juan Miguel Carceller <22276694+jmcarcell@users.noreply.github.com> Date: Mon, 25 Sep 2023 08:58:25 +0200 Subject: [PATCH 3/6] Update cmake/LCIOConfig.cmake.in Co-authored-by: Andre Sailer --- cmake/LCIOConfig.cmake.in | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/LCIOConfig.cmake.in b/cmake/LCIOConfig.cmake.in index cd83ea53f..e543e2161 100644 --- a/cmake/LCIOConfig.cmake.in +++ b/cmake/LCIOConfig.cmake.in @@ -68,7 +68,11 @@ CHECK_PACKAGE_LIBS( LCIO lcio @CHECK_PACKAGE_SIO_LIBRARY@ ) include(CMakeFindDependencyMacro) -find_dependency(SIO) +if("@CHECK_PACKAGE_SIO_LIBRARY@" STREQUAL "") + find_dependency(SIO REQUIRED) +else() + find_dependency(ZLIB REQUIRED) +endif() # Include the targets file to create the imported targets that a client can link # to or execute From 9a51be8e8a94f7a51c5c525f4cc34311edda1495 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sun, 1 Oct 2023 22:14:50 +0200 Subject: [PATCH 4/6] Don't modify INSTALL_SHARED_LIBRARY and add a SIOTargets file --- CMakeLists.txt | 8 ++++++++ cmake/MacroInstallSharedLibrary.cmake | 1 - sio/CMakeLists.txt | 2 +- src/cpp/CMakeLists.txt | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 01a7e0c03..6e344e8be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -319,3 +319,11 @@ install(EXPORT ${PROJECT_NAME}Targets FILE "${PROJECT_NAME}Targets.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/" ) + +IF( NOT SIO_FOUND ) +install(EXPORT SIOTargets + NAMESPACE SIO:: + FILE "SIOTargets.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SIO/" + ) +ENDIF() diff --git a/cmake/MacroInstallSharedLibrary.cmake b/cmake/MacroInstallSharedLibrary.cmake index 4e54d1aa3..37c0995b6 100644 --- a/cmake/MacroInstallSharedLibrary.cmake +++ b/cmake/MacroInstallSharedLibrary.cmake @@ -4,7 +4,6 @@ MACRO( INSTALL_SHARED_LIBRARY ) # install library INSTALL( TARGETS ${ARGN} - EXPORT LCIOTargets PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE diff --git a/sio/CMakeLists.txt b/sio/CMakeLists.txt index 4afb279af..85d48e1ac 100644 --- a/sio/CMakeLists.txt +++ b/sio/CMakeLists.txt @@ -36,7 +36,7 @@ TARGET_INCLUDE_DIRECTORIES( sio PUBLIC $ ) TARGET_LINK_LIBRARIES( sio PUBLIC ZLIB::ZLIB ) -INSTALL_SHARED_LIBRARY( sio DESTINATION ${CMAKE_INSTALL_LIBDIR} ) +INSTALL_SHARED_LIBRARY( sio DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT SIOTargets ) ADD_LIBRARY( SIO::sio ALIAS sio ) # Install the sio headers as well. Necessary for the python bindings and also diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index 730b6bfcb..957aea54f 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -257,7 +257,7 @@ ADD_SHARED_LIBRARY( lcio ${LCIO_SIO_SRCS} ${LCIO_MT_SRCS} ) -INSTALL_SHARED_LIBRARY( lcio DESTINATION ${CMAKE_INSTALL_LIBDIR} ) +INSTALL_SHARED_LIBRARY( lcio DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT LCIOTargets ) TARGET_LINK_LIBRARIES( lcio ${CMAKE_THREAD_LIBS_INIT} ) TARGET_LINK_LIBRARIES( lcio ${SIO_LIBRARIES} ) From e9fc9713ae04a617cd8a07d9a8bd9c3b673f46a7 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 13 Nov 2023 14:35:53 +0100 Subject: [PATCH 5/6] Change SIO_LIBRARIES to SIO::sio --- src/cpp/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index 957aea54f..811460d63 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -260,7 +260,7 @@ ADD_SHARED_LIBRARY( lcio INSTALL_SHARED_LIBRARY( lcio DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT LCIOTargets ) TARGET_LINK_LIBRARIES( lcio ${CMAKE_THREAD_LIBS_INIT} ) -TARGET_LINK_LIBRARIES( lcio ${SIO_LIBRARIES} ) +TARGET_LINK_LIBRARIES( lcio PRIVATE SIO::sio ) ADD_CUSTOM_TARGET( lib DEPENDS lcio ) ADD_LIBRARY( LCIO::lcio ALIAS lcio ) From ff903487c0223260a35dadb10bfe5b10cc6f66e9 Mon Sep 17 00:00:00 2001 From: Juan Miguel Carceller <22276694+jmcarcell@users.noreply.github.com> Date: Mon, 13 Nov 2023 15:31:14 +0100 Subject: [PATCH 6/6] Include SIOTargets in LCIOConfig.cmake Co-authored-by: Andre Sailer --- cmake/LCIOConfig.cmake.in | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/LCIOConfig.cmake.in b/cmake/LCIOConfig.cmake.in index e543e2161..e1b545636 100644 --- a/cmake/LCIOConfig.cmake.in +++ b/cmake/LCIOConfig.cmake.in @@ -72,6 +72,7 @@ if("@CHECK_PACKAGE_SIO_LIBRARY@" STREQUAL "") find_dependency(SIO REQUIRED) else() find_dependency(ZLIB REQUIRED) + include("${CMAKE_CURRENT_LIST_DIR}/SIOTargets.cmake") endif() # Include the targets file to create the imported targets that a client can link