Skip to content

Commit

Permalink
Add CMake package config
Browse files Browse the repository at this point in the history
  • Loading branch information
globberwops committed Apr 22, 2023
1 parent 3502ca1 commit edd76bc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
42 changes: 39 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,51 @@
cmake_minimum_required(VERSION 3.10)
project(recycle)

project(recycle
VERSION 6.0.0
DESCRIPTION "Simple resource pool for recycling resources in C++"
LANGUAGES CXX)

# Define library
add_library(recycle INTERFACE)
target_compile_features(recycle INTERFACE cxx_std_14)
target_include_directories(recycle INTERFACE src/)
target_include_directories(recycle INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src> $<INSTALL_INTERFACE:include>)
add_library(steinwurf::recycle ALIAS recycle)

include(GNUInstallDirs)
set(RECYCLE_CONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/recycle" CACHE PATH "recycle config directory")

# Install headers
install(
DIRECTORY ./src/recycle
DESTINATION ${CMAKE_INSTALL_PREFIX}/include
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING
PATTERN *.hpp)

# Install targets
install(TARGETS recycle EXPORT recycle-targets)
install(
EXPORT recycle-targets
DESTINATION ${RECYCLE_CONFIG_DIR}
NAMESPACE steinwurf::)

# Install package config
include(CMakePackageConfigHelpers)

configure_package_config_file(
cmake/recycle-config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/recycle-config.cmake"
INSTALL_DESTINATION ${RECYCLE_CONFIG_DIR}
NO_CHECK_REQUIRED_COMPONENTS_MACRO)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/recycle-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/recycle-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/recycle-config-version.cmake"
DESTINATION
${RECYCLE_CONFIG_DIR})
6 changes: 6 additions & 0 deletions cmake/recycle-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@PACKAGE_INIT@

if(NOT TARGET steinwurf::recycle)
set_and_check(RECYCLE_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@")
include("${CMAKE_CURRENT_LIST_DIR}/recycle-targets.cmake")
endif()

0 comments on commit edd76bc

Please sign in to comment.