Skip to content

Commit

Permalink
proper cmake package config
Browse files Browse the repository at this point in the history
  • Loading branch information
aportelli committed Feb 8, 2024
1 parent 534013f commit d786524
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ project(
LANGUAGES C CXX)

# includes
include(CMakePackageConfigHelpers)
include(FetchContent)
include(FindPackageMessage)
include(GNUInstallDirs)
Expand All @@ -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(
Expand All @@ -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(
Expand Down
21 changes: 21 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,29 @@ set_target_properties(LatAnalyze PROPERTIES VERSION ${PROJECT_VERSION})
target_include_directories(
LatAnalyze PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

# 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)
28 changes: 28 additions & 0 deletions lib/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit d786524

Please sign in to comment.