Skip to content

Commit 2f9f30b

Browse files
committed
Merge branch 'backup-main'
2 parents d80cf86 + 2e54cdb commit 2f9f30b

File tree

2 files changed

+95
-2
lines changed

2 files changed

+95
-2
lines changed

CMake/ystdlib-config.cmake.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# gersemi: off
2+
# this file is preprocessed and should not be linted like a CMake file
3+
include(CMakeFindDependencyMacro)
4+
5+
@PACKAGE_INIT@
6+
7+
if(@Catch2_FOUND@)
8+
find_dependency(Catch2)
9+
endif()
10+
11+
if(@outcome_FOUND@)
12+
find_dependency(outcome)
13+
endif()
14+
15+
set_and_check(ystdlib_INCLUDE_DIR "@PACKAGE_YSTDLIB_INSTALL_INCLUDE_DIR@")
16+
17+
check_required_components(ystdlib)
18+
19+
# Avoid repeatedly including the targets
20+
if(NOT TARGET ystdlib::ystdlib)
21+
include("${CMAKE_CURRENT_LIST_DIR}/ystdlib-targets.cmake")
22+
endif()
23+
# gersemi: on

CMakeLists.txt

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ cmake_minimum_required(VERSION 3.22.1)
22

33
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
44
include(ystdlib-cpp-helpers)
5-
6-
project(YSTDLIB_CPP LANGUAGES CXX)
5+
include(CMakePackageConfigHelpers)
6+
include(GNUInstallDirs)
77

88
set(YSTDLIB_CPP_VERSION "0.0.1" CACHE STRING "Project version.")
99

10+
project(YSTDLIB_CPP VERSION "${YSTDLIB_CPP_VERSION}" LANGUAGES CXX)
11+
1012
option(BUILD_SHARED_LIBS "Build using shared libraries." OFF)
1113
option(YSTDLIB_CPP_BUILD_TESTING "Build the testing tree for ystdlib-cpp." ON)
1214

@@ -82,4 +84,72 @@ if(YSTDLIB_CPP_ENABLE_TESTS)
8284
catch_discover_tests(${UNIFIED_UNIT_TEST_TARGET} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/testbin)
8385
endif()
8486

87+
set(YSTDLIB_INSTALL_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/ystdlib)
88+
set(YSTDLIB_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR})
89+
90+
file(
91+
GLOB_RECURSE SOURCE_FILES
92+
CONFIGURE_DEPENDS
93+
"${PROJECT_SOURCE_DIR}/src/*.cpp"
94+
"${PROJECT_SOURCE_DIR}/src/*.hpp"
95+
"${PROJECT_SOURCE_DIR}/src/*.h"
96+
)
97+
list(FILTER SOURCE_FILES EXCLUDE REGEX ".*test_*\..*")
98+
99+
add_library(ystdlib ${SOURCE_FILES})
100+
add_library(ystdlib::ystdlib ALIAS ystdlib)
101+
102+
target_include_directories(
103+
ystdlib
104+
PUBLIC
105+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
106+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
107+
)
108+
109+
target_compile_features(ystdlib PUBLIC cxx_std_20)
110+
111+
set_target_properties(
112+
ystdlib
113+
PROPERTIES
114+
LINKER_LANGUAGE
115+
CXX
116+
)
117+
118+
install(TARGETS ystdlib EXPORT ystdlib-targets)
119+
120+
install(EXPORT ystdlib-targets NAMESPACE ystdlib:: DESTINATION ${YSTDLIB_INSTALL_CONFIG_DIR})
121+
122+
install(
123+
DIRECTORY
124+
"${PROJECT_SOURCE_DIR}/src/ystdlib"
125+
DESTINATION "${YSTDLIB_INSTALL_INCLUDE_DIR}"
126+
FILES_MATCHING
127+
PATTERN
128+
"*.h"
129+
PATTERN
130+
"*.hpp"
131+
PATTERN
132+
"*.tpp"
133+
)
134+
135+
configure_package_config_file(
136+
${CMAKE_CURRENT_LIST_DIR}/CMake/ystdlib-config.cmake.in
137+
${CMAKE_CURRENT_BINARY_DIR}/ystdlib-config.cmake
138+
INSTALL_DESTINATION ${YSTDLIB_INSTALL_CONFIG_DIR}
139+
PATH_VARS
140+
YSTDLIB_INSTALL_INCLUDE_DIR
141+
)
142+
143+
write_basic_package_version_file(
144+
${CMAKE_CURRENT_BINARY_DIR}/ystdlib-config-version.cmake
145+
COMPATIBILITY SameMajorVersion
146+
)
147+
148+
install(
149+
FILES
150+
${CMAKE_CURRENT_BINARY_DIR}/ystdlib-config.cmake
151+
${CMAKE_CURRENT_BINARY_DIR}/ystdlib-config-version.cmake
152+
DESTINATION ${YSTDLIB_INSTALL_CONFIG_DIR}
153+
)
154+
85155
add_subdirectory(src/ystdlib)

0 commit comments

Comments
 (0)