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.70.0) 19set(BOOST_HASH_TARGZ "882b48708d211a5f48e60b0124cf5863c1534cd544ecd0664bb534a4b5d506e9") 20set(BOOST_HASH_ZIP "48f379b2e90dd1084429aae87d6bdbde9670139fa7569ee856c8c86dd366039d") 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 # Note: bintray.com has rate limiting, so use the sourceforge mirror 36 # set(BOOST_URL https://dl.bintray.com/boostorg/release/${BOOST_VER}/source/boost_${BOOST_VER_FNAME}.${BOOST_EXT}) 37 set(BOOST_URL https://iweb.dl.sourceforge.net/project/boost/boost/${BOOST_VER}/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_archive) 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