From d786524508a5c63b45345b4413cf6fb94973d9c2 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 8 Feb 2024 19:08:44 +0100 Subject: [PATCH] proper cmake package config --- CMakeLists.txt | 5 +++-- lib/CMakeLists.txt | 21 +++++++++++++++++++++ lib/Config.cmake.in | 28 ++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 lib/Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index f331c8e..4f9837f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ project( LANGUAGES C CXX) # includes +include(CMakePackageConfigHelpers) include(FetchContent) include(FindPackageMessage) include(GNUInstallDirs) @@ -30,7 +31,7 @@ file(CREATE_LINK ${eigen3_SOURCE_DIR}/Eigen ${CMAKE_SOURCE_DIR}/lib/LatAnalyze/E # dependencies find_package(GSL REQUIRED) find_package(HDF5 REQUIRED COMPONENTS C CXX) -find_package(Minuit2) +find_package(Minuit2 QUIET) if(Minuit2_FOUND) set(Minuit2_MSG "yes") find_package_message( @@ -40,7 +41,7 @@ else() set(Minuit2_MSG "no") message(STATUS "Minuit2 not found") endif() -find_package(NLopt) +find_package(NLopt QUIET) if(NLopt_FOUND) set(NLopt_MSG "yes") find_package_message( diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 6aeb140..2e58e19 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -53,8 +53,29 @@ set_target_properties(LatAnalyze PROPERTIES VERSION ${PROJECT_VERSION}) target_include_directories( LatAnalyze PUBLIC $ $) + +# installation install( TARGETS LatAnalyze + EXPORT LatAnalyzeTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} FILE_SET public_headers 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) diff --git a/lib/Config.cmake.in b/lib/Config.cmake.in new file mode 100644 index 0000000..67bd4e2 --- /dev/null +++ b/lib/Config.cmake.in @@ -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)