Skip to content

Commit

Permalink
Experimental support for supporting builds from the Git repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Orphis committed Dec 24, 2018
1 parent 8797ece commit e29f0a6
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 34 deletions.
22 changes: 17 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

Expand Down
6 changes: 6 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -63,4 +68,5 @@ steps:
BUILD_COMPILER: $(BUILD_COMPILER)
BUILD_ARCH: $(BUILD_ARCH)
BUILD_TOOLCHAIN: $(BUILD_TOOLCHAIN)
BUILD_GIT: $(BUILD_GIT)
CCACHE_DISABLE: 1
17 changes: 12 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
15 changes: 14 additions & 1 deletion cmake/Modules/CheckBoostVersion.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
# 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}")
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)
2 changes: 2 additions & 0 deletions libs/context.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
14 changes: 7 additions & 7 deletions libs/context/jump_combined.S
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 7 additions & 7 deletions libs/context/make_combined.S
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 7 additions & 7 deletions libs/context/ontop_combined.S
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 11 additions & 1 deletion libs/header.cmake
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit e29f0a6

Please sign in to comment.