From e72490638a8801a1830a909d6a09f34b35a543a1 Mon Sep 17 00:00:00 2001 From: Mike Dev Date: Tue, 2 Oct 2018 22:04:12 +0200 Subject: [PATCH 01/10] [CMake] Add minimal cmake file Generate cmake target that builds the library and which can be used by other libraries to express their dependency on this library and retrieve any configuration information such as the include directory, binary to link to, transitive dependencies, necessary compiler options or the required c++ standards level. --- CMakeLists.txt | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..598cbd9d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright 2018 Mike Dev +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt + +cmake_minimum_required(VERSION 3.5) +project(BoostRegex LANGUAGES CXX) + + +file(GLOB BOOST_REGEX_SRC ./src/*.cpp) + +add_library(boost_regex ${BOOST_REGEX_SRC}) +add_library(Boost::regex ALIAS boost_regex) + +target_include_directories(boost_regex PUBLIC include) + +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 +) From 3d44eca405e4a930e75d7f50862e803c67ba98e3 Mon Sep 17 00:00:00 2001 From: Mike Dev Date: Sun, 16 Jun 2019 19:47:22 +0200 Subject: [PATCH 02/10] [CMake] Add option to build some of the examples --- CMakeLists.txt | 27 ++++++++++++++++++--------- example/snippets/CMakeLists.txt | 30 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 example/snippets/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 598cbd9d..bce463c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,19 +1,23 @@ -# Copyright 2018 Mike Dev +# Copyright 2018-2019 Mike Dev # Distributed under the Boost Software License, Version 1.0. -# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt +# 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 -cmake_minimum_required(VERSION 3.5) -project(BoostRegex LANGUAGES CXX) +cmake_minimum_required( VERSION 3.5 ) +project( BoostRegex LANGUAGES CXX ) +option( BOOST_REGEX_INCLUDE_EXAMPLES "Also build (some) boost regex examples" OFF ) -file(GLOB BOOST_REGEX_SRC ./src/*.cpp) +file( GLOB BOOST_REGEX_SRC ./src/*.cpp ) -add_library(boost_regex ${BOOST_REGEX_SRC}) -add_library(Boost::regex ALIAS boost_regex) +add_library( boost_regex ${BOOST_REGEX_SRC} ) +add_library( Boost::regex ALIAS boost_regex ) -target_include_directories(boost_regex PUBLIC include) +target_include_directories( boost_regex PUBLIC include ) -target_link_libraries(boost_regex +target_link_libraries( boost_regex PUBLIC Boost::assert Boost::concept_check @@ -29,3 +33,8 @@ target_link_libraries(boost_regex Boost::throw_exception Boost::type_traits ) + +if( BOOST_REGEX_INCLUDE_EXAMPLES ) + add_subdirectory( example/snippets ) +endif() + diff --git a/example/snippets/CMakeLists.txt b/example/snippets/CMakeLists.txt new file mode 100644 index 00000000..f672785b --- /dev/null +++ b/example/snippets/CMakeLists.txt @@ -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() From bb0c6105911b307ada3d83f2f2d54ebb493499cc Mon Sep 17 00:00:00 2001 From: Mike Dev Date: Sun, 8 Dec 2019 16:21:30 +0100 Subject: [PATCH 03/10] [CMake] Add option for compilation with ICU support --- CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bce463c4..3e1fe28c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ 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 ) @@ -34,6 +35,19 @@ target_link_libraries( boost_regex Boost::type_traits ) +if( BOOST_REGEX_USE_ICU ) + 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() From e54e8e01738445b8d42c360675ec8fb021c60ab4 Mon Sep 17 00:00:00 2001 From: Mike Dev Date: Sat, 28 Dec 2019 11:55:46 +0100 Subject: [PATCH 04/10] [CMake] Disable autolink for regex --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e1fe28c..1c0fdd27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ add_library( boost_regex ${BOOST_REGEX_SRC} ) add_library( Boost::regex ALIAS boost_regex ) target_include_directories( boost_regex PUBLIC include ) +target_compile_definitions( boost_regex PUBLIC BOOST_REGEX_NO_LIB) target_link_libraries( boost_regex PUBLIC From 7ec82a06d4f17f3f70b66a5118d2f6cb5de2f7f9 Mon Sep 17 00:00:00 2001 From: Mike Dev Date: Sat, 28 Dec 2019 12:14:26 +0100 Subject: [PATCH 05/10] [CI] Enable travis script to run with other branches than master or develop --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2bc5872d..3b8daa5f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -243,8 +243,9 @@ matrix: 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 From 634fa6847eec9d12817ce2e70c16be370c096282 Mon Sep 17 00:00:00 2001 From: Mike Dev Date: Sat, 28 Dec 2019 12:06:34 +0100 Subject: [PATCH 06/10] [CMake/CI] Add basic cmake run to travis --- .travis.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.travis.yml b/.travis.yml index 3b8daa5f..d7abf7e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,14 @@ matrix: - os: linux env: TOOLSET=gcc COMPILER=g++ CXXSTD=03 + - os: linux + env: TEST_CMAKE=true + script: + - mkdir __build__ + - cd __build__ + - cmake .. -DBOOST_ENABLE_CMAKE=ON -DBOOST_REGEX_INCLUDE_EXAMPLES=ON + - cmake --build . + - os: linux env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=03,11 addons: @@ -242,6 +250,8 @@ matrix: env: TOOLSET=clang COMPILER=clang++ CXXSTD=11 osx_image: xcode6.4 + + install: - BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true - cd .. From 45d12f199d92f2d0cf23f37b4368bf76151bc533 Mon Sep 17 00:00:00 2001 From: Mike Dev Date: Sat, 28 Dec 2019 12:22:27 +0100 Subject: [PATCH 07/10] [CMake/CI] Clone additional transitive dependencies --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d7abf7e4..56dffdc5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,8 +31,13 @@ matrix: env: TOOLSET=gcc COMPILER=g++ CXXSTD=03 - os: linux - env: TEST_CMAKE=true + env: TEST_CMAKE=true # unused - just for identification in travis ci gui script: + - git submodule update --init tools/cmake + - git submodule update --init libs/typeof + - git submodule update --init libs/conversion + - git submodule update --init libs/function_types + - git submodule update --init libs/fusion - mkdir __build__ - cd __build__ - cmake .. -DBOOST_ENABLE_CMAKE=ON -DBOOST_REGEX_INCLUDE_EXAMPLES=ON From c07e8c4f8076581682e17be2437ac98bce65b646 Mon Sep 17 00:00:00 2001 From: Mike Dev Date: Sat, 28 Dec 2019 13:51:31 +0100 Subject: [PATCH 08/10] [CMake] Add support for building shared library and restrict absolute include path to build interface --- CMakeLists.txt | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c0fdd27..621e28a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,9 +16,26 @@ file( GLOB BOOST_REGEX_SRC ./src/*.cpp ) add_library( boost_regex ${BOOST_REGEX_SRC} ) add_library( Boost::regex ALIAS boost_regex ) -target_include_directories( boost_regex PUBLIC include ) -target_compile_definitions( boost_regex PUBLIC BOOST_REGEX_NO_LIB) +# 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 + $ + $ +) +target_compile_definitions( boost_regex + PUBLIC + # No need for autolink and we don't mangle library name anyway + BOOST_REGEX_NO_LIB + $<$,SHARED_LIBRARY>:BOOST_REGEX_DYN_LINK=1> + $<$,STATIC_LIBRARY>:BOOST_REGEX_STATIC_LINK=1> +) + +# Specify dependencies (including header-only libraries) target_link_libraries( boost_regex PUBLIC Boost::assert From 957d2f1bca51b44af9360c3aadc2068567b3e3aa Mon Sep 17 00:00:00 2001 From: Mike Dev Date: Sat, 28 Dec 2019 13:52:21 +0100 Subject: [PATCH 09/10] [CMake] Add some comments about how to use the file --- CMakeLists.txt | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 621e28a1..d7e190be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,45 @@ # 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( []) +# target_link_libraries( 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 ) @@ -54,6 +93,8 @@ target_link_libraries( boost_regex ) 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 ) From 92f6a803a5c497e0da5d8fd8304758a4c1cb18ff Mon Sep 17 00:00:00 2001 From: Mike Dev Date: Sat, 28 Dec 2019 13:54:25 +0100 Subject: [PATCH 10/10] [CMake/CI] Also test build as shared library on travis Also, as a minor tweak, put cmake builds to the front as they complete the most quickly --- .travis.yml | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 56dffdc5..bad8a07e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,21 +28,32 @@ matrix: include: - os: linux - env: TOOLSET=gcc COMPILER=g++ CXXSTD=03 - - - os: linux - env: TEST_CMAKE=true # unused - just for identification in travis ci gui - script: + 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/typeof - git submodule update --init libs/conversion - git submodule update --init libs/function_types - git submodule update --init libs/fusion - - mkdir __build__ - - cd __build__ - - cmake .. -DBOOST_ENABLE_CMAKE=ON -DBOOST_REGEX_INCLUDE_EXAMPLES=ON + - 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 + - os: linux env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=03,11 addons: