1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-14 01:45:35 +00:00

proper cmake package config

This commit is contained in:
Antonin Portelli 2024-02-08 19:08:44 +01:00
parent 534013fd87
commit d786524508
3 changed files with 52 additions and 2 deletions

View File

@ -6,6 +6,7 @@ project(
LANGUAGES C CXX) LANGUAGES C CXX)
# includes # includes
include(CMakePackageConfigHelpers)
include(FetchContent) include(FetchContent)
include(FindPackageMessage) include(FindPackageMessage)
include(GNUInstallDirs) include(GNUInstallDirs)
@ -30,7 +31,7 @@ file(CREATE_LINK ${eigen3_SOURCE_DIR}/Eigen ${CMAKE_SOURCE_DIR}/lib/LatAnalyze/E
# dependencies # dependencies
find_package(GSL REQUIRED) find_package(GSL REQUIRED)
find_package(HDF5 REQUIRED COMPONENTS C CXX) find_package(HDF5 REQUIRED COMPONENTS C CXX)
find_package(Minuit2) find_package(Minuit2 QUIET)
if(Minuit2_FOUND) if(Minuit2_FOUND)
set(Minuit2_MSG "yes") set(Minuit2_MSG "yes")
find_package_message( find_package_message(
@ -40,7 +41,7 @@ else()
set(Minuit2_MSG "no") set(Minuit2_MSG "no")
message(STATUS "Minuit2 not found") message(STATUS "Minuit2 not found")
endif() endif()
find_package(NLopt) find_package(NLopt QUIET)
if(NLopt_FOUND) if(NLopt_FOUND)
set(NLopt_MSG "yes") set(NLopt_MSG "yes")
find_package_message( find_package_message(

View File

@ -53,8 +53,29 @@ set_target_properties(LatAnalyze PROPERTIES VERSION ${PROJECT_VERSION})
target_include_directories( target_include_directories(
LatAnalyze PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> LatAnalyze PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
# installation
install( install(
TARGETS LatAnalyze TARGETS LatAnalyze
EXPORT LatAnalyzeTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
FILE_SET public_headers FILE_SET public_headers
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(
EXPORT LatAnalyzeTargets
FILE LatAnalyzeTargets.cmake
NAMESPACE LatAnalyze::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/LatAnalyze)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/LatAnalyzeConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/LatAnalyze)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/LatAnalyzeConfigVersion.cmake"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY AnyNewerVersion)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/LatAnalyzeConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/LatAnalyzeConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/LatAnalyze)

28
lib/Config.cmake.in Normal file
View File

@ -0,0 +1,28 @@
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
find_dependency(GSL REQUIRED)
find_dependency(HDF5 REQUIRED COMPONENTS C CXX)
set(HAVE_Minuit2 @Minuit2_FOUND@)
set(HAVE_NLopt @NLopt_FOUND@)
if(HAVE_Minuit2)
find_dependency(Minuit2 REQUIRED)
list(APPEND _LatAnalyze_supported_components MINUIT2)
set(LatAnalyze_MINUIT2_FOUND True)
endif()
if(HAVE_NLopt)
find_dependency(NLopt REQUIRED)
list(APPEND _LatAnalyze_supported_components NLOPT)
set(LatAnalyze_NLOPT_FOUND True)
endif()
foreach(_comp ${LatAnalyze_FIND_COMPONENTS})
if (NOT ";${_LatAnalyze_supported_components};" MATCHES ";${_comp};")
set(LatAnalyze_FOUND False)
set(LatAnalyze_NOT_FOUND_MESSAGE "Unsupported LatAnalyze component: ${_comp}")
endif()
endforeach()
include("${CMAKE_CURRENT_LIST_DIR}/LatAnalyzeTargets.cmake")
check_required_components(LatAnalyze)