Skip to content

Commit 3d2fecf

Browse files
committed
Introduce the build interface param for cpp_libraray()
1 parent ba2066f commit 3d2fecf

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

CMake/ystdlib-cpp-helpers.cmake

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1-
# Set up include paths for building the project and for external projects that incorporate this
2-
# project using the add_subdirectory() function.
3-
set(CPP_LIB_BUILD_INTERFACE "${PROJECT_SOURCE_DIR}/src")
4-
51
# Adds a c++20 interface library in the subdirectory NAME with the target NAME and alias
62
# NAMESPACE::NAME. Libraries with multiple levels of namespace nesting are currently not supported.
73
#
84
# @param NAME
95
# @param NAMESPACE
6+
# @param [LIB_BUILD_INTERFACE] The list of include paths for building the library and for external
7+
# projects that link against it via the add_subdirectory() function.
108
function(cpp_library)
119
set(options "")
1210
set(oneValueArgs
1311
NAME
1412
NAMESPACE
1513
)
16-
set(multiValueArgs "")
14+
set(multiValueArgs LIB_BUILD_INTERFACE)
1715
cmake_parse_arguments(arg_cpp_lib "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
1816

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+
1927
add_library(${arg_cpp_lib_NAME} INTERFACE)
2028
target_include_directories(
2129
${arg_cpp_lib_NAME}
2230
INTERFACE
23-
"$<BUILD_INTERFACE:${CPP_LIB_BUILD_INTERFACE}>"
31+
"$<BUILD_INTERFACE:${arg_cpp_lib_LIB_BUILD_INTERFACE}>"
2432
)
2533
target_compile_features(${arg_cpp_lib_NAME} INTERFACE cxx_std_20)
2634
add_library(${arg_cpp_lib_NAMESPACE}::${arg_cpp_lib_NAME} ALIAS ${arg_cpp_lib_NAME})

0 commit comments

Comments
 (0)