Skip to content

Commit

Permalink
Export targets and make sure they can be used by other projects (#177)
Browse files Browse the repository at this point in the history
Co-authored-by: jmcarcell <[email protected]>
Co-authored-by: Andre Sailer <[email protected]>
  • Loading branch information
3 people authored Nov 14, 2023
1 parent 93aff55 commit 65a9367
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,17 @@ 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}/"
)

IF( NOT SIO_FOUND )
install(EXPORT SIOTargets
NAMESPACE SIO::
FILE "SIOTargets.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SIO/"
)
ENDIF()
11 changes: 11 additions & 0 deletions cmake/LCIOConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ CHECK_PACKAGE_LIBS( LCIO lcio @CHECK_PACKAGE_SIO_LIBRARY@ )
## ---------------------------------------------------------------


include(CMakeFindDependencyMacro)
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
# to or execute
include("${CMAKE_CURRENT_LIST_DIR}/LCIOTargets.cmake")


# ---------- final checking ---------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions cmake/MacroGeneratePackageConfigFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions sio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ TARGET_INCLUDE_DIRECTORIES( sio PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
TARGET_INCLUDE_DIRECTORIES( sio SYSTEM PUBLIC ${ZLIB_INCLUDE_DIR} )
TARGET_LINK_LIBRARIES( sio ${ZLIB_LIBRARIES} )
INSTALL_SHARED_LIBRARY( sio DESTINATION ${CMAKE_INSTALL_LIBDIR} )
TARGET_LINK_LIBRARIES( sio PUBLIC ZLIB::ZLIB )
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
# for cases where others want to link against LCIO / this version of SIO
Expand Down
5 changes: 3 additions & 2 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,13 @@ 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} )
TARGET_LINK_LIBRARIES( lcio PRIVATE SIO::sio )

ADD_CUSTOM_TARGET( lib DEPENDS lcio )
ADD_LIBRARY( LCIO::lcio ALIAS lcio )
# ----------------------------------------------------------------------------


Expand Down

0 comments on commit 65a9367

Please sign in to comment.