forked from bringauto/boost-cmake-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
89 lines (71 loc) · 2.61 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#
# CMake Boost Build.
#
# Cmd line options:
# CMAKE_BUILD_TYPE in { Debug, Release }
# BOOST_VERSION - valid boost version (Example: 1.76.0)
#
#
PROJECT(CMAKE_BOOST CXX)
CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
IF(NOT BOOST_VERSION)
MESSAGE(FATAL_ERROR "Boost version veraible BOOST_VERSION not specified!!")
ENDIF()
IF(NOT CMAKE_BUILD_TYPE)
MESSAGE(FATAL_ERROR "Please set CMAKE_BUILD_TYPE!!")
ENDIF()
IF(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" AND
NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Release")
MESSAGE(FATAL_ERROR "Unsupported build type: ${CMAKE_BUILD_TYPE}")
ENDIF()
STRING(REGEX MATCH "^[0-9]\.[0-9]+\.[0-9]+$" version_ok "${BOOST_VERSION}")
IF(NOT version_ok)
MESSAGE(FATAL_ERROR "Boost version ${BOOST_VERSION} is not valid!")
ENDIF()
STRING(REPLACE "\." "_" BOOST_VERSION_UNDERSCORE "${BOOST_VERSION}")
SET(BOOST_DOWNLOAD_URL "https://boostorg.jfrog.io/artifactory/main/release/${BOOST_VERSION}/source/boost_${BOOST_VERSION_UNDERSCORE}.tar.gz")
SET(BOOST_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/boost_install")
SET(BOOST_BUILD_OPTIONS "cxxflags=-fPIC" "cflags=-fPIC")
SET(archive_path ${CMAKE_CURRENT_BINARY_DIR}/boost_${BOOST_VERSION_UNDERSCORE}.tar.gz)
SET(extracted_archive_path ${CMAKE_CURRENT_BINARY_DIR}/boost_${BOOST_VERSION_UNDERSCORE}_${CMAKE_BUILD_TYPE})
IF(NOT EXISTS "${archive_path}")
FILE(DOWNLOAD "${BOOST_DOWNLOAD_URL}" "${archive_path}" SHOW_PROGRESS)
ENDIF()
FILE(MAKE_DIRECTORY "${extracted_archive_path}")
EXECUTE_PROCESS(
COMMAND ${CMAKE_COMMAND} -E tar xjf ${archive_path}
WORKING_DIRECTORY ${extracted_archive_path}
)
SET(boost_sources "${extracted_archive_path}/boost_${BOOST_VERSION_UNDERSCORE}")
MESSAGE(STATUS ${boost_sources})
ADD_CUSTOM_COMMAND(OUTPUT "${boost_sources}/b2"
MAIN_DEPENDENCY "${boost_sources}"
COMMAND ./bootstrap.sh
WORKING_DIRECTORY "${boost_sources}"
COMMENT "Boost bootstrap"
)
ADD_CUSTOM_COMMAND(
OUTPUT "${BOOST_INSTALL_DIR}"
MAIN_DEPENDENCY "${boost_sources}"
DEPENDS "${boost_sources}/b2"
COMMAND ./b2 --prefix="${BOOST_INSTALL_DIR}"
runtime-link=shared,static
link=shared,static
variant=$<$<CONFIG:Debug>:debug>$<$<CONFIG:Release>:release>
threading=multi
${BOOST_BUILD_OPTIONS}
address-model=64 --layout=tagged
--with-headers
-j 16 install
WORKING_DIRECTORY "${boost_sources}"
COMMENT "Build Boost from sources"
)
ADD_CUSTOM_TARGET(boost_build ALL
DEPENDS "${BOOST_INSTALL_DIR}"
)
INSTALL(DIRECTORY ${BOOST_INSTALL_DIR}/include/
DESTINATION "include"
)
INSTALL(DIRECTORY ${BOOST_INSTALL_DIR}/lib/
DESTINATION "lib"
)