Skip to content

Commit c07e8c4

Browse files
committed
[CMake] Add support for building shared library and restrict absolute include path to build interface
1 parent 45d12f1 commit c07e8c4

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

CMakeLists.txt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,26 @@ file( GLOB BOOST_REGEX_SRC ./src/*.cpp )
1616
add_library( boost_regex ${BOOST_REGEX_SRC} )
1717
add_library( Boost::regex ALIAS boost_regex )
1818

19-
target_include_directories( boost_regex PUBLIC include )
20-
target_compile_definitions( boost_regex PUBLIC BOOST_REGEX_NO_LIB)
19+
# Currently, installation isn't supported directly,
20+
# but someone else might install this target from the parent
21+
# CMake script, so lets proactively differentiate between
22+
# the include directory during regular use (BUILD_INTERFACE)
23+
# and after installation
24+
target_include_directories( boost_regex
25+
PUBLIC
26+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
27+
$<INSTALL_INTERFACE:include>
28+
)
29+
30+
target_compile_definitions( boost_regex
31+
PUBLIC
32+
# No need for autolink and we don't mangle library name anyway
33+
BOOST_REGEX_NO_LIB
34+
$<$<STREQUAL:$<TARGET_PROPERTY:boost_regex,TYPE>,SHARED_LIBRARY>:BOOST_REGEX_DYN_LINK=1>
35+
$<$<STREQUAL:$<TARGET_PROPERTY:boost_regex,TYPE>,STATIC_LIBRARY>:BOOST_REGEX_STATIC_LINK=1>
36+
)
2137

38+
# Specify dependencies (including header-only libraries)
2239
target_link_libraries( boost_regex
2340
PUBLIC
2441
Boost::assert

0 commit comments

Comments
 (0)