-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Add CMakeLists.txt files and helper function for building interface libraries.
#17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5fdcea2
Add cmake command ystdlib_cpp_library and update cmake linting exclus…
Bill-hbrhbr e7df6bb
Add cmake formatting file at library level
Bill-hbrhbr 0100bfb
Reformat lint-cmake.yaml
Bill-hbrhbr c60837c
Add a dummy library
Bill-hbrhbr b3da5de
Use target link lib to show that ystdlib has actually been built
Bill-hbrhbr 7321bb7
Address offline review comments
Bill-hbrhbr 888189a
Trim
Bill-hbrhbr 16c2883
Fix build error
Bill-hbrhbr bff4345
Address review concerns
Bill-hbrhbr 56f2fa6
Change header guard name
Bill-hbrhbr 0ec0d75
Remove unused install interface
Bill-hbrhbr 83c8123
Fix lint sources alphabetical order
Bill-hbrhbr 0f6857d
Rebuild dummy project structure according to review
Bill-hbrhbr 951284a
Address review concern about lib namespaces
Bill-hbrhbr ba2066f
lint fix
Bill-hbrhbr 3d2fecf
Introduce the build interface param for cpp_libraray()
Bill-hbrhbr cdefa7d
Update usage doc
Bill-hbrhbr 77135c0
Apply suggestions from code review
Bill-hbrhbr ebed9f4
Resolve readme conflicts
Bill-hbrhbr 75d680a
Update README.md
Bill-hbrhbr f5e77f7
Update README.md
Bill-hbrhbr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| # yamllint disable-line rule:line-length | ||
| # yaml-language-server: $schema=https://raw.githubusercontent.com/BlankSpruce/gersemi/master/gersemi/configuration.schema.json | ||
|
|
||
| definitions: ["CMake/ystdlib-cpp-helpers.cmake"] | ||
| line_length: 100 | ||
| list_expansion: "favour-expansion" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Adds a c++20 interface library in the subdirectory NAME with the target NAME and alias | ||
| # NAMESPACE::NAME. Libraries with multiple levels of namespace nesting are currently not supported. | ||
| # | ||
| # @param NAME | ||
| # @param NAMESPACE | ||
| # @param [LIB_BUILD_INTERFACE="${PROJECT_SOURCE_DIR}/src"] The list of include paths for building | ||
| # the library and for external projects that link against it via the add_subdirectory() function. | ||
| function(cpp_library) | ||
| set(options "") | ||
| set(oneValueArgs | ||
| NAME | ||
| NAMESPACE | ||
| ) | ||
| set(multiValueArgs LIB_BUILD_INTERFACE) | ||
| cmake_parse_arguments(arg_cpp_lib "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
|
|
||
| # TODO: Turn this into a function for handling other optional params that have default values. | ||
| if("LIB_BUILD_INTERFACE" IN_LIST arg_cpp_lib_KEYWORDS_MISSING_VALUES) | ||
| message( | ||
| FATAL_ERROR | ||
| "Missing build interface list for ${arg_cpp_lib_NAMESPACE}::${arg_cpp_lib_NAME}." | ||
| ) | ||
| elseif(NOT DEFINED arg_cpp_lib_LIB_BUILD_INTERFACE) | ||
| set(arg_cpp_lib_LIB_BUILD_INTERFACE "${PROJECT_SOURCE_DIR}/src") | ||
| endif() | ||
|
|
||
| add_library(${arg_cpp_lib_NAME} INTERFACE) | ||
| target_include_directories( | ||
| ${arg_cpp_lib_NAME} | ||
| INTERFACE | ||
| "$<BUILD_INTERFACE:${arg_cpp_lib_LIB_BUILD_INTERFACE}>" | ||
| ) | ||
| target_compile_features(${arg_cpp_lib_NAME} INTERFACE cxx_std_20) | ||
| add_library(${arg_cpp_lib_NAMESPACE}::${arg_cpp_lib_NAME} ALIAS ${arg_cpp_lib_NAME}) | ||
| endfunction() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #include <iostream> | ||
| #include <ystdlib/testlib/hello.hpp> | ||
|
|
||
| [[nodiscard]] auto main() -> int { | ||
| std::cout << ystdlib::testlib::hello() << '\n'; | ||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| add_subdirectory(testlib) |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| cpp_library(NAME testlib NAMESPACE ystdlib) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #ifndef YSTDLIB_TESTLIB_HELLO_HPP | ||
| #define YSTDLIB_TESTLIB_HELLO_HPP | ||
|
|
||
| #include <string> | ||
|
|
||
| namespace ystdlib::testlib { | ||
| [[nodiscard]] inline auto hello() -> std::string { | ||
| return "Hello, world!"; | ||
| } | ||
| } // namespace ystdlib::testlib | ||
|
|
||
| #endif // YSTDLIB_TESTLIB_HELLO_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.