Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
oaknut: add configuration for standalone installation
Browse files Browse the repository at this point in the history
  • Loading branch information
Castor216 authored and merryhime committed Jan 20, 2024
1 parent 69799b4 commit 9f131cf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
30 changes: 26 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(oaknut LANGUAGES CXX VERSION 1.2.2)
# or if this is the master project.
set(MASTER_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(MASTER_PROJECT ON)
set(MASTER_PROJECT ON)
endif()

# Disable in-source builds
Expand Down Expand Up @@ -41,11 +41,16 @@ set(header_files
${CMAKE_CURRENT_SOURCE_DIR}/include/oaknut/oaknut_exception.hpp
)

include(GNUInstallDirs)

# Library definition
add_library(oaknut INTERFACE)
add_library(merry::oaknut ALIAS oaknut)
target_sources(oaknut INTERFACE "$<BUILD_INTERFACE:${header_files}>")
target_include_directories(oaknut INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
target_include_directories(oaknut INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_LIBDIR}>
)
target_compile_features(oaknut INTERFACE cxx_std_20)

# Tests
Expand Down Expand Up @@ -97,11 +102,28 @@ if (MASTER_PROJECT)
endif()
endif()

# Export
include(GNUInstallDirs)
# Install
include(CMakePackageConfigHelpers)

install(TARGETS oaknut EXPORT oaknutTargets)
install(EXPORT oaknutTargets
NAMESPACE merry::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/oaknut"
)

configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/oaknutConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/oaknutConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/oaknut"
)
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/oaknutConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/oaknutConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/oaknutConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/oaknut"
)
install(DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}/include/oaknut"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
5 changes: 5 additions & 0 deletions oaknutConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")

check_required_components(@PROJECT_NAME@)

0 comments on commit 9f131cf

Please sign in to comment.