diff --git a/CMakeLists.txt b/CMakeLists.txt index 02eda9fdb..c53bafa9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,16 +2,28 @@ cmake_minimum_required(VERSION 3.12) project(Boost-CMake) option(BOOST_DISABLE_TESTS "Do not build test targets, even if building standalone" OFF) +option(BOOST_GIT "Get Boost from Git source" OFF) set(BOOST_URL "https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.bz2" CACHE STRING "Boost download URL") set(BOOST_URL_SHA256 "8f32d4617390d1c2d16f26a27ab60d97807b35440d45891fa340fc2648b04406" CACHE STRING "Boost download URL SHA256 checksum") +set(BOOST_GIT_URL "https://github.com/boostorg/boost.git" CACHE STRING "Boost Git URL to top-level repository") +set(BOOST_GIT_TAG "boost-1.69.0" CACHE STRING "Boost Git tag or branch name") include(FetchContent) -FetchContent_Declare( - Boost - URL ${BOOST_URL} - URL_HASH SHA256=${BOOST_URL_SHA256} -) + +if(BOOST_GIT) + FetchContent_Declare( + Boost + GIT_REPOSITORY "${BOOST_GIT_URL}" + GIT_TAG "${BOOST_GIT_TAG}" + ) +else() + FetchContent_Declare( + Boost + URL ${BOOST_URL} + URL_HASH SHA256=${BOOST_URL_SHA256} + ) +endif() FetchContent_GetProperties(Boost) if(NOT Boost_POPULATED) diff --git a/README.md b/README.md index f75014217..a28672564 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,23 @@ set(BOOST_URL_SHA256 foobar) add_subdirectory(boost-cmake) ``` +If you prefer using Boost from Git, you can use the following: +``` +set(BOOST_GIT ON) +add_subdirectory(boost-cmake) +``` + +For more advanced configuration, you can override the way to download the sources using [FetchContent_Declare](https://cmake.org/cmake/help/latest/module/FetchContent.html): +``` +FetchContent_Declare( + Boost + SVN_REPOSITORY "svn+ssh://svn.company.com/boost" +) +``` + If you have Boost sources already available and want to point to them, you can use the following: ``` -set(BOOST_SOURCE /path/to/boost) +set(FETCHCONTENT_SOURCE_DIR_boost /path/to/boost) add_subdirectory(boost-cmake) ``` diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 9b582f08a..81f8e77f8 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -13,6 +13,11 @@ strategy: imageName: 'ubuntu-16.04' BUILD_TARGET: 'Linux' BUILD_COMPILER: 'Clang' + Linux-Clang-Git: + imageName: 'ubuntu-16.04' + BUILD_TARGET: 'Linux' + BUILD_COMPILER: 'Clang' + BUILD_GIT: 'ON' Android-arm64: imageName: 'ubuntu-16.04' BUILD_TARGET: 'Android' @@ -63,4 +68,5 @@ steps: BUILD_COMPILER: $(BUILD_COMPILER) BUILD_ARCH: $(BUILD_ARCH) BUILD_TOOLCHAIN: $(BUILD_TOOLCHAIN) + BUILD_GIT: $(BUILD_GIT) CCACHE_DISABLE: 1 diff --git a/build.sh b/build.sh index c2fa0f0e3..38808740a 100644 --- a/build.sh +++ b/build.sh @@ -59,6 +59,10 @@ build_script() { mkdir build pushd build + if [[ "$BUILD_GIT" == "ON" ]]; then + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DBOOST_GIT=ON" + fi + if [[ "$BUILD_TARGET" == "Linux" ]]; then if [[ "$BUILD_COMPILER" == "GCC" ]]; then CC=gcc-5 @@ -69,21 +73,24 @@ build_script() { fi cmake .. -GNinja \ -DCMAKE_C_COMPILER=$CC \ - -DCMAKE_CXX_COMPILER=$CXX + -DCMAKE_CXX_COMPILER=$CXX \ + $CMAKE_OPTIONS elif [[ "$BUILD_TARGET" == "Android" ]]; then cmake .. -GNinja \ -DCMAKE_SYSTEM_NAME=Android \ -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang \ - -DCMAKE_ANDROID_ARCH_ABI=${BUILD_ARCH} + -DCMAKE_ANDROID_ARCH_ABI=${BUILD_ARCH} \ + $CMAKE_OPTIONS elif [[ "$BUILD_TARGET" == "macOS" ]]; then - cmake .. -GNinja + cmake .. -GNinja $CMAKE_OPTIONS elif [[ "$BUILD_TARGET" == "iOS" ]]; then cmake .. -GNinja \ - -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchains/ios.cmake + -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchains/ios.cmake \ + $CMAKE_OPTIONS elif [[ "$BUILD_TARGET" == "Windows" ]]; then vcpath=$(vswhere.exe -latest -property installationPath) vcscript="\"$vcpath\\VC\\Auxiliary\\Build\\vcvarsall.bat\" $BUILD_TOOLCHAIN" - cmd.exe /c "$vcscript & cmake .. -GNinja -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe & ninja -v" + cmd.exe /c "$vcscript & cmake .. -GNinja -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe $CMAKE_OPTIONS & ninja -v" exit 0 fi diff --git a/cmake/Modules/CheckBoostVersion.cmake b/cmake/Modules/CheckBoostVersion.cmake index e9fceb383..f7dc7e8da 100644 --- a/cmake/Modules/CheckBoostVersion.cmake +++ b/cmake/Modules/CheckBoostVersion.cmake @@ -1,5 +1,15 @@ # Detect Boost version -file(STRINGS "${BOOST_SOURCE}/boost/version.hpp" boost_version_raw +if(EXISTS "${BOOST_SOURCE}/boost/version.hpp") + set(BOOST_MODULARIZED FALSE) + set(boost_version_file "${BOOST_SOURCE}/boost/version.hpp") + message(STATUS "Boost format: archive") +elseif(EXISTS "${BOOST_SOURCE}/libs/config/include/boost/version.hpp") + set(BOOST_MODULARIZED TRUE) + set(boost_version_file "${BOOST_SOURCE}/libs/config/include/boost/version.hpp") + message(STATUS "Boost format: modularized") +endif() + +file(STRINGS "${boost_version_file}" boost_version_raw REGEX "define BOOST_VERSION " ) string(REGEX MATCH "[0-9]+" boost_version_raw "${boost_version_raw}") @@ -7,3 +17,6 @@ math(EXPR BOOST_VERSION_MAJOR "${boost_version_raw} / 100000") math(EXPR BOOST_VERSION_MINOR "${boost_version_raw} / 100 % 1000") math(EXPR BOOST_VERSION_PATCH "${boost_version_raw} % 100") set(BOOST_VERSION "${BOOST_VERSION_MAJOR}.${BOOST_VERSION_MINOR}.${BOOST_VERSION_PATCH}") + +unset(boost_version_raw) +unset(boost_version_file) diff --git a/libs/context.cmake b/libs/context.cmake index ac5d6ff37..caa689d4d 100644 --- a/libs/context.cmake +++ b/libs/context.cmake @@ -41,6 +41,8 @@ _add_boost_lib( DEFINE_PRIVATE BOOST_CONTEXT_SOURCE=1 BOOST_CONTEXT_EXPORT + INCLUDE_PRIVATE + ${BOOST_SOURCE}/libs/context/src/asm LINK Boost::thread ) diff --git a/libs/context/jump_combined.S b/libs/context/jump_combined.S index cb9b494e4..dd71d0c59 100644 --- a/libs/context/jump_combined.S +++ b/libs/context/jump_combined.S @@ -1,21 +1,21 @@ #if defined(__APPLE__) #if defined(__arm__) - #include "libs/context/src/asm/jump_arm_aapcs_macho_gas.S" + #include "jump_arm_aapcs_macho_gas.S" #elif defined(__arm64__) - #include "libs/context/src/asm/jump_arm64_aapcs_macho_gas.S" + #include "jump_arm64_aapcs_macho_gas.S" #else // Other kinds of macOS or iOS Simulator - #include "libs/context/src/asm/jump_combined_sysv_macho_gas.S" + #include "jump_combined_sysv_macho_gas.S" #endif #elif defined(__linux__) || defined(__FreeBSD__) #if defined(__arm__) - #include "libs/context/src/asm/jump_arm_aapcs_elf_gas.S" + #include "jump_arm_aapcs_elf_gas.S" #elif defined(__aarch64__) - #include "libs/context/src/asm/jump_arm64_aapcs_elf_gas.S" + #include "jump_arm64_aapcs_elf_gas.S" #elif defined(__i386__) - #include "libs/context/src/asm/jump_i386_sysv_elf_gas.S" + #include "jump_i386_sysv_elf_gas.S" #elif defined(__x86_64__) - #include "libs/context/src/asm/jump_x86_64_sysv_elf_gas.S" + #include "jump_x86_64_sysv_elf_gas.S" #else #error "Unknown platform" #endif diff --git a/libs/context/make_combined.S b/libs/context/make_combined.S index 28b4fedb8..7d10ba1ee 100644 --- a/libs/context/make_combined.S +++ b/libs/context/make_combined.S @@ -1,21 +1,21 @@ #if defined(__APPLE__) #if defined(__arm__) - #include "libs/context/src/asm/make_arm_aapcs_macho_gas.S" + #include "make_arm_aapcs_macho_gas.S" #elif defined(__arm64__) - #include "libs/context/src/asm/make_arm64_aapcs_macho_gas.S" + #include "make_arm64_aapcs_macho_gas.S" #else // Other kinds of macOS or iOS Simulator - #include "libs/context/src/asm/make_combined_sysv_macho_gas.S" + #include "make_combined_sysv_macho_gas.S" #endif #elif defined(__linux__) || defined(__FreeBSD__) #if defined(__arm__) - #include "libs/context/src/asm/make_arm_aapcs_elf_gas.S" + #include "make_arm_aapcs_elf_gas.S" #elif defined(__aarch64__) - #include "libs/context/src/asm/make_arm64_aapcs_elf_gas.S" + #include "make_arm64_aapcs_elf_gas.S" #elif defined(__i386__) - #include "libs/context/src/asm/make_i386_sysv_elf_gas.S" + #include "make_i386_sysv_elf_gas.S" #elif defined(__x86_64__) - #include "libs/context/src/asm/make_x86_64_sysv_elf_gas.S" + #include "make_x86_64_sysv_elf_gas.S" #else #error "Unknown platform" #endif diff --git a/libs/context/ontop_combined.S b/libs/context/ontop_combined.S index a387aaf37..87d5bc156 100644 --- a/libs/context/ontop_combined.S +++ b/libs/context/ontop_combined.S @@ -1,21 +1,21 @@ #if defined(__APPLE__) #if defined(__arm__) - #include "libs/context/src/asm/ontop_arm_aapcs_macho_gas.S" + #include "ontop_arm_aapcs_macho_gas.S" #elif defined(__arm64__) - #include "libs/context/src/asm/ontop_arm64_aapcs_macho_gas.S" + #include "ontop_arm64_aapcs_macho_gas.S" #else // Other kinds of macOS or iOS Simulator - #include "libs/context/src/asm/ontop_combined_sysv_macho_gas.S" + #include "ontop_combined_sysv_macho_gas.S" #endif #elif defined(__linux__) || defined(__FreeBSD__) #if defined(__arm__) - #include "libs/context/src/asm/ontop_arm_aapcs_elf_gas.S" + #include "ontop_arm_aapcs_elf_gas.S" #elif defined(__aarch64__) - #include "libs/context/src/asm/ontop_arm64_aapcs_elf_gas.S" + #include "ontop_arm64_aapcs_elf_gas.S" #elif defined(__i386__) - #include "libs/context/src/asm/ontop_i386_sysv_elf_gas.S" + #include "ontop_i386_sysv_elf_gas.S" #elif defined(__x86_64__) - #include "libs/context/src/asm/ontop_x86_64_sysv_elf_gas.S" + #include "ontop_x86_64_sysv_elf_gas.S" #else #error "Unknown platform" #endif diff --git a/libs/header.cmake b/libs/header.cmake index dd336546b..6e35d1d62 100644 --- a/libs/header.cmake +++ b/libs/header.cmake @@ -1,6 +1,16 @@ # Define the header-only Boost target add_library(Boost::boost INTERFACE IMPORTED GLOBAL) -target_include_directories(Boost::boost SYSTEM INTERFACE ${BOOST_SOURCE}) # Disable autolink target_compile_definitions(Boost::boost INTERFACE BOOST_ALL_NO_LIB=1) + +if(BOOST_MODULARIZED) + file(GLOB alllibs "${BOOST_SOURCE}/libs/*" "${BOOST_SOURCE}/libs/numeric/*") + foreach(lib IN LISTS alllibs) + if(IS_DIRECTORY "${lib}/include") + target_include_directories(Boost::boost SYSTEM INTERFACE "${lib}/include") + endif() + endforeach() +else() + target_include_directories(Boost::boost SYSTEM INTERFACE ${BOOST_SOURCE}) +endif()