2018-03-12 14:01:33 +08:00
|
|
|
cmake_minimum_required(VERSION 3.9)
|
|
|
|
project(boost CXX)
|
|
|
|
|
2021-09-22 06:07:46 +08:00
|
|
|
set(B2_OPTIONS)
|
2018-03-12 14:01:33 +08:00
|
|
|
|
2021-09-22 06:07:46 +08:00
|
|
|
if(MSVC)
|
|
|
|
if(MSVC_VERSION LESS 1900)
|
|
|
|
math(EXPR BOOST_MSVC_VERSION "${MSVC_VERSION} / 10 - 60")
|
|
|
|
else()
|
|
|
|
math(EXPR BOOST_MSVC_VERSION "${MSVC_VERSION} / 10 - 50")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
set(VCPKG_PLATFORM_TOOLSET external)
|
|
|
|
endif()
|
2018-03-12 14:01:33 +08:00
|
|
|
|
2021-09-22 06:07:46 +08:00
|
|
|
#### Handle ICU
|
|
|
|
if(WIN32)
|
|
|
|
list(APPEND B2_OPTIONS "--disable-icu")
|
|
|
|
else()
|
|
|
|
find_path(ICU_PATH include/unicode/utf.h)
|
|
|
|
list(APPEND B2_OPTIONS "-sICU_PATH=\"${ICU_PATH}\"")
|
|
|
|
endif()
|
2018-03-12 14:01:33 +08:00
|
|
|
|
|
|
|
# Add build type specific options
|
2021-09-22 06:07:46 +08:00
|
|
|
if(VCPKG_CRT_LINKAGE STREQUAL "dynamic")
|
2018-03-12 14:01:33 +08:00
|
|
|
list(APPEND B2_OPTIONS runtime-link=shared)
|
|
|
|
set(LIB_RUNTIME_LINK "shared")
|
|
|
|
else()
|
|
|
|
list(APPEND B2_OPTIONS runtime-link=static)
|
|
|
|
set(LIB_RUNTIME_LINK "static")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
list(APPEND B2_OPTIONS link=shared)
|
|
|
|
else()
|
|
|
|
list(APPEND B2_OPTIONS link=static)
|
|
|
|
endif()
|
|
|
|
|
2018-05-15 08:10:20 +08:00
|
|
|
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
2018-03-12 14:01:33 +08:00
|
|
|
list(APPEND B2_OPTIONS address-model=64)
|
2018-05-15 08:10:20 +08:00
|
|
|
else()
|
|
|
|
list(APPEND B2_OPTIONS address-model=32)
|
2018-03-12 14:01:33 +08:00
|
|
|
endif()
|
|
|
|
|
2020-07-31 13:55:25 +08:00
|
|
|
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "s390x")
|
|
|
|
list(APPEND B2_OPTIONS architecture=s390x)
|
2020-09-06 01:45:48 +08:00
|
|
|
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm" OR VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
|
|
|
|
list(APPEND B2_OPTIONS architecture=arm)
|
2021-01-23 02:37:26 +08:00
|
|
|
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "ppc64le")
|
|
|
|
list(APPEND B2_OPTIONS architecture=power)
|
2020-07-31 13:55:25 +08:00
|
|
|
else()
|
|
|
|
list(APPEND B2_OPTIONS architecture=x86)
|
|
|
|
endif()
|
|
|
|
|
2021-09-22 06:07:46 +08:00
|
|
|
if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86" AND WIN32)
|
|
|
|
list(APPEND B2_OPTIONS "asmflags=/safeseh")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
file(TO_CMAKE_PATH "${CMAKE_CURRENT_LIST_DIR}/nothing.bat" NOTHING_BAT)
|
|
|
|
|
|
|
|
if(MSVC)
|
|
|
|
set(B2_TOOLSET msvc)
|
|
|
|
list(APPEND B2_OPTIONS target-os=windows)
|
|
|
|
elseif(APPLE)
|
2021-07-07 05:05:13 +08:00
|
|
|
set(B2_TOOLSET clang)
|
|
|
|
list(APPEND B2_OPTIONS target-os=darwin)
|
2020-02-12 09:30:03 +08:00
|
|
|
elseif(WIN32)
|
2021-07-07 05:05:13 +08:00
|
|
|
set(B2_TOOLSET gcc)
|
|
|
|
list(APPEND B2_OPTIONS target-os=windows)
|
2021-05-01 02:43:39 +08:00
|
|
|
elseif(ANDROID)
|
2021-07-07 05:05:13 +08:00
|
|
|
set(B2_TOOLSET gcc)
|
|
|
|
list(APPEND B2_OPTIONS target-os=android)
|
2018-04-18 07:26:01 +08:00
|
|
|
else()
|
2021-07-07 05:05:13 +08:00
|
|
|
set(B2_TOOLSET gcc)
|
|
|
|
list(APPEND B2_OPTIONS target-os=linux)
|
2018-04-18 07:26:01 +08:00
|
|
|
endif()
|
2018-03-12 14:01:33 +08:00
|
|
|
|
2020-02-12 09:30:03 +08:00
|
|
|
if(WIN32)
|
|
|
|
list(APPEND B2_OPTIONS threadapi=win32)
|
|
|
|
else()
|
|
|
|
list(APPEND B2_OPTIONS threadapi=pthread)
|
|
|
|
endif()
|
|
|
|
|
2018-10-23 00:29:54 +08:00
|
|
|
# Properly handle compiler and linker flags passed by VCPKG
|
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
|
|
set(CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
|
|
|
|
set(CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}")
|
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
|
|
|
|
else()
|
|
|
|
set(LDFLAGS "${CMAKE_STATIC_LINKER_FLAGS} ${CMAKE_STATIC_LINKER_FLAGS_RELEASE}")
|
|
|
|
endif()
|
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
|
|
set(CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
|
|
|
|
set(CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}")
|
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
|
|
|
|
else()
|
|
|
|
set(LDFLAGS "${CMAKE_STATIC_LINKER_FLAGS} ${CMAKE_STATIC_LINKER_FLAGS_DEBUG}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2021-07-07 05:05:13 +08:00
|
|
|
if(APPLE)
|
|
|
|
if(CMAKE_OSX_DEPLOYMENT_TARGET)
|
|
|
|
set(CXXFLAGS "-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET} ${CXXFLAGS}")
|
|
|
|
set(CFLAGS "-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET} ${CFLAGS}")
|
|
|
|
set(LDFLAGS "-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET} ${LDFLAGS}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_OSX_SYSROOT)
|
|
|
|
set(CXXFLAGS "-isysroot ${CMAKE_OSX_SYSROOT} ${CXXFLAGS}")
|
|
|
|
set(CFLAGS "-isysroot ${CMAKE_OSX_SYSROOT} ${CFLAGS}")
|
|
|
|
set(LDFLAGS "-isysroot ${CMAKE_OSX_SYSROOT} ${LDFLAGS}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# if specific architectures are set, configure them,
|
|
|
|
# if not set, this will still default to current arch
|
|
|
|
foreach(ARCH IN LISTS CMAKE_OSX_ARCHITECTURES)
|
|
|
|
set(CXXFLAGS "-arch ${ARCH} ${CXXFLAGS}")
|
|
|
|
set(CFLAGS "-arch ${ARCH} ${CFLAGS}")
|
|
|
|
set(LDFLAGS "-arch ${ARCH} ${LDFLAGS}")
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
2018-10-23 00:29:54 +08:00
|
|
|
string(STRIP "${CXXFLAGS}" CXXFLAGS)
|
|
|
|
string(STRIP "${CFLAGS}" CFLAGS)
|
|
|
|
string(STRIP "${LDFLAGS}" LDFLAGS)
|
|
|
|
|
|
|
|
if(NOT CXXFLAGS STREQUAL "")
|
|
|
|
string(REPLACE " " " <cxxflags>" CXXFLAGS "<cxxflags>${CXXFLAGS}")
|
|
|
|
endif()
|
|
|
|
if(NOT CFLAGS STREQUAL "")
|
|
|
|
string(REPLACE " " " <cflags>" CFLAGS "<cflags>${CFLAGS}")
|
|
|
|
endif()
|
2020-11-07 05:30:37 +08:00
|
|
|
if(NOT LDFLAGS STREQUAL "")
|
2018-10-23 00:29:54 +08:00
|
|
|
string(REPLACE " " " <linkflags>" LDFLAGS "<linkflags>${LDFLAGS}")
|
|
|
|
endif()
|
|
|
|
|
2020-06-06 03:28:42 +08:00
|
|
|
if(CMAKE_CXX_COMPILER_TARGET AND CMAKE_CXX_COMPILE_OPTIONS_TARGET)
|
2020-04-25 05:03:45 +08:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
2021-09-22 06:07:46 +08:00
|
|
|
string(APPEND CXXFLAGS " <compileflags>${CMAKE_CXX_COMPILE_OPTIONS_TARGET}${CMAKE_CXX_COMPILER_TARGET}")
|
|
|
|
string(APPEND LDFLAGS " <linkflags>${CMAKE_CXX_COMPILE_OPTIONS_TARGET}${CMAKE_CXX_COMPILER_TARGET}")
|
2020-04-25 05:03:45 +08:00
|
|
|
else()
|
2021-09-22 06:07:46 +08:00
|
|
|
string(APPEND CXXFLAGS " <compileflags>${CMAKE_CXX_COMPILE_OPTIONS_TARGET} <compileflags>${CMAKE_CXX_COMPILER_TARGET}")
|
|
|
|
string(APPEND LDFLAGS " <linkflags>${CMAKE_CXX_COMPILE_OPTIONS_TARGET} <linkflags>${CMAKE_CXX_COMPILER_TARGET}")
|
2020-04-25 05:03:45 +08:00
|
|
|
endif()
|
2018-03-12 14:01:33 +08:00
|
|
|
endif()
|
2021-09-22 06:07:46 +08:00
|
|
|
|
2018-03-12 14:01:33 +08:00
|
|
|
if(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
|
2020-08-08 07:14:05 +08:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
2021-09-22 06:07:46 +08:00
|
|
|
string(APPEND CXXFLAGS " <compileflags>${CMAKE_CXX_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN}${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}")
|
|
|
|
string(APPEND LDFLAGS " <linkflags>${CMAKE_CXX_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN}${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}")
|
2020-08-08 07:14:05 +08:00
|
|
|
else()
|
2021-09-22 06:07:46 +08:00
|
|
|
string(APPEND CXXFLAGS " <compileflags>${CMAKE_CXX_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN} <compileflags>${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}")
|
|
|
|
string(APPEND LDFLAGS " <linkflags>${CMAKE_CXX_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN} <linkflags>${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}")
|
2020-08-08 07:14:05 +08:00
|
|
|
endif()
|
2018-03-12 14:01:33 +08:00
|
|
|
endif()
|
2021-09-22 06:07:46 +08:00
|
|
|
|
2018-03-12 14:01:33 +08:00
|
|
|
if(CMAKE_SYSROOT AND CMAKE_CXX_COMPILE_OPTIONS_SYSROOT)
|
2021-09-22 06:07:46 +08:00
|
|
|
string(APPEND CXXFLAGS " <compileflags>${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT}")
|
|
|
|
string(APPEND LDFLAGS " <linkflags>${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT}")
|
2018-03-12 14:01:33 +08:00
|
|
|
endif()
|
2021-09-22 06:07:46 +08:00
|
|
|
foreach(INCDIR IN LISTS CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES)
|
|
|
|
string(APPEND CXXFLAGS " <compileflags>${CMAKE_INCLUDE_FLAG_C}${CMAKE_INCLUDE_FLAG_C_SEP}${INCDIR}")
|
2018-03-12 14:01:33 +08:00
|
|
|
endforeach()
|
|
|
|
|
2018-04-18 07:26:01 +08:00
|
|
|
if(APPLE)
|
2021-09-22 06:07:46 +08:00
|
|
|
string(APPEND CXXFLAGS " <compileflags>-D_DARWIN_C_SOURCE <cxxflags>-std=c++11 <cxxflags>-stdlib=libc++")
|
|
|
|
string(APPEND LDFLAGS " <linkflags>-stdlib=libc++")
|
2018-04-18 07:26:01 +08:00
|
|
|
endif()
|
|
|
|
|
2021-09-22 06:07:46 +08:00
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
|
|
|
|
# cl in b2 appears to not receive `LIBPATH` for finding winmd files, so we transform them to `/AI` options.
|
|
|
|
set(libpath_args "$ENV{LIBPATH}")
|
|
|
|
# Apply: {x -> /AI"x"}
|
|
|
|
list(TRANSFORM libpath_args PREPEND "/AI\"")
|
|
|
|
list(TRANSFORM libpath_args APPEND "\"")
|
|
|
|
# Apply: {\ -> \\}
|
|
|
|
list(TRANSFORM libpath_args REPLACE "\\\\" "\\\\\\\\")
|
|
|
|
# Apply: {" -> \"}
|
|
|
|
list(TRANSFORM libpath_args REPLACE "\\\"" "\\\\\"")
|
|
|
|
list(JOIN libpath_args " " libpath_arg)
|
|
|
|
|
2021-09-28 08:12:39 +08:00
|
|
|
string(APPEND CXXFLAGS " <compileflags>\"${libpath_arg}\" <cxxflags>/ZW <compileflags>\"/D_WIN32_WINNT=0x0A00\"")
|
|
|
|
string(APPEND CFLAGS " <cflags>-Zl")
|
2021-09-22 06:07:46 +08:00
|
|
|
list(APPEND B2_OPTIONS windows-api=store)
|
2021-09-28 08:12:39 +08:00
|
|
|
list(APPEND B2_OPTIONS linkflags=WindowsApp.lib)
|
2021-09-22 06:07:46 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
|
|
list(APPEND B2_OPTIONS variant=release)
|
|
|
|
else()
|
|
|
|
list(APPEND B2_OPTIONS variant=debug)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT WIN32)
|
|
|
|
list(APPEND B2_OPTIONS "--layout=system")
|
2018-03-12 14:01:33 +08:00
|
|
|
endif()
|
|
|
|
|
2021-09-28 08:12:39 +08:00
|
|
|
# Include port specific CMake fragment
|
|
|
|
if(DEFINED BOOST_CMAKE_FRAGMENT)
|
|
|
|
message(STATUS "Including ${BOOST_CMAKE_FRAGMENT}")
|
|
|
|
include(${BOOST_CMAKE_FRAGMENT})
|
|
|
|
endif()
|
|
|
|
|
2018-03-12 14:01:33 +08:00
|
|
|
configure_file(${CMAKE_CURRENT_LIST_DIR}/user-config.jam ${CMAKE_CURRENT_BINARY_DIR}/user-config.jam @ONLY)
|
|
|
|
|
2020-03-03 02:41:27 +08:00
|
|
|
include(ProcessorCount)
|
|
|
|
ProcessorCount(NUMBER_OF_PROCESSORS)
|
2018-03-12 14:01:33 +08:00
|
|
|
if(NOT NUMBER_OF_PROCESSORS)
|
|
|
|
set(NUMBER_OF_PROCESSORS 1)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_custom_target(boost ALL
|
|
|
|
COMMAND "${B2_EXE}"
|
2021-07-07 05:05:13 +08:00
|
|
|
toolset=${B2_TOOLSET}
|
2018-03-12 14:01:33 +08:00
|
|
|
--user-config=${CMAKE_CURRENT_BINARY_DIR}/user-config.jam
|
|
|
|
--stagedir=${CMAKE_CURRENT_BINARY_DIR}/stage
|
|
|
|
--build-dir=${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
${B2_OPTIONS}
|
|
|
|
--with-atomic
|
|
|
|
--with-random
|
|
|
|
--with-date_time
|
|
|
|
--with-filesystem
|
|
|
|
--with-system
|
|
|
|
--with-thread
|
|
|
|
--with-chrono
|
|
|
|
-j${NUMBER_OF_PROCESSORS}
|
|
|
|
-sBOOST_ROOT=${BOOST_BUILD_PATH}
|
|
|
|
-sBOOST_BUILD_PATH=${BOOST_BUILD_PATH}
|
|
|
|
--debug-configuration
|
2021-09-22 06:07:46 +08:00
|
|
|
--debug-building
|
|
|
|
--debug-generators
|
2018-03-12 14:01:33 +08:00
|
|
|
--ignore-site-config
|
|
|
|
--hash
|
|
|
|
-q
|
2021-09-22 06:07:46 +08:00
|
|
|
debug-symbols=on
|
|
|
|
-d +2
|
2018-03-12 14:01:33 +08:00
|
|
|
|
|
|
|
threading=multi
|
2019-05-20 02:52:11 +08:00
|
|
|
|
|
|
|
stage
|
2018-04-18 06:18:09 +08:00
|
|
|
WORKING_DIRECTORY ${SOURCE_PATH}/build
|
2018-03-12 14:01:33 +08:00
|
|
|
)
|
|
|
|
|
2019-05-20 02:52:11 +08:00
|
|
|
set(SUBDIR ${CMAKE_CURRENT_BINARY_DIR}/stage/lib)
|
2018-03-12 14:01:33 +08:00
|
|
|
install(
|
2021-09-22 06:07:46 +08:00
|
|
|
CODE "
|
|
|
|
file(GLOB LIBS ${SUBDIR}/*.so.* ${SUBDIR}/*.so ${SUBDIR}/*.a ${SUBDIR}/*.dylib ${SUBDIR}/*.dylib.* ${SUBDIR}/*.lib)
|
|
|
|
if(LIBS)
|
|
|
|
file(INSTALL \${LIBS} DESTINATION \"\${CMAKE_INSTALL_PREFIX}/lib\")
|
|
|
|
endif()
|
|
|
|
file(GLOB DLLS ${SUBDIR}/*.dll)
|
|
|
|
if(DLLS)
|
|
|
|
file(INSTALL \${DLLS} DESTINATION \"\${CMAKE_INSTALL_PREFIX}/bin\")
|
|
|
|
endif()
|
|
|
|
"
|
2018-03-12 14:01:33 +08:00
|
|
|
)
|