-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfc9b62
commit 47f01b7
Showing
5 changed files
with
843 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
build | ||
build64 | ||
./build | ||
./build64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
# This CMakeLists wraps the Boost build scripts in order to allow compilation | ||
# in a separate build tree. | ||
# | ||
# Expected CMake variables are: | ||
# | ||
# MODULES_SEARCH_PATH : Search path for cmake-common modules | ||
# BOOST_SOURCE_DIR <path> : The absolute path to the Boost's source tree | ||
# BOOST_NO_COMPONENTS : Boolean flag if no components has to be built | ||
# BOOST_COMPONENTS <components>: List of components to build | ||
# BOOST_EXTRA_FLAGS <flags> : List of extra raw flags to provide to package | ||
# low level build engine | ||
# BOOST_FLAGS : List of flags to configure Boost's build | ||
# RUNTIME_STATIC : Flag to request static link with runtime | ||
# STATIC : Flag to request compilation of a staic library | ||
# | ||
cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR) | ||
|
||
include(ExternalPackageHelpers) | ||
include(HelpersArguments) | ||
include(EnhancedList) | ||
include(boost_build) | ||
|
||
# ============================================================================== | ||
# ======================= D e f i n e f u n c t i o n s ====================== | ||
# ============================================================================== | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Prepare the build context for the BOOST package | ||
macro(_boost_setup_build_context) | ||
# Parse given flags | ||
if(BOOST_FLAGS) | ||
parse_arguments("BOOST" | ||
"STATIC;RUNTIME_STATIC" | ||
"" | ||
"" | ||
"" | ||
${BOOST_FLAGS} | ||
) | ||
endif() | ||
|
||
# Prepare build base flags and build directory suffix | ||
unset(_base_build_flags) | ||
unset(_build_dir_suffix) | ||
|
||
if(CMAKE_SIZEOF_VOID_P EQUAL 8) | ||
list(APPEND _build_dir_suffix x64) | ||
else() | ||
list(APPEND _build_dir_suffix x86) | ||
endif() | ||
|
||
if(BOOST_STATIC) | ||
list(APPEND _base_build_flags STATIC) | ||
list(APPEND _build_dir_suffix ST) | ||
else() | ||
list(APPEND _build_dir_suffix SH) | ||
endif() | ||
|
||
if(BOOST_RUNTIME_STATIC) | ||
list(APPEND _base_build_flags RUNTIME_STATIC) | ||
list(APPEND _build_dir_suffix RS) | ||
endif() | ||
|
||
list_join(_build_dir_suffix "_" _build_dir_suffix) | ||
string(TOLOWER "${_build_dir_suffix}" _build_dir_suffix) | ||
|
||
# Set-up some directories | ||
set(BOOST_BUILD_BASE_DIR | ||
"${CMAKE_CURRENT_BINARY_DIR}/build/${_build_dir_suffix}" | ||
) | ||
|
||
set(BOOST_INSTALL_DIR | ||
"${CMAKE_CURRENT_BINARY_DIR}/stage/${_build_dir_suffix}" | ||
) | ||
|
||
external_setup_build_context(Boost "${_build_dir_suffix}") | ||
endmacro() | ||
|
||
|
||
# ============================================================================== | ||
# ==================== C o r e I m p l e m e n t a t i o n =================== | ||
# ============================================================================== | ||
|
||
_boost_setup_build_context() | ||
|
||
if(Boost_DEBUG) | ||
external_debug("Build context status:") | ||
foreach(_var NEED_BUILD NO_COMPONENTS EXTRA_FLAGS COMPONENTS | ||
STATIC RUNTIME_STATIC INSTALL_DIR BUILD_BASE_DIR) | ||
external_debug(" BOOST_${_var} : ${BOOST_${_var}}") | ||
endforeach() | ||
endif() | ||
|
||
if(BOOST_NEED_BUILD) | ||
# Determine what modes the Boost has to be compiled in | ||
if(CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) | ||
set(_build_modes "dbg" "rel") | ||
elseif(CMAKE_BUILD_TYPE MATCHES "^[Dd][Ee][Bb][Uu][Gg]$") | ||
set(_build_modes "dbg") | ||
else() | ||
set(_build_modes "rel") | ||
endif() | ||
|
||
file(MAKE_DIRECTORY "${BOOST_INSTALL_DIR}") | ||
foreach(_mode IN LISTS _build_modes) | ||
# Set build flags | ||
unset(_build_flags) | ||
unset(_lib_mode) | ||
|
||
if(BOOST_NO_COMPONENTS) | ||
list(APPEND _build_flags "NO_LIB") | ||
endif() | ||
|
||
if(_base_build_flags) | ||
list(APPEND _build_flags "${_base_build_flags}") | ||
list(APPEND _lib_mode "${_base_build_flags}") | ||
else() | ||
list(APPEND _lib_mode "SHARED") | ||
endif() | ||
|
||
if(_mode STREQUAL "dbg") | ||
list(APPEND _build_flags "DEBUG") | ||
list(APPEND _lib_mode "DEBUG") | ||
else() | ||
list(APPEND _lib_mode "RELEASE") | ||
endif() | ||
|
||
if(Boost_DEBUG) | ||
external_debug("_build_flags: '${_build_flags}'") | ||
endif() | ||
|
||
# Start the build session | ||
list_join(_lib_mode "/" _lib_mode) | ||
external_log("Building Libraries in mode ${_lib_mode}") | ||
boost_build( | ||
NO_LOG | ||
"${_build_flags}" | ||
SOURCE_DIR "${BOOST_SOURCE_DIR}" | ||
INSTALL_DIR "${BOOST_INSTALL_DIR}" | ||
BUILD_DIR "${BOOST_BUILD_BASE_DIR}/${_mode}" | ||
COMPONENTS ${BOOST_COMPONENTS} | ||
EXTRA_FLAGS "${BOOST_EXTRA_FLAGS}" | ||
) | ||
endforeach() | ||
|
||
external_teardown_build_context(Boost "${_build_dir_suffix}") | ||
|
||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,244 @@ | ||
# This CMAKE script should be included from parent wishing to build BOOST | ||
# libraries. | ||
# | ||
# Valid options are: | ||
# DEBUG # Flag to compile library in debug mode | ||
# STATIC # Flag to compile library in static mode | ||
# RUNTIME_STATIC # Flag to link with platform's static runtime | ||
# SOURCE_DIR <path> # Path to package's source tree | ||
# INSTALL_DIR <path> # Destination where to store built libraries | ||
# BUILD_DIR <path> # Destination where to build libraries | ||
# COMPONENTS <names> # List of names of the components to build | ||
# EXTRA_FLAGS <flags> # List of raw flags to provide to boost's scripts | ||
# | ||
# Example: | ||
# include(boost_build) | ||
# | ||
# boost_build( | ||
# SOURCE_DIR "path/to/the/package/source/tree" | ||
# COMPONENTS | ||
# chrono | ||
# filesystem | ||
# iostreams | ||
# EXTRA_FLAGS | ||
# -sNO_BZIP2=1 | ||
# ) | ||
# | ||
if(__H_BOOST_BUILD_INCLUDED) | ||
return() | ||
endif() | ||
set(__H_BOOST_BUILD_INCLUDED TRUE) | ||
|
||
cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR) | ||
|
||
include(ExternalPackageHelpers) | ||
include(HelpersArguments) | ||
include(SystemTools) | ||
include(ProcessorCount) | ||
|
||
# ============================================================================== | ||
# ======================= D e f i n e f u n c t i o n s ====================== | ||
# ============================================================================== | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Initializes the environment that will be needed to build the BOOST package | ||
macro(boost_build_initialization) | ||
# Parse arguments | ||
parse_arguments("BOOST_BUILD" | ||
"NO_LIB;NO_LOG;DEBUG;STATIC;RUNTIME_STATIC" | ||
"SOURCE_DIR;INSTALL_DIR;BUILD_DIR" | ||
"COMPONENTS;EXTRA_FLAGS" | ||
"" | ||
${ARGN} | ||
) | ||
|
||
if(NOT BOOST_BUILD_BUILD_DIR) | ||
set(BOOST_BUILD_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/boost") | ||
endif() | ||
|
||
if(NOT BOOST_BUILD_INSTALL_DIR) | ||
set(BOOST_BUILD_INSTALL_DIR "${BOOST_BUILD_BUILD_DIR}/stage") | ||
endif() | ||
|
||
if(Boost_DEBUG) | ||
set(Boost_DEBUG NO_LOG DEBUG) | ||
else() | ||
unset(Boost_DEBUG) | ||
endif() | ||
|
||
set(BOOST_BOOTSTRAP "${BOOST_BUILD_SOURCE_DIR}/bootstrap") | ||
set(BOOST_BUILDER "${BOOST_BUILD_SOURCE_DIR}/bjam") | ||
if(NOT BOOST_BUILD_NO_LOG) | ||
set(BOOST_BUILDER_LOG LOG "${BOOST_BUILD_BUILD_DIR}/boost_builder.log") | ||
else() | ||
set(BOOST_BUILDER_LOG NO_LOG) | ||
endif() | ||
|
||
if(CMAKE_SYSTEM_NAME STREQUAL "Windows") | ||
set(BOOST_BUILDER "${BOOST_BUILDER}.exe") | ||
set(BOOST_BOOTSTRAP "${BOOST_BOOTSTRAP}.bat") | ||
else() | ||
set(BOOST_BOOTSTRAP "${BOOST_BOOTSTRAP}.sh") | ||
endif() | ||
|
||
# Set-up toolset name and associated ABI flags flags | ||
unset(cxx_flags) | ||
unset(link_flags) | ||
string(TOLOWER "${CMAKE_CXX_COMPILER_ID}" toolset_name) | ||
if ("${toolset_name}" STREQUAL "clang") | ||
set(cxx_flags "cxxflags=-std=c++11 -stdlib=libc++") | ||
set(link_flags "linkflags=-stdlib=libc++") | ||
elseif ("${toolset_name}" STREQUAL "gnu") | ||
set(toolset_name "gcc") | ||
string(REGEX REPLACE | ||
"([0-9]+)(\\.([0-9]+))?.*" | ||
"gcc\\1\\3" | ||
toolset_version | ||
"${CMAKE_CXX_COMPILER_VERSION}" | ||
) | ||
set(cxx_flags "cxxflags=-std=c++11") | ||
elseif("${toolset_name}" STREQUAL "msvc") | ||
else() | ||
external_error("COMPILER '${CMAKE_CXX_COMPILER_ID}' NOT HANDLED") | ||
endif() | ||
|
||
unset(_arch_cfg) | ||
list(APPEND _arch_cfg "architecture=x86") | ||
if(CMAKE_SIZEOF_VOID_P EQUAL 8) | ||
list(APPEND _arch_cfg "address-model=64") | ||
else() | ||
list(APPEND _arch_cfg "address-model=32") | ||
endif() | ||
|
||
ProcessorCount(_processors_count) | ||
if(_processors_count) | ||
set(_processors_count "-j${_processors_count}") | ||
else() | ||
unset(_processors_count) | ||
endif() | ||
|
||
# Compile BOOST's build tool | ||
if(NOT EXISTS "${BOOST_BUILDER}") | ||
external_log("Compiling Boost's builder") | ||
unset(_tmp) | ||
if(NOT "$ENV{CC}" STREQUAL "") | ||
set(_tmp "ENV" "CC=") | ||
endif() | ||
system_execute( | ||
${Boost_DEBUG} | ||
"${BOOST_BUILDER_LOG}" | ||
WORKING_DIR "${BOOST_BUILD_SOURCE_DIR}" | ||
COMMAND "${BOOST_BOOTSTRAP}" | ||
${_tmp} | ||
) | ||
|
||
# Test we successfully built builder | ||
if(NOT EXISTS "${BOOST_BUILDER}") | ||
if(EXISTS "${BOOST_BUILD_SOURCE_DIR}/bootstrap.log") | ||
file(STRINGS "${BOOST_BUILD_SOURCE_DIR}/bootstrap.log" _tmp) | ||
external_log("===[ ${BOOST_BUILD_SOURCE_DIR}/bootstrap.log ] ===\n") | ||
foreach(_line IN LISTS _tmp) | ||
external_log("${_line}") | ||
endforeach() | ||
external_log("===") | ||
endif() | ||
external_error("Cannot compile Boost's builder.") | ||
endif() | ||
endif() | ||
|
||
# Compute list of possible components | ||
execute_process( | ||
OUTPUT_VARIABLE _boost_libraries | ||
WORKING_DIRECTORY "${BOOST_BUILD_SOURCE_DIR}" | ||
COMMAND "${BOOST_BUILDER}" "--show-libraries" | ||
) | ||
string(REGEX REPLACE "(^[^:]+:[\t ]*\n|[\t ]+)" "" | ||
_boost_libraries "${_boost_libraries}") | ||
string(REGEX REPLACE "-([^\n]*)\n+" "\\1;" | ||
_boost_libraries "${_boost_libraries}") | ||
string(REGEX REPLACE ";+$" "" | ||
_boost_libraries "${_boost_libraries}") | ||
|
||
# Create BOOST's headers tree in case of Boost Modular repo | ||
if(NOT EXISTS "${BOOST_BUILD_SOURCE_DIR}/boost") | ||
external_log("Create Boost's headers tree") | ||
system_execute( | ||
${Boost_DEBUG} | ||
"${BOOST_BUILDER_LOG}" | ||
WORKING_DIR "${BOOST_BUILD_SOURCE_DIR}" | ||
COMMAND "${BOOST_BUILDER}" | ||
ARGS headers | ||
) | ||
endif() | ||
endmacro() | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Build the BOOST package from the given source path | ||
function(boost_build) | ||
|
||
# Prepare BOOST context | ||
boost_build_initialization("${ARGN}") | ||
|
||
# Prepare build options | ||
if(BOOST_BUILD_NO_LIB) | ||
# No libraries to compile... | ||
return() | ||
endif() | ||
|
||
set(_build_options | ||
"${cxx_flags}" | ||
"${link_flags}" | ||
"${_arch_cfg}" | ||
"toolset=${toolset_name}" | ||
"${_processors_count}" | ||
"-q" | ||
"--hash" | ||
--debug-configuration | ||
--layout=versioned | ||
stage | ||
"--stagedir=${BOOST_BUILD_INSTALL_DIR}" | ||
"--build-dir=${BOOST_BUILD_BUILD_DIR}" | ||
) | ||
|
||
if(NOT BOOST_BUILD_DEBUG) | ||
list(APPEND _build_options variant=release optimization=space) | ||
else() | ||
list(APPEND _build_options variant=debug) | ||
endif() | ||
|
||
unset(_skipped) | ||
list_join(_boost_libraries "|" _filter) | ||
foreach(_component ${BOOST_BUILD_COMPONENTS}) | ||
if("${_component}" MATCHES "^(${_filter})$") | ||
list(APPEND _build_options "--with-${_component}") | ||
else() | ||
list(APPEND _skipped "${_component}") | ||
endif() | ||
endforeach() | ||
if(_skipped) | ||
list_join(_skipped ", " _skipped) | ||
external_log("Skipping implicit libraries: ${_skipped}") | ||
endif() | ||
|
||
if(BOOST_BUILD_EXTRA_FLAGS) | ||
list(APPEND _build_options "${BOOST_BUILD_EXTRA_FLAGS}") | ||
endif() | ||
|
||
if(NOT BOOST_BUILD_STATIC) | ||
list(APPEND _build_options link=shared runtime-link=shared) | ||
elseif(NOT BOOST_BUILD_RUNTIME_STATIC) | ||
list(APPEND _build_options link=static runtime-link=shared) | ||
else() | ||
list(APPEND _build_options link=static runtime-link=static) | ||
endif() | ||
|
||
# Compile BOOST libraries | ||
system_execute( | ||
${Boost_DEBUG} | ||
"${BOOST_BUILDER_LOG}" | ||
WORKING_DIR "${BOOST_BUILD_SOURCE_DIR}" | ||
COMMAND "${BOOST_BUILDER}" | ||
ARGS "${_build_options}" | ||
) | ||
endfunction() | ||
|
Oops, something went wrong.