Skip to content

Commit bda1ea0

Browse files
Apply suggestions from code review
Co-authored-by: kirkrodrigues <[email protected]>
1 parent e72fb28 commit bda1ea0

File tree

3 files changed

+60
-48
lines changed

3 files changed

+60
-48
lines changed

README.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,37 @@ An open-source C++ library developed and used at YScope.
44

55
# Usage
66

7-
## Via CMake's `find_package`
8-
97
First, [build](#building) and [install](#installing) `ystdlib` onto your system. Then, in your
108
project's `CMakeLists.txt`, add the following:
119

1210
```cmake
13-
# If `BUILD_TESTING` is set, set `ystdlib_BUILD_TESTING` to an accepted `FALSE` class value to skip
14-
# building ystdlib's unit tests.
15-
# option(ystdlib_BUILD_TESTING "" OFF)
16-
# If ystdlib is not installed to a path that is searched by default, set `ystdlib_ROOT` to manually
17-
# specify the location.
18-
# set(ystdlib_ROOT "<PATH_TO_INSTALLATION>")
1911
find_package(ystdlib REQUIRED)
20-
target_link_libraries(<target_name> <link_options>
21-
ystdlib::<lib_1> ystdlib::<lib_2> ... ystdlib::<lib_N>
22-
# other libs...
12+
target_link_libraries(<target_name>
13+
[<link-options>]
14+
ystdlib::<lib_1>
15+
[ystdlib::<lib_2> ... ystdlib::<lib_N>]
2316
)
2417
```
2518

19+
Where
20+
21+
* `<target_name>` is the name of your target.
22+
* `<link-options>` are the link options for your target.
23+
* `lib_1`, `lib_2`, ..., `lib_N` are the names of the ystdlib libraries you wish to link with your
24+
target.
25+
26+
> [!NOTE]
27+
> If `BUILD_TESTING` is set, set `ystdlib_BUILD_TESTING` to an accepted `FALSE` class value to skip
28+
> building ystdlib's unit tests.
29+
30+
> [!TIP]
31+
> If ystdlib is not installed to a path that is searched by default, set `ystdlib_ROOT` to manually
32+
> specify the location:
33+
>
34+
> ```cmake
35+
> set(ystdlib_ROOT "<PATH_TO_INSTALLATION>")
36+
> ```
37+
2638
# Contributing
2739
Follow the steps below to develop and contribute to the project.
2840
@@ -46,7 +58,10 @@ task deps:install-all
4658

4759
## Building
4860

49-
### Task
61+
The library can be built directly using [CMake](#using-cmake) or indirectly using
62+
[Task](#using-task).
63+
64+
### Using Task
5065

5166
To build all targets:
5267
```shell
@@ -63,7 +78,7 @@ To build an executable containing a single library's unit tests:
6378
task build:unit-test-<lib_name>
6479
```
6580

66-
### CMake
81+
### Using CMake
6782

6883
To build all libraries, run:
6984

@@ -72,17 +87,19 @@ cmake -S . -B ./build
7287
cmake --build ./build
7388
```
7489

75-
To build a subset of libraries, set the variable `ystdlib_LIBRARIES` to a semicolon(`;`) separated
76-
list of library names. The library names match their [directory name in src/](./src/ystdlib).
77-
For example:
90+
To build a subset of libraries, set the variable `ystdlib_LIBRARIES` to a semicolon-separated (`;`)
91+
list of library names. The library names match their [directory name in src/](./src/ystdlib). For
92+
example:
7893

7994
```shell
8095
cmake -S . -B ./build -Dystdlib_LIBRARIES="containers;io_interface"
8196
cmake --build ./build
8297
```
8398

84-
It is not necessary to specify libraries your subset depends on. In the example, specifying
85-
`io_interface` automatically builds `wrapped_facade_headers`.
99+
> [!NOTE]
100+
> Internal dependencies of the libraries you choose will be automatically built, even if you don't
101+
> explicitly specify them. In the example, specifying `io_interface` automatically builds
102+
> `wrapped_facade_headers`.
86103
87104
## Installing
88105

cmake/ystdlib-helpers.cmake

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
include(CMakePackageConfigHelpers)
22

3-
# Checks that each argument name is defined and non-empty. Requires a prior call to
4-
# `cmake_parse_arguments` with `ARG` as the prefix to access the values of the arguments in
5-
# `REQUIRED_ARG_NAMES`.
3+
# Checks that each argument name in `REQUIRED_ARG_NAMES` is defined and non-empty. Assumes the
4+
# arguments are stored in variables prefixed with `ARG_<NAME>`.
65
#
76
# @param {string[]} REQUIRED_ARG_NAMES
87
macro(require_argument_values REQUIRED_ARG_NAMES)
98
set(_REQUIRED_ARGS "${REQUIRED_ARG_NAMES}")
109
foreach(_REQUIRED_ARG IN LISTS _REQUIRED_ARGS)
1110
if(NOT DEFINED ARG_${_REQUIRED_ARG} OR ARG_${_REQUIRED_ARG} STREQUAL "")
12-
message(FATAL_ERROR "Non-empty value for argument: '${_REQUIRED_ARG}'")
11+
message(FATAL_ERROR "Empty value for argument: '${_REQUIRED_ARG}'")
1312
endif()
1413
endforeach()
1514
endmacro()
1615

17-
# @param {string[]} SOURCE_LIST The list of source files to check.
18-
# @param {bool} IS_HEADER_ONLY Returns TRUE if list only contains header files, FALSE otherwise.
16+
# Checks if `SOURCE_LIST` contains only header files.
17+
#
18+
# @param {string[]} SOURCE_LIST
19+
# @param {bool} IS_HEADER_ONLY Returns whether the list contains only header files.
1920
# @param {string} NON_HEADER_FILE Returns the name of the first, if any, non-header file.
2021
function(check_if_header_only SOURCE_LIST IS_HEADER_ONLY NON_HEADER_FILE)
2122
set(LOCAL_SOURCE_LIST "${${SOURCE_LIST}}")
2223
foreach(SRC_FILE IN LISTS LOCAL_SOURCE_LIST)
23-
if(NOT ${SRC_FILE} MATCHES ".*\\.(h|hpp)")
24+
if(NOT "${SRC_FILE}" MATCHES ".*\\.(h|hpp)")
2425
set(${IS_HEADER_ONLY} FALSE PARENT_SCOPE)
25-
set(${NON_HEADER_FILE} ${SRC_FILE} PARENT_SCOPE)
26+
set(${NON_HEADER_FILE} "${SRC_FILE}" PARENT_SCOPE)
2627
return()
2728
endif()
2829
endforeach()
@@ -113,15 +114,15 @@ function(add_cpp_library)
113114
)
114115
endfunction()
115116

116-
# Adds a C++ 20 test executable named unit-test-NAME that will be built with SOURCES and linked with
117-
# LINK_LIBRARIES, in addition to Catch2.
117+
# Adds a C++ 20 test executable named `unit-test-NAME` that will be built with `SOURCES` and linked
118+
# with `LINK_LIBRARIES`, in addition to Catch2.
118119
#
119120
# @param {string} NAME
120121
# @param {string} NAMESPACE
121122
# @param {string[]} SOURCES
122123
# @param {string[]} [LINK_LIBRARIES]
123-
# @param {string} [UNIFIED_TEST_TARGET] If set, SOURCES and LINK_LIBRARIES are also added to
124-
# UNIFIED_TEST_TARGET.
124+
# @param {string} [UNIFIED_TEST_TARGET] If set, `SOURCES` and `LINK_LIBRARIES` are also added to
125+
# `UNIFIED_TEST_TARGET`.
125126
function(add_catch2_tests)
126127
set(SINGLE_VALUE_ARGS
127128
NAME
@@ -177,11 +178,11 @@ endfunction()
177178
# @param {string} NAME
178179
# @param {string} NAMESPACE
179180
# @param {string} [CONFIG_DEST_DIR] Destination to install the generated config file
180-
# (NAME-config.cmake).
181-
# @param {string} [CONFIG_INPUT_DIR] configure_package_config_file input file
182-
# (NAME-config.cmake.in).
183-
# @param {string} [CONFIG_OUTPUT_DIR] configure_package_config_file output file
184-
# (NAME-config.cmake).
181+
# (`NAME-config.cmake`).
182+
# @param {string} [CONFIG_INPUT_DIR] `configure_package_config_file` input file
183+
# (`NAME-config.cmake.in`).
184+
# @param {string} [CONFIG_OUTPUT_DIR] `configure_package_config_file` output file
185+
# (`NAME-config.cmake`).
185186
function(install_library)
186187
set(SINGLE_VALUE_ARGS
187188
NAME

examples/README.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
11
# Examples
22

3+
This directory contains example programs that demonstrate how to use the ystdlib library.
4+
35
The example program `linking-tests` references all of ystdlib's library targets to ensure they can
46
be installed and linked correctly.
57

6-
## Building
7-
8-
First, ensure ystdlib has been installed. For example, after
9-
[building ystdlib](../README.md#building), [install it](../README.md#installing) by running:
8+
# Requirements
109

11-
```shell
12-
cmake --install "./build" --prefix "./build/examples/ystdlib"
13-
```
10+
[Build](../README.md#building) and [install](../README.md#installing) ystdlib. The commands below
11+
assume you've built and installed ystdlib to `./build/examples/ystdlib`. If you installed it to a
12+
different location, adjust the paths accordingly.
1413

15-
To build the examples, run:
14+
## Building
1615

1716
```shell
1817
cmake -S "./examples" -B "./build/examples" -Dystdlib_ROOT="./build/examples/ystdlib"
1918

2019
cmake --build "./build/examples"
2120
```
2221

23-
Setting `ystdlib_ROOT` is not necessary if `ystdlib` is installed on a path CMake searches by
24-
default.
25-
2622
## Running
2723

28-
Run the example program as follows:
29-
3024
```shell
3125
./build/examples/linking-tests
3226
```

0 commit comments

Comments
 (0)