Skip to content

Commit 7133493

Browse files
committed
Large switch env variable to handle library installation selection.
1 parent 0e0651e commit 7133493

16 files changed

+444
-240
lines changed

.gersemirc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# yaml-language-server: $schema=https://raw.githubusercontent.com/BlankSpruce/gersemi/master/gersemi/configuration.schema.json
33

44
definitions:
5-
- "CMake/ystdlib-helpers.cmake"
5+
- "cmake/ystdlib-helpers.cmake"
66
- "build/deps/Catch2/Catch2-src/extras/Catch.cmake"
77
line_length: 100
88
list_expansion: "favour-expansion"

CMake/ystdlib-config.cmake.in

Lines changed: 0 additions & 17 deletions
This file was deleted.

CMake/ystdlib-helpers.cmake

Lines changed: 0 additions & 174 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.23)
22

33
project(ystdlib VERSION "0.0.1" LANGUAGES CXX)
44

5-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
5+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
66
include(ystdlib-helpers)
77
include(CMakePackageConfigHelpers)
88
include(GNUInstallDirs)
@@ -31,14 +31,27 @@ if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "${ystdlib_CMAKE_CXX_COMPILER_MI
3131
)
3232
endif()
3333

34-
# Enable exporting compile commands
3534
set(CMAKE_EXPORT_COMPILE_COMMANDS
3635
ON
3736
CACHE BOOL
3837
"Enable/Disable output of compile commands during generation."
3938
FORCE
4039
)
4140

41+
set(YSTDLIB_LIBRARIES
42+
"containers"
43+
"error_handling"
44+
"io_interface"
45+
"wrapped_facade_headers"
46+
CACHE STRING
47+
"Semi-colon separated list of libraries to be built."
48+
)
49+
50+
message(STATUS "Building the following libraries:")
51+
foreach(lib IN LISTS YSTDLIB_LIBRARIES)
52+
message(" - ${lib}")
53+
endforeach()
54+
4255
if(ystdlib_IS_TOP_LEVEL)
4356
# Include dependency settings if the project isn't being included as a subproject.
4457
# NOTE: We mark the file optional because if the user happens to have the dependencies
@@ -53,17 +66,6 @@ if(BUILD_TESTING AND ystdlib_BUILD_TESTING)
5366
set(ystdlib_ENABLE_TESTS ON)
5467
endif()
5568

56-
set(boost_find_package_args
57-
1.81.0
58-
REQUIRED
59-
COMPONENTS
60-
headers
61-
)
62-
find_package(Boost ${boost_find_package_args})
63-
if(Boost_FOUND)
64-
message(STATUS "Found Boost ${Boost_VERSION}.")
65-
endif()
66-
6769
if(ystdlib_ENABLE_TESTS)
6870
find_package(Catch2 3.8.0 REQUIRED)
6971
if(Catch2_FOUND)
@@ -73,7 +75,6 @@ if(ystdlib_ENABLE_TESTS)
7375
endif()
7476
include(Catch)
7577

76-
# Set up the unified unit test target
7778
set(UNIFIED_UNIT_TEST_TARGET "unit-test-all")
7879
add_executable(${UNIFIED_UNIT_TEST_TARGET})
7980
target_link_libraries(${UNIFIED_UNIT_TEST_TARGET} PRIVATE Catch2::Catch2WithMain)
@@ -88,13 +89,12 @@ if(ystdlib_ENABLE_TESTS)
8889
catch_discover_tests(${UNIFIED_UNIT_TEST_TARGET} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/testbin)
8990
endif()
9091

91-
add_subdirectory(src/ystdlib)
92-
9392
set(ystdlib_INSTALL_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/ystdlib)
94-
install(EXPORT ystdlib-targets NAMESPACE ystdlib:: DESTINATION ${ystdlib_INSTALL_CONFIG_DIR})
93+
94+
add_subdirectory(src/ystdlib)
9595

9696
configure_package_config_file(
97-
${CMAKE_CURRENT_LIST_DIR}/CMake/ystdlib-config.cmake.in
97+
${CMAKE_CURRENT_LIST_DIR}/cmake/ystdlib-config.cmake.in
9898
${CMAKE_CURRENT_BINARY_DIR}/ystdlib-config.cmake
9999
INSTALL_DESTINATION ${ystdlib_INSTALL_CONFIG_DIR}
100100
)

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ task deps:install-all
4545
```
4646

4747
## Building
48+
49+
### Task
50+
4851
To build all targets:
4952
```shell
5053
task build:all
@@ -60,6 +63,27 @@ To build an executable containing a single library's unit tests:
6063
task build:unit-test-<lib_name>
6164
```
6265

66+
### CMake
67+
68+
To build all libraries, run:
69+
70+
```shell
71+
cmake -S . -D ./build
72+
cmake --build ./build
73+
```
74+
75+
To build a subset of libraries set the variable `YSTDLIB_LIBRARIES` to a semi-colon(`;`) separated
76+
list of library names. The library names match their [directory name in src/](./src/ystdlib).
77+
For example:
78+
79+
```shell
80+
cmake -S . -B ./build -DYSTDLIB_LIBRARIES="containers;io_interface"
81+
cmake --build ./build
82+
```
83+
84+
It is not necessary to specify libraries your subset depends on. In the example, specifying
85+
`io_interface` automatically builds `wrapped_facade_headers`.
86+
6387
## Installing
6488

6589
After [building](#building), install with:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# gersemi: off
2+
if(NOT TARGET "ystdlib::containers")
3+
include("${CMAKE_CURRENT_LIST_DIR}/containers-target.cmake")
4+
endif()
5+
# gersemi: on
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# gersemi: off
2+
if(@Boost_FOUND@)
3+
find_dependency(Boost @boost_find_package_args@)
4+
endif()
5+
6+
if(NOT TARGET "ystdlib::error_handling")
7+
include("${CMAKE_CURRENT_LIST_DIR}/error_handling-target.cmake")
8+
endif()
9+
# gersemi: on
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# gersemi: off
2+
if(NOT TARGET "ystdlib::wrapped_facade_headers")
3+
include("${CMAKE_CURRENT_LIST_DIR}/wrapped_facade_headers-target.cmake")
4+
endif()
5+
6+
if(NOT TARGET "ystdlib::io_interface")
7+
include("${CMAKE_CURRENT_LIST_DIR}/io_interface-target.cmake")
8+
endif()
9+
# gersemi: on
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# gersemi: off
2+
if(NOT TARGET "ystdlib::wrapped_facade_headers")
3+
include("${CMAKE_CURRENT_LIST_DIR}/wrapped_facade_headers-target.cmake")
4+
endif()
5+
# gersemi: on

cmake/ystdlib-config.cmake.in

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 no component is specified we require all libraries.
8+
# We guard against repeatedly including targets to support multiple find_package calls.
9+
if(NOT ystdlib_FIND_COMPONENTS)
10+
set(_YSTDLIB_LIBRARIES "@YSTDLIB_LIBRARIES@")
11+
foreach(lib IN LISTS _YSTDLIB_LIBRARIES)
12+
if(NOT TARGET "ystdlib::${lib}")
13+
include("${CMAKE_CURRENT_LIST_DIR}/libs/${lib}-config.cmake")
14+
endif()
15+
endforeach()
16+
else()
17+
foreach(lib IN LISTS ystdlib_FIND_COMPONENTS)
18+
if(NOT TARGET "ystdlib::${lib}")
19+
if(${ystdlib_FIND_REQUIRED_${lib}})
20+
include("${CMAKE_CURRENT_LIST_DIR}/libs/${lib}-config.cmake")
21+
else()
22+
include("${CMAKE_CURRENT_LIST_DIR}/libs/${lib}-config.cmake" OPTIONAL)
23+
endif()
24+
endif()
25+
endforeach()
26+
endif()
27+
28+
check_required_components(ystdlib)
29+
# gersemi: on

0 commit comments

Comments
 (0)