Skip to content

Commit

Permalink
build: use GNUInstallDirs and improve packaging (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks authored Mar 19, 2023
1 parent 263ca0c commit 12f2c19
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
67 changes: 33 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)

project(IRT
VERSION 1.0.4
VERSION 1.0.5
LANGUAGES CXX
)

Expand All @@ -23,6 +23,7 @@ include(${ROOT_USE_FILE})
#----------------------------------------------------------------------------
# flags

include(GNUInstallDirs) # standard GNU installation
include(CheckCXXCompilerFlag)

set(CMAKE_CXX_FLAGS "-std=c++0x")
Expand All @@ -42,17 +43,11 @@ endif()
#----------------------------------------------------------------------------
# IRT library

set(IRT_LIB IRT)

include_directories(
include_directories(
${PROJECT_SOURCE_DIR}/include
${ROOT_INCLUDE_DIRS}

# For now assume that newly installed edm4eic::(CherenkovPID, ...) event structures are available
# in the same place where IRT is supposed to be installed;
${CMAKE_INSTALL_PREFIX}/include
)
file(GLOB HEADERS ${PROJECT_SOURCE_DIR}/include/*.h )
file(GLOB HEADERS ${PROJECT_SOURCE_DIR}/include/*.h)

set(IRT_SRC
${PROJECT_SOURCE_DIR}/source/SphericalSurface.cc
Expand All @@ -62,13 +57,16 @@ set(IRT_SRC
G__IRT.cxx
)

set(IRT_ROOTMAP ${CMAKE_CURRENT_BINARY_DIR}/lib${IRT_LIB}_rdict.pcm ${CMAKE_CURRENT_BINARY_DIR}/lib${IRT_LIB}.rootmap )
set(IRT_ROOTMAP
${CMAKE_CURRENT_BINARY_DIR}/lib${CMAKE_PROJECT_NAME}_rdict.pcm
${CMAKE_CURRENT_BINARY_DIR}/lib${CMAKE_PROJECT_NAME}.rootmap
)
root_generate_dictionary(G__IRT ${HEADERS} LINKDEF irtLinkDef.h)

add_library(${IRT_LIB} SHARED ${IRT_SRC} )
target_link_libraries(${IRT_LIB} ROOT::Core)
target_compile_options(${IRT_LIB} PRIVATE -Wall -Wno-misleading-indentation)
target_include_directories(${IRT_LIB} PUBLIC
add_library(${CMAKE_PROJECT_NAME} SHARED ${IRT_SRC} )
target_link_libraries(${CMAKE_PROJECT_NAME} ROOT::Core ROOT::Physics)
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -Wall -Wno-misleading-indentation)
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
)
Expand All @@ -89,47 +87,48 @@ endif()

install(FILES
${HEADERS}
DESTINATION include/IRT
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME}
)
install(TARGETS ${IRT_LIB}
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include/IRT
install(TARGETS ${CMAKE_PROJECT_NAME}
EXPORT ${CMAKE_PROJECT_NAME}Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME}
)
install(FILES
${IRT_ROOTMAP}
DESTINATION lib
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

#----------------------------------------------------------------------------
# package config

include(CMakePackageConfigHelpers)
install(EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION lib/IRT

install(EXPORT ${CMAKE_PROJECT_NAME}Targets
FILE ${CMAKE_PROJECT_NAME}Targets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}
)

set(TARGETS_INSTALL_PATH lib/IRT/IRTTargets.cmake)
set(TARGETS_INSTALL_PATH ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}/${CMAKE_PROJECT_NAME}Targets.cmake)

configure_package_config_file(
cmake/IRTConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/IRTConfig.cmake
INSTALL_DESTINATION lib/IRT
PATH_VARS TARGETS_INSTALL_PATH
cmake/${CMAKE_PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}
PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR TARGETS_INSTALL_PATH
)

write_basic_package_version_file(
"IRTConfigVersion.cmake"
"${CMAKE_PROJECT_NAME}ConfigVersion.cmake"
VERSION ${VERSION}
COMPATIBILITY SameMajorVersion
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/IRTConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/IRTConfigVersion.cmake
DESTINATION lib/IRT
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}
)

2 changes: 2 additions & 0 deletions cmake/IRTConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@PACKAGE_INIT@
include("@PACKAGE_TARGETS_INSTALL_PATH@")
set_and_check(IRT_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
set_and_check(IRT_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@")
check_required_components(IRT)
4 changes: 2 additions & 2 deletions delphes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ TARGET_LINK_LIBRARIES(${DELPHES_LIB} ${ROOT_LIBRARIES} EG )

#----------------------------------------------------------------------------

INSTALL(FILES ${DELPHES_ROOTMAP} DESTINATION lib)
install(TARGETS ${DELPHES_LIB} DESTINATION lib)
INSTALL(FILES ${DELPHES_ROOTMAP} DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS ${DELPHES_LIB} DESTINATION ${CMAKE_INSTALL_LIBDIR})

0 comments on commit 12f2c19

Please sign in to comment.