|
| 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 | + |
0 commit comments