Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gersemirc
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"
29 changes: 29 additions & 0 deletions CMake/ystdlib-cpp-helpers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
set(CPP_LIB_BUILD_INTERFACE ${YSTDLIB_CPP_BUILD_INCLUDE_DIRS})
Comment thread
Bill-hbrhbr marked this conversation as resolved.
Outdated
set(CPP_LIB_INSTALL_INTERFACE ${YSTDLIB_CPP_INSTALL_INCLUDE_DIRS})

# cpp_library()
#
# CMake function for adding C++ libraries with sources, dependencies, and build settings.
Comment thread
Bill-hbrhbr marked this conversation as resolved.
Outdated
#
# Parameters:
# NAME: name of the library target
# NAMESPACE: namespace of the library
Comment thread
Bill-hbrhbr marked this conversation as resolved.
Outdated
function(cpp_library)
Comment thread
davidlion marked this conversation as resolved.
set(options)
set(oneValueArgs
NAME
NAMESPACE
)
set(multiValueArgs)
cmake_parse_arguments(arg_cpp_lib "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
Comment thread
Bill-hbrhbr marked this conversation as resolved.
Outdated

add_library(${arg_cpp_lib_NAME} INTERFACE)
target_include_directories(
${arg_cpp_lib_NAME}
INTERFACE
"$<BUILD_INTERFACE:${CPP_LIB_BUILD_INTERFACE}>"
"$<INSTALL_INTERFACE:${CPP_LIB_INSTALL_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()
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS
FORCE
)

# Configure include paths for building ystdlib-cpp.
list(APPEND YSTDLIB_CPP_BUILD_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src)

# Configure include paths for projects using ystdlib-cpp.
list(APPEND YSTDLIB_CPP_INSTALL_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src)

# Import CMake helper functions
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/CMake)
include(ystdlib-cpp-helpers)

add_subdirectory(src/ystdlib)

# Test dummy project
add_executable(dummy)
target_sources(dummy PRIVATE src/ystdlib/hello.cpp)
target_link_libraries(dummy PRIVATE ystdlib::hello)
target_compile_features(dummy PRIVATE cxx_std_20)
1 change: 1 addition & 0 deletions src/ystdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(hello)
3 changes: 2 additions & 1 deletion src/ystdlib/hello.cpp
Comment thread
Bill-hbrhbr marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <iostream>
#include <ystdlib/hello/hello.hpp>

[[nodiscard]] auto main() -> int {
std::cout << "Hello, world!" << '\n';
std::cout << ystdlib::hello() << '\n';
return 0;
}
1 change: 1 addition & 0 deletions src/ystdlib/hello/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cpp_library(NAME hello NAMESPACE ystdlib)
12 changes: 12 additions & 0 deletions src/ystdlib/hello/hello.hpp
Comment thread
Bill-hbrhbr marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef YSTDLIB_ARRAY_HPP
#define YSTDLIB_ARRAY_HPP

#include <string>

namespace ystdlib {
[[nodiscard]] inline auto hello() -> std::string {
return "Hello, world!";
}
} // namespace ystdlib

#endif // YSTDLIB_ARRAY_HPP
7 changes: 6 additions & 1 deletion taskfiles/lint-cmake.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ tasks:
- "{{.ROOT_DIR}}/**/*.cmake.in"
- "{{.ROOT_DIR}}/**/CMakeLists.txt"
- "{{.TASKFILE}}"
- "{{.ROOT_DIR}}/.gersemirc"
- "{{.G_YSTDLIB_CPP_SRC_DIR}}/.gersemirc"
- exclude: "{{.ROOT_DIR}}/**/build/*"
- exclude: "{{.ROOT_DIR}}/**/cmake_install.cmake"
- exclude: "{{.ROOT_DIR}}/**/CMakeFiles/*"
Comment thread
Bill-hbrhbr marked this conversation as resolved.
- exclude: "{{.ROOT_DIR}}/**/submodules/*"
- exclude: "{{.ROOT_DIR}}/**/tools/*"
deps:
Expand Down Expand Up @@ -44,7 +48,8 @@ tasks:
- |-
. "{{.G_LINT_VENV_DIR}}/bin/activate"
find . \
\( -path '**/build' -o -path '**/submodules' -o -path '**/tools' \) -prune -o \
\( -path '**/build' -o -path '**/cmake_install.cmake' -o -path '**/CMakeFiles' \
-o -path '**/submodules' -o -path '**/tools' \) -prune -o \
\( -iname "CMakeLists.txt" -o -iname "*.cmake" -o -iname "*.cmake.in" \) \
-print0 | \
xargs -0 gersemi {{.FLAGS}}