Skip to content

Commit f63c602

Browse files
authored
Merge pull request boostorg#86 from Mike-Devel/min_cmake
[CMake] Add minimal cmake support
2 parents a550507 + 92f6a80 commit f63c602

File tree

3 files changed

+171
-1
lines changed

3 files changed

+171
-1
lines changed

.travis.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ matrix:
2727
- env: BOGUS_JOB=true
2828

2929
include:
30+
- os: linux
31+
env: TEST_CMAKE=true # variables unused - just for identification in travis ci gui
32+
script:
33+
- git submodule update --init tools/cmake
34+
- git submodule update --init libs/conversion
35+
- git submodule update --init libs/function_types
36+
- git submodule update --init libs/fusion
37+
- git submodule update --init libs/typeof
38+
- mkdir __build__ && cd __build__
39+
- cmake .. -DBOOST_ENABLE_CMAKE=ON -DBOOST_REGEX_INCLUDE_EXAMPLES=ON
40+
- cmake --build .
41+
42+
- os: linux
43+
env: TEST_CMAKE=true BUILD_SHARED_LIBS=On # variables unused - just for identification in travis ci gui
44+
script:
45+
- git submodule update --init tools/cmake
46+
- git submodule update --init libs/conversion
47+
- git submodule update --init libs/function_types
48+
- git submodule update --init libs/fusion
49+
- git submodule update --init libs/typeof
50+
- mkdir __build__ && cd __build__
51+
- cmake .. -DBUILD_SHARED_LIBS=ON -DBOOST_ENABLE_CMAKE=ON -DBOOST_REGEX_INCLUDE_EXAMPLES=ON
52+
- cmake --build .
53+
3054
- os: linux
3155
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03
3256

@@ -242,9 +266,12 @@ matrix:
242266
env: TOOLSET=clang COMPILER=clang++ CXXSTD=11
243267
osx_image: xcode6.4
244268

269+
270+
245271
install:
272+
- BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
246273
- cd ..
247-
- git clone -b $TRAVIS_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
274+
- git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost-root
248275
- cd boost-root
249276
- git submodule update --init tools/build
250277
- git submodule update --init tools/boost_install

CMakeLists.txt

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Copyright 2018-2019 Mike Dev
2+
# Distributed under the Boost Software License, Version 1.0.
3+
# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
4+
#
5+
# NOTE: CMake support for Boost.Regex is currently experimental at best
6+
# and the interface is likely to change in the future
7+
8+
9+
##### How-To:
10+
#
11+
# If you have a cmake project that wants to use and compile
12+
# boost_regex, as part of a single build system run, do the following:
13+
# 1) clone the boost project and all its sub-projects:
14+
#
15+
# git clone --branch develop --depth 1 --recursive --shallow-submodules https://github.com/boostorg/boost.git boost-root
16+
#
17+
# 2) add to your cmake script:
18+
#
19+
# add_subdirectory( <path-to-boost-root> [<build-dir-for-boost-libs>])
20+
# target_link_libraries( <my-exec> PUBLIC Boost::regex)
21+
#
22+
# 3) run your cmake build as usual
23+
#
24+
# ## Explanation:
25+
#
26+
# Currently this file does not work standalone. It is expected to be
27+
# invoked from a parent script via add_subdirectory. That parent script
28+
# is responsible for providing targets for direct and indirect dependencies,
29+
# such as Boost::assert, Boost::concept_check, e.g. by also adding those
30+
# libraries via add_submodule (order doesn't matter).
31+
# The parent script can be your own cmake script, but it is easier to just
32+
# use add the CMakeLists in the root of the boost super project, which
33+
# will in turn add all boost libraries usable with the add_subdirectory
34+
# Workflow.
35+
#
36+
# Note: You don't need to actually clone all boost libraries. E.g. look
37+
# into the travis ci file to see on which libraries boost_regex actually
38+
# depends or use boostdep https://github.com/boostorg/boostdep
39+
40+
41+
##### Current Limitations:
42+
#
43+
# - Doesn't compile or run tests
44+
# - Doesn't support installation
45+
#
46+
47+
cmake_minimum_required( VERSION 3.5 )
48+
project( BoostRegex LANGUAGES CXX )
49+
50+
option( BOOST_REGEX_INCLUDE_EXAMPLES "Also build (some) boost regex examples" OFF )
51+
option( BOOST_REGEX_USE_ICU "Enable ICU support in boost regex" OFF )
52+
53+
file( GLOB BOOST_REGEX_SRC ./src/*.cpp )
54+
55+
add_library( boost_regex ${BOOST_REGEX_SRC} )
56+
add_library( Boost::regex ALIAS boost_regex )
57+
58+
# Currently, installation isn't supported directly,
59+
# but someone else might install this target from the parent
60+
# CMake script, so lets proactively differentiate between
61+
# the include directory during regular use (BUILD_INTERFACE)
62+
# and after installation
63+
target_include_directories( boost_regex
64+
PUBLIC
65+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
66+
$<INSTALL_INTERFACE:include>
67+
)
68+
69+
target_compile_definitions( boost_regex
70+
PUBLIC
71+
# No need for autolink and we don't mangle library name anyway
72+
BOOST_REGEX_NO_LIB
73+
$<$<STREQUAL:$<TARGET_PROPERTY:boost_regex,TYPE>,SHARED_LIBRARY>:BOOST_REGEX_DYN_LINK=1>
74+
$<$<STREQUAL:$<TARGET_PROPERTY:boost_regex,TYPE>,STATIC_LIBRARY>:BOOST_REGEX_STATIC_LINK=1>
75+
)
76+
77+
# Specify dependencies (including header-only libraries)
78+
target_link_libraries( boost_regex
79+
PUBLIC
80+
Boost::assert
81+
Boost::concept_check
82+
Boost::config
83+
Boost::container_hash
84+
Boost::core
85+
Boost::integer
86+
Boost::iterator
87+
Boost::mpl
88+
Boost::predef
89+
Boost::smart_ptr
90+
Boost::static_assert
91+
Boost::throw_exception
92+
Boost::type_traits
93+
)
94+
95+
if( BOOST_REGEX_USE_ICU )
96+
# ICU Targets could be provided by parent project,
97+
# if not, look for them ourselves
98+
if( NOT TARGET ICU::dt )
99+
# components need to be listed explicitly
100+
find_package( ICU COMPONENTS dt in uc REQUIRED )
101+
endif()
102+
103+
target_link_libraries( boost_regex
104+
PRIVATE
105+
ICU::dt ICU::in ICU::uc
106+
)
107+
target_compile_definitions( boost_regex PRIVATE BOOST_HAS_ICU=1 )
108+
endif()
109+
110+
if( BOOST_REGEX_INCLUDE_EXAMPLES )
111+
add_subdirectory( example/snippets )
112+
endif()
113+

example/snippets/CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2019 Mike Dev
2+
# Distributed under the Boost Software License, Version 1.0.
3+
# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
4+
#
5+
# NOTE: CMake support for Boost.Regex is currently experimental at best
6+
# and we are currently only building a few examples
7+
8+
set(examples
9+
partial_regex_grep
10+
partial_regex_iterate
11+
partial_regex_match
12+
regex_grep_example_1
13+
regex_grep_example_2
14+
regex_grep_example_3
15+
regex_grep_example_4
16+
regex_iterator_example
17+
regex_match_example
18+
regex_merge_example
19+
regex_replace_example
20+
regex_search_example
21+
regex_split_example_1
22+
regex_split_example_2
23+
regex_token_iterator_eg_1
24+
regex_token_iterator_eg_2
25+
)
26+
27+
foreach( example IN LISTS examples )
28+
add_executable( boost_regex_ex_${example} ${example}.cpp )
29+
target_link_libraries( boost_regex_ex_${example} Boost::regex )
30+
endforeach()

0 commit comments

Comments
 (0)