Skip to content

Commit

Permalink
added cmake config
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Jan 4, 2024
1 parent a24006b commit 4b3b218
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
44 changes: 44 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
27 changes: 27 additions & 0 deletions Config.cmake.in
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

# 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::
)

0 comments on commit 4b3b218

Please sign in to comment.