xref: /aosp_15_r20/external/swiftshader/third_party/boost/CMakeLists.txt (revision 03ce13f70fcc45d86ee91b7ee4cab1936a95046e)
1# Copyright 2020 The SwiftShader Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#    http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# Boost is downloaded if necessary
16
17# From https://www.boost.org/users/download/
18set(BOOST_VER 1.78.0)
19set(BOOST_HASH_TARGZ "94ced8b72956591c4775ae2207a9763d3600b30d9d7446562c552f0a14a63be7")
20set(BOOST_HASH_ZIP   "f22143b5528e081123c3c5ed437e92f648fe69748e95fa6e2bd41484e2986cc3")
21
22string(REPLACE "." "_" BOOST_VER_FNAME ${BOOST_VER})
23set(BOOST_PARENT_DIR ${CMAKE_CURRENT_BINARY_DIR})
24set(BOOST_DIR ${BOOST_PARENT_DIR}/boost_${BOOST_VER_FNAME})
25
26function(DownloadBoost)
27    if (LINUX)
28        set(BOOST_EXT "tar.gz")
29        set(BOOST_HASH ${BOOST_HASH_TARGZ})
30    else()
31        set(BOOST_EXT "zip")
32        set(BOOST_HASH ${BOOST_HASH_ZIP})
33    endif()
34
35    # set(BOOST_URL https://dl.bintray.com/boostorg/release/${BOOST_VER}/source/boost_${BOOST_VER_FNAME}.${BOOST_EXT})  # Note: bintray.com has rate limiting
36    # set(BOOST_URL https://iweb.dl.sourceforge.net/project/boost/boost/${BOOST_VER}/boost_${BOOST_VER_FNAME}.${BOOST_EXT})  # Note: iweb.dl.sourceforge.net no longer available
37    set(BOOST_URL https://boostorg.jfrog.io/artifactory/main/release/${BOOST_VER}/source/boost_${BOOST_VER_FNAME}.${BOOST_EXT})
38
39    if (NOT TARGET Boost::boost)
40        if(NOT EXISTS ${BOOST_DIR})
41            message(WARNING "
42          ${BOOST_DIR} is missing.
43          Downloading and extracting boost:
44            ")
45
46            set(BOOST_ARCHIVE ${CMAKE_BINARY_DIR}/temp/boost_${BOOST_VER_FNAME}.${BOOST_EXT})
47            message(STATUS "Downloading ${BOOST_URL} to ${BOOST_ARCHIVE}...")
48            file(DOWNLOAD ${BOOST_URL} ${BOOST_ARCHIVE} EXPECTED_HASH SHA256=${BOOST_HASH})
49            message(STATUS "Extracting ${BOOST_ARCHIVE} to ${BOOST_DIR}...")
50            execute_process(
51                WORKING_DIRECTORY ${BOOST_PARENT_DIR}
52                COMMAND cmake -E tar xf ${BOOST_ARCHIVE}
53            )
54        endif()
55    endif()
56endfunction()
57
58DownloadBoost()
59
60set(BOOST_INCLUDEDIR ${BOOST_DIR})
61find_package(Boost REQUIRED)
62
63# Expose Boost::boost target for parent project
64add_library(boost INTERFACE)
65target_link_libraries(boost INTERFACE
66    Boost::boost
67)
68add_library(Boost::boost ALIAS boost)
69