Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Build-related directories and files
.task
build

# CTest directories and files
Testing
7 changes: 4 additions & 3 deletions CMake/ystdlib-cpp-helpers.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# 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.
#
# If `BUILD_TESTING` is ON, build the unit tests specific to the current library, and link this
# library against the unified unit test target for the entire `ystdlib-cpp`.
# If `YSTDLIB_CPP_ENABLE_TESTS` is ON, builds the unit tests specific to the current library, and
# links this library against the unified unit test target for the entire `ystdlib-cpp` project.
#
# @param NAME
# @param NAMESPACE
Expand Down Expand Up @@ -41,7 +41,8 @@ function(cpp_library)
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})

if(BUILD_TESTING)
if(YSTDLIB_CPP_ENABLE_TESTS)
# Build library-specific unit test target
set(_UNIT_TEST_TARGET "unit-test-${arg_cpp_lib_NAME}")
add_executable(${_UNIT_TEST_TARGET})
target_sources(${_UNIT_TEST_TARGET} PRIVATE ${arg_cpp_lib_TESTS_SOURCES})
Expand Down
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS
FORCE
)

option(BUILD_TESTING "If ON, unit tests will be built." ON)
if(YSTDLIB_CPP_IS_TOP_LEVEL)
Comment thread
Bill-hbrhbr marked this conversation as resolved.
# If previously undefined, `BUILD_TESTING` will be set to ON.
include(CTest)
endif()

option(YSTDLIB_CPP_BUILD_TESTING "Build the testing tree for ystdlib-cpp." ON)
if(BUILD_TESTING AND YSTDLIB_CPP_BUILD_TESTING)
set(YSTDLIB_CPP_ENABLE_TESTS ON)
endif()

# Import CMake helper functions
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/CMake)
Comment thread
Bill-hbrhbr marked this conversation as resolved.

if(BUILD_TESTING)
if(YSTDLIB_CPP_ENABLE_TESTS)
find_package(Catch2 3.8.0 REQUIRED)
if(Catch2_FOUND)
message(STATUS "Found Catch2 ${Catch2_VERSION}.")
else()
message(FATAL_ERROR "Could not find libraries for Catch2.")
endif()
include(Catch)

# Set up the unified unit test target
set(UNIFIED_UNIT_TEST_TARGET "unit-test-all")
Expand All @@ -36,6 +45,7 @@ if(BUILD_TESTING)
RUNTIME_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/testbin
)
catch_discover_tests(${UNIFIED_UNIT_TEST_TARGET} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/testbin)
endif()

include(ystdlib-cpp-helpers)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Comment thread
Bill-hbrhbr marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ ystdlib-cpp
An open-source C++ library developed and used at YScope.

# Usage

## Via CMake's add_subdirectory()
Clone `ystdlib-cpp` into your project. Then, in your project's `CMakeLists.txt`, add the following:
```cmake
# Uncomment the next line if you do not want to build ystdlib-cpp's unit tests.
# option(YSTDLIB_CPP_BUILD_TESTING "" OFF)
add_subdirectory(/path/to/ystdlib-cpp EXCLUDE_FROM_ALL)
target_link_libraries(<target_name> <link_options>
ystdlib::<lib_1> ystdlib::<lib_2> ... ystdlib::<lib_N>
Expand Down