Skip to content

Commit 8797ece

Browse files
committed
Use FetchContent to download Boost sources
FetchContent can be overriden in the parent project with a lot more options. Should be more robust overall than my custom download method.
1 parent 14e68fb commit 8797ece

File tree

3 files changed

+23
-120
lines changed

3 files changed

+23
-120
lines changed

CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
cmake_minimum_required(VERSION 3.12)
22
project(Boost-CMake)
33

4-
option(BOOST_DOWNLOAD_TO_BINARY_DIR "Prefer downloading Boost to the binary directory instead of source directory" OFF)
54
option(BOOST_DISABLE_TESTS "Do not build test targets, even if building standalone" OFF)
65

76
set(BOOST_URL "https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.bz2" CACHE STRING "Boost download URL")
87
set(BOOST_URL_SHA256 "8f32d4617390d1c2d16f26a27ab60d97807b35440d45891fa340fc2648b04406" CACHE STRING "Boost download URL SHA256 checksum")
9-
set(BOOST_ARCHIVE_DIRECTORY "" CACHE DIRECTORY "Use the specified local directory to search for boost archives instead of downloading them" )
108

11-
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
9+
include(FetchContent)
10+
FetchContent_Declare(
11+
Boost
12+
URL ${BOOST_URL}
13+
URL_HASH SHA256=${BOOST_URL_SHA256}
14+
)
15+
FetchContent_GetProperties(Boost)
1216

13-
include(DownloadBoost)
17+
if(NOT Boost_POPULATED)
18+
FetchContent_Populate(Boost)
19+
set(BOOST_SOURCE ${boost_SOURCE_DIR})
20+
endif()
21+
22+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
23+
include(CheckBoostVersion)
1424

1525
message(STATUS "Boost found: ${BOOST_VERSION} ${BOOST_SOURCE}")
1626

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Detect Boost version
2+
file(STRINGS "${BOOST_SOURCE}/boost/version.hpp" boost_version_raw
3+
REGEX "define BOOST_VERSION "
4+
)
5+
string(REGEX MATCH "[0-9]+" boost_version_raw "${boost_version_raw}")
6+
math(EXPR BOOST_VERSION_MAJOR "${boost_version_raw} / 100000")
7+
math(EXPR BOOST_VERSION_MINOR "${boost_version_raw} / 100 % 1000")
8+
math(EXPR BOOST_VERSION_PATCH "${boost_version_raw} % 100")
9+
set(BOOST_VERSION "${BOOST_VERSION_MAJOR}.${BOOST_VERSION_MINOR}.${BOOST_VERSION_PATCH}")

cmake/Modules/DownloadBoost.cmake

Lines changed: 0 additions & 116 deletions
This file was deleted.

0 commit comments

Comments
 (0)