diff --git a/CMakeLists.txt b/CMakeLists.txt index 74db49e7..ab8f92d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,3 +94,47 @@ endif() ########### # Install # ########### + +# Install header files +install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/loki" + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +# Install cmake scripts +install( + DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/loki/cmake" +) + + + +########### +# Exports # +########### + +# https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html + +include(CMakePackageConfigHelpers) + +# Generate the version file for the config file +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/lokiConfigVersion.cmake" + VERSION "${loki_VERSION_MAJOR}.${loki_VERSION_MINOR}" + COMPATIBILITY ExactVersion +) + +# Create config file +# https://cmake.org/cmake/help/book/mastering-cmake/cmake/Help/guide/importing-exporting/index.html +# https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html#generating-a-package-configuration-file +configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/lokiConfig.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/loki" + NO_CHECK_REQUIRED_COMPONENTS_MACRO +) + +# Install config files +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/lokiConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/lokiConfigVersion.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/loki" +) diff --git a/Config.cmake.in b/Config.cmake.in new file mode 100644 index 00000000..e90399b1 --- /dev/null +++ b/Config.cmake.in @@ -0,0 +1,27 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/cmake/configure_boost.cmake") + +############## +# Dependencies +############## + +include(CMakeFindDependencyMacro) + +configure_boost() +find_dependency(Boost ${BOOST_MIN_VERSION} REQUIRED) + + +############ +# Components +############ + +set(_loki_supported_components parsers) + +foreach(_comp ${loki_FIND_COMPONENTS}) + if (NOT _comp IN_LIST _loki_supported_components) + set(loki_FOUND False) + set(loki_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}") + endif() + include("${CMAKE_CURRENT_LIST_DIR}/loki${_comp}Targets.cmake") +endforeach() \ No newline at end of file diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index c95c417c..1629ba6a 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -8,6 +8,7 @@ FetchContent_Declare( # Make Google Benchmark available set(BENCHMARK_DOWNLOAD_DEPENDENCIES ON) +set(BENCHMARK_ENABLE_INSTALL OFF) FetchContent_MakeAvailable(googlebenchmark) # Now declare your executable diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 62a80491..dc197e66 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,3 +16,34 @@ add_library(parsers STATIC ${SRC_FILES}) # Create an alias for simpler reference add_library(loki::parsers ALIAS parsers) + +# Use include depending on building or using from installed location +target_include_directories(parsers + INTERFACE + "$" + "$" +) + +# Install the target and create export-set +install( + TARGETS parsers + EXPORT parsersTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) + +# Generate and install export file +install(EXPORT parsersTargets + NAMESPACE loki:: + COMPONENT parsers + FILE parsersTargets.cmake + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/loki" +) + +# Generate build tree export file +export(EXPORT parsersTargets + FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/parsersTargets.cmake" + NAMESPACE dlplan:: +)