File tree Expand file tree Collapse file tree 10 files changed +85
-9
lines changed Expand file tree Collapse file tree 10 files changed +85
-9
lines changed Original file line number Diff line number Diff line change 11# yamllint disable-line rule:line-length
22# yaml-language-server: $schema=https://raw.githubusercontent.com/BlankSpruce/gersemi/master/gersemi/configuration.schema.json
33
4+ definitions: ["CMake/ystdlib-cpp-helpers.cmake"]
45line_length: 100
56list_expansion: "favour-expansion"
Original file line number Diff line number Diff line change 1+ # Adds a c++20 interface library in the subdirectory NAME with the target NAME and alias
2+ # NAMESPACE::NAME. Libraries with multiple levels of namespace nesting are currently not supported.
3+ #
4+ # @param NAME
5+ # @param NAMESPACE
6+ # @param [LIB_BUILD_INTERFACE="${PROJECT_SOURCE_DIR}/src"] The list of include paths for building
7+ # the library and for external projects that link against it via the add_subdirectory() function.
8+ function (cpp_library)
9+ set (options "" )
10+ set (oneValueArgs
11+ NAME
12+ NAMESPACE
13+ )
14+ set (multiValueArgs LIB_BUILD_INTERFACE)
15+ cmake_parse_arguments (arg_cpp_lib "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
16+
17+ # TODO: Turn this into a function for handling other optional params that have default values.
18+ if ("LIB_BUILD_INTERFACE" IN_LIST arg_cpp_lib_KEYWORDS_MISSING_VALUES)
19+ message (
20+ FATAL_ERROR
21+ "Missing build interface list for ${arg_cpp_lib_NAMESPACE} ::${arg_cpp_lib_NAME} ."
22+ )
23+ elseif (NOT DEFINED arg_cpp_lib_LIB_BUILD_INTERFACE)
24+ set (arg_cpp_lib_LIB_BUILD_INTERFACE "${PROJECT_SOURCE_DIR} /src" )
25+ endif ()
26+
27+ add_library (${arg_cpp_lib_NAME} INTERFACE )
28+ target_include_directories (
29+ ${arg_cpp_lib_NAME}
30+ INTERFACE
31+ "$<BUILD_INTERFACE:${arg_cpp_lib_LIB_BUILD_INTERFACE} >"
32+ )
33+ target_compile_features (${arg_cpp_lib_NAME} INTERFACE cxx_std_20)
34+ add_library (${arg_cpp_lib_NAMESPACE} ::${arg_cpp_lib_NAME} ALIAS ${arg_cpp_lib_NAME} )
35+ endfunction ()
Original file line number Diff line number Diff line change @@ -11,6 +11,14 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS
1111 FORCE
1212)
1313
14+ # Import CMake helper functions
15+ list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} /CMake)
16+ include (ystdlib-cpp-helpers)
17+
18+ add_subdirectory (src/ystdlib)
19+
20+ # Test dummy project
1421add_executable (dummy)
15- target_sources (dummy PRIVATE src/ystdlib/hello.cpp)
22+ target_sources (dummy PRIVATE src/main.cpp)
23+ target_link_libraries (dummy PRIVATE ystdlib::testlib)
1624target_compile_features (dummy PRIVATE cxx_std_20)
Original file line number Diff line number Diff line change @@ -2,6 +2,18 @@ ystdlib-cpp
22===================================
33An open-source C++ library developed and used at YScope.
44
5+ # Usage
6+ Clone ` ystdlib-cpp ` into your project. Then, in your project's ` CMakeLists.txt ` , add the following:
7+ ``` cmake
8+ add_subdirectory(/path/to/ystdlib-cpp EXCLUDE_FROM_ALL)
9+ target_link_libraries(<target_name> <link_options>
10+ ystdlib::<lib_1> ystdlib::<lib_2> ... ystdlib::<lib_N>
11+ # other libs...
12+ )
13+ ```
14+ Ensure that ` ystdlib-cpp ` is either within a subdirectory of the folder containing ` CMakeLists.txt `
15+ or at the same level.
16+
517# Contributing
618Follow the steps below to develop and contribute to the project.
719
@@ -15,7 +27,7 @@ Initialize and update submodules:
1527git submodule update --init --recursive
1628```
1729
18- # Building
30+ ## Building
1931To build all targets in ` ystdlib-cpp ` :
2032``` shell
2133task build:target
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < ystdlib/testlib/hello.hpp>
3+
4+ [[nodiscard]] auto main () -> int {
5+ std::cout << ystdlib::testlib::hello () << ' \n ' ;
6+ return 0 ;
7+ }
Original file line number Diff line number Diff line change 1+ add_subdirectory (testlib)
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ cpp_library(NAME testlib NAMESPACE ystdlib)
Original file line number Diff line number Diff line change 1+ #ifndef YSTDLIB_TESTLIB_HELLO_HPP
2+ #define YSTDLIB_TESTLIB_HELLO_HPP
3+
4+ #include < string>
5+
6+ namespace ystdlib ::testlib {
7+ [[nodiscard]] inline auto hello () -> std::string {
8+ return " Hello, world!" ;
9+ }
10+ } // namespace ystdlib::testlib
11+
12+ #endif // YSTDLIB_TESTLIB_HELLO_HPP
Original file line number Diff line number Diff line change 55 desc : " Runs the CMake linters."
66 sources : &cmake_format_src_files
77 - " {{.G_LINT_VENV_CHECKSUM_FILE}}"
8+ - " {{.G_YSTDLIB_CPP_SRC_DIR}}/.gersemirc"
89 - " {{.ROOT_DIR}}/**/*.cmake"
910 - " {{.ROOT_DIR}}/**/*.cmake.in"
1011 - " {{.ROOT_DIR}}/**/CMakeLists.txt"
12+ - " {{.ROOT_DIR}}/.gersemirc"
1113 - " {{.TASKFILE}}"
1214 - exclude : " {{.ROOT_DIR}}/**/build/*"
15+ - exclude : " {{.ROOT_DIR}}/**/cmake_install.cmake"
16+ - exclude : " {{.ROOT_DIR}}/**/CMakeFiles/*"
1317 - exclude : " {{.ROOT_DIR}}/**/submodules/*"
1418 - exclude : " {{.ROOT_DIR}}/**/tools/*"
1519 deps :
4448 - |-
4549 . "{{.G_LINT_VENV_DIR}}/bin/activate"
4650 find . \
47- \( -path '**/build' -o -path '**/submodules' -o -path '**/tools' \) -prune -o \
51+ \( -path '**/build' -o -path '**/cmake_install.cmake' -o -path '**/CMakeFiles' \
52+ -o -path '**/submodules' -o -path '**/tools' \) -prune -o \
4853 \( -iname "CMakeLists.txt" -o -iname "*.cmake" -o -iname "*.cmake.in" \) \
4954 -print0 | \
5055 xargs -0 gersemi {{.FLAGS}}
You can’t perform that action at this time.
0 commit comments