Merge pull request #86 from Mike-Devel/min_cmake

[CMake] Add minimal cmake support
This commit is contained in:
jzmaddock
2020-01-07 18:47:46 +00:00
committed by GitHub
3 changed files with 171 additions and 1 deletions

View File

@ -27,6 +27,30 @@ matrix:
- env: BOGUS_JOB=true
include:
- os: linux
env: TEST_CMAKE=true # variables unused - just for identification in travis ci gui
script:
- git submodule update --init tools/cmake
- git submodule update --init libs/conversion
- git submodule update --init libs/function_types
- git submodule update --init libs/fusion
- git submodule update --init libs/typeof
- mkdir __build__ && cd __build__
- cmake .. -DBOOST_ENABLE_CMAKE=ON -DBOOST_REGEX_INCLUDE_EXAMPLES=ON
- cmake --build .
- os: linux
env: TEST_CMAKE=true BUILD_SHARED_LIBS=On # variables unused - just for identification in travis ci gui
script:
- git submodule update --init tools/cmake
- git submodule update --init libs/conversion
- git submodule update --init libs/function_types
- git submodule update --init libs/fusion
- git submodule update --init libs/typeof
- mkdir __build__ && cd __build__
- cmake .. -DBUILD_SHARED_LIBS=ON -DBOOST_ENABLE_CMAKE=ON -DBOOST_REGEX_INCLUDE_EXAMPLES=ON
- cmake --build .
- os: linux
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03
@ -242,9 +266,12 @@ matrix:
env: TOOLSET=clang COMPILER=clang++ CXXSTD=11
osx_image: xcode6.4
install:
- BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
- cd ..
- git clone -b $TRAVIS_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
- git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost-root
- cd boost-root
- git submodule update --init tools/build
- git submodule update --init tools/boost_install

113
CMakeLists.txt Normal file
View File

@ -0,0 +1,113 @@
# Copyright 2018-2019 Mike Dev
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
#
# NOTE: CMake support for Boost.Regex is currently experimental at best
# and the interface is likely to change in the future
##### How-To:
#
# If you have a cmake project that wants to use and compile
# boost_regex, as part of a single build system run, do the following:
# 1) clone the boost project and all its sub-projects:
#
# git clone --branch develop --depth 1 --recursive --shallow-submodules https://github.com/boostorg/boost.git boost-root
#
# 2) add to your cmake script:
#
# add_subdirectory( <path-to-boost-root> [<build-dir-for-boost-libs>])
# target_link_libraries( <my-exec> PUBLIC Boost::regex)
#
# 3) run your cmake build as usual
#
# ## Explanation:
#
# Currently this file does not work standalone. It is expected to be
# invoked from a parent script via add_subdirectory. That parent script
# is responsible for providing targets for direct and indirect dependencies,
# such as Boost::assert, Boost::concept_check, e.g. by also adding those
# libraries via add_submodule (order doesn't matter).
# The parent script can be your own cmake script, but it is easier to just
# use add the CMakeLists in the root of the boost super project, which
# will in turn add all boost libraries usable with the add_subdirectory
# Workflow.
#
# Note: You don't need to actually clone all boost libraries. E.g. look
# into the travis ci file to see on which libraries boost_regex actually
# depends or use boostdep https://github.com/boostorg/boostdep
##### Current Limitations:
#
# - Doesn't compile or run tests
# - Doesn't support installation
#
cmake_minimum_required( VERSION 3.5 )
project( BoostRegex LANGUAGES CXX )
option( BOOST_REGEX_INCLUDE_EXAMPLES "Also build (some) boost regex examples" OFF )
option( BOOST_REGEX_USE_ICU "Enable ICU support in boost regex" OFF )
file( GLOB BOOST_REGEX_SRC ./src/*.cpp )
add_library( boost_regex ${BOOST_REGEX_SRC} )
add_library( Boost::regex ALIAS boost_regex )
# Currently, installation isn't supported directly,
# but someone else might install this target from the parent
# CMake script, so lets proactively differentiate between
# the include directory during regular use (BUILD_INTERFACE)
# and after installation
target_include_directories( boost_regex
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_compile_definitions( boost_regex
PUBLIC
# No need for autolink and we don't mangle library name anyway
BOOST_REGEX_NO_LIB
$<$<STREQUAL:$<TARGET_PROPERTY:boost_regex,TYPE>,SHARED_LIBRARY>:BOOST_REGEX_DYN_LINK=1>
$<$<STREQUAL:$<TARGET_PROPERTY:boost_regex,TYPE>,STATIC_LIBRARY>:BOOST_REGEX_STATIC_LINK=1>
)
# Specify dependencies (including header-only libraries)
target_link_libraries( boost_regex
PUBLIC
Boost::assert
Boost::concept_check
Boost::config
Boost::container_hash
Boost::core
Boost::integer
Boost::iterator
Boost::mpl
Boost::predef
Boost::smart_ptr
Boost::static_assert
Boost::throw_exception
Boost::type_traits
)
if( BOOST_REGEX_USE_ICU )
# ICU Targets could be provided by parent project,
# if not, look for them ourselves
if( NOT TARGET ICU::dt )
# components need to be listed explicitly
find_package( ICU COMPONENTS dt in uc REQUIRED )
endif()
target_link_libraries( boost_regex
PRIVATE
ICU::dt ICU::in ICU::uc
)
target_compile_definitions( boost_regex PRIVATE BOOST_HAS_ICU=1 )
endif()
if( BOOST_REGEX_INCLUDE_EXAMPLES )
add_subdirectory( example/snippets )
endif()

View File

@ -0,0 +1,30 @@
# Copyright 2019 Mike Dev
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
#
# NOTE: CMake support for Boost.Regex is currently experimental at best
# and we are currently only building a few examples
set(examples
partial_regex_grep
partial_regex_iterate
partial_regex_match
regex_grep_example_1
regex_grep_example_2
regex_grep_example_3
regex_grep_example_4
regex_iterator_example
regex_match_example
regex_merge_example
regex_replace_example
regex_search_example
regex_split_example_1
regex_split_example_2
regex_token_iterator_eg_1
regex_token_iterator_eg_2
)
foreach( example IN LISTS examples )
add_executable( boost_regex_ex_${example} ${example}.cpp )
target_link_libraries( boost_regex_ex_${example} Boost::regex )
endforeach()