Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
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
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,24 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS
FORCE
)

option(BUILD_TESTING "If ON, unit tests will be built." ON)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(YSTDLIB_CPP_MASTER_PROJECT ON CACHE BOOL "ystdlib-cpp is the top-level CMake project.")
endif()

# Enable unit test building by default if `BUILD_TESING` is not already defined in the parent scope.
if(NOT DEFINED BUILD_TESTING)
set(BUILD_TESTING ON)
endif()

set(YSTDLIB_CPP_ENABLE_TESTS OFF)
if((YSTDLIB_CPP_MASTER_PROJECT OR YSTDLIB_CPP_BUILD_TESTING) AND 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}.")
Expand Down
1 change: 1 addition & 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 @@ -5,6 +5,7 @@ An open-source C++ library developed and used at YScope.
# Usage
Clone `ystdlib-cpp` into your project. Then, in your project's `CMakeLists.txt`, add the following:
```cmake
set(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