Compare commits

...

1 Commits

Author SHA1 Message Date
ReenigneArcher
5f390d2ea0 build(deps): use pre-compiled boost 2025-08-05 18:52:10 -04:00
9 changed files with 1479 additions and 90 deletions

View File

@@ -47,6 +47,10 @@ if(${END_BUILD})
return()
endif()
# CPM
include(${CMAKE_MODULE_PATH}/cpm/CPM.cmake)
CPMUsePackageLock(package-lock.cmake)
# project constants
include(${CMAKE_MODULE_PATH}/prep/constants.cmake)

View File

@@ -13,7 +13,7 @@ foreach(dir ${MACOS_LINK_DIRECTORIES})
endif()
endforeach()
if(NOT BOOST_USE_STATIC AND NOT FETCH_CONTENT_BOOST_USED)
if(NOT BOOST_USE_STATIC AND NOT CPM_BOOST_USED)
ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)
endif()

View File

1363
cmake/cpm/CPM.cmake Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,102 +1,101 @@
#
# Loads the boost library giving the priority to the system package first, with a fallback to FetchContent.
# Loads the boost library giving the following priority
# - LizardByte pre-built
# - System package
# - CPM/FetchContent
#
include_guard(GLOBAL)
set(BOOST_VERSION "1.87.0")
set(BOOST_COMPONENTS
filesystem
locale
log
program_options
system
)
# system is not used by Sunshine, but by Simple-Web-Server, added here for convenience
# algorithm, preprocessor, scope, and uuid are not used by Sunshine, but by libdisplaydevice, added here for convenience
if(WIN32)
list(APPEND BOOST_COMPONENTS
algorithm
preprocessor
scope
uuid
)
endif()
if(BOOST_USE_STATIC)
set(Boost_USE_STATIC_LIBS ON) # cmake-lint: disable=C0103
set(BOOST_PREPARED_BINARIES
"${CMAKE_SOURCE_DIR}/third-party/build-deps/dist/${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
# check if the directory exists
if(EXISTS "${BOOST_PREPARED_BINARIES}")
set(Boost_FOUND TRUE) # cmake-lint: disable=C0103
set(Boost_INCLUDE_DIRS # cmake-lint: disable=C0103
"$<BUILD_INTERFACE:${BOOST_PREPARED_BINARIES}/include/boost>")
file(GLOB Boost_LIBRARIES "${BOOST_PREPARED_BINARIES}/lib/libboost_*.a")
set(PREPARED_BOOST_USED TRUE)
# Create Boost::headers target
add_library(Boost::headers INTERFACE IMPORTED)
set_target_properties(Boost::headers PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${BOOST_PREPARED_BINARIES}/include/boost"
)
else()
message(WARNING
"Boost pre-compiled binaries not found at ${BOOST_PREPARED_BINARIES}. \
Please consider contributing to the LizardByte/build-deps repository.")
endif()
endif()
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.30")
cmake_policy(SET CMP0167 NEW) # Get BoostConfig.cmake from upstream
endif()
find_package(Boost CONFIG ${BOOST_VERSION} EXACT COMPONENTS ${BOOST_COMPONENTS})
if(NOT Boost_FOUND)
message(STATUS "Boost v${BOOST_VERSION} package not found in the system. Falling back to FetchContent.")
include(FetchContent)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW) # Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24
endif()
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.31.0")
cmake_policy(SET CMP0174 NEW) # Handle empty variables
endif()
# more components required for compiling boost targets
list(APPEND BOOST_COMPONENTS
asio
crc
format
process
property_tree)
set(BOOST_ENABLE_CMAKE ON)
# Limit boost to the required libraries only
set(BOOST_INCLUDE_LIBRARIES ${BOOST_COMPONENTS})
set(BOOST_URL "https://github.com/boostorg/boost/releases/download/boost-${BOOST_VERSION}/boost-${BOOST_VERSION}-cmake.tar.xz") # cmake-lint: disable=C0301
set(BOOST_HASH "SHA256=7da75f171837577a52bbf217e17f8ea576c7c246e4594d617bfde7fafd408be5")
if(CMAKE_VERSION VERSION_LESS "3.24.0")
FetchContent_Declare(
Boost
URL ${BOOST_URL}
URL_HASH ${BOOST_HASH}
)
elseif(APPLE AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.25.0")
# add SYSTEM to FetchContent_Declare, this fails on debian bookworm
FetchContent_Declare(
Boost
URL ${BOOST_URL}
URL_HASH ${BOOST_HASH}
SYSTEM # requires CMake 3.25+
OVERRIDE_FIND_PACKAGE # requires CMake 3.24+, but we have a macro to handle it for other versions
)
elseif(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
FetchContent_Declare(
Boost
URL ${BOOST_URL}
URL_HASH ${BOOST_HASH}
OVERRIDE_FIND_PACKAGE # requires CMake 3.24+, but we have a macro to handle it for other versions
)
endif()
FetchContent_MakeAvailable(Boost)
set(FETCH_CONTENT_BOOST_USED TRUE)
set(Boost_FOUND TRUE) # cmake-lint: disable=C0103
set(Boost_INCLUDE_DIRS # cmake-lint: disable=C0103
"$<BUILD_INTERFACE:${Boost_SOURCE_DIR}/libs/headers/include>")
set(BOOST_COMPONENTS
filesystem
locale
log
program_options
system
)
# system is not used by Sunshine, but by Simple-Web-Server, added here for convenience
# algorithm, preprocessor, scope, and uuid are not used by Sunshine,
# but by libdisplaydevice, added here for convenience
if(WIN32)
# Windows build is failing to create .h file in this directory
file(MAKE_DIRECTORY ${Boost_BINARY_DIR}/libs/log/src/windows)
list(APPEND BOOST_COMPONENTS
algorithm
preprocessor
scope
uuid
)
endif()
set(Boost_LIBRARIES "") # cmake-lint: disable=C0103
foreach(component ${BOOST_COMPONENTS})
list(APPEND Boost_LIBRARIES "Boost::${component}")
endforeach()
if(BOOST_USE_STATIC)
set(Boost_USE_STATIC_LIBS ON) # cmake-lint: disable=C0103
endif()
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.30")
cmake_policy(SET CMP0167 NEW) # Get BoostConfig.cmake from upstream
endif()
find_package(Boost CONFIG ${BOOST_VERSION} EXACT COMPONENTS ${BOOST_COMPONENTS})
if(NOT Boost_FOUND)
message(STATUS "Boost v${BOOST_VERSION} package not found in the system. Falling back to CPM.")
CPMGetPackage(Boost)
# more components required for compiling boost targets
list(APPEND BOOST_COMPONENTS
asio
crc
format
process
property_tree)
set(BOOST_ENABLE_CMAKE ON) # Use experimental superproject to pull library dependencies recursively
set(BOOST_INCLUDE_LIBRARIES ${BOOST_COMPONENTS}) # Limit boost to the required libraries only
set(BOOST_SKIP_INSTALL_RULES ON) # do not install Boost libraries or headers
set(CPM_BOOST_USED TRUE)
set(Boost_FOUND TRUE) # cmake-lint: disable=C0103
set(Boost_INCLUDE_DIRS # cmake-lint: disable=C0103
"$<BUILD_INTERFACE:${Boost_SOURCE_DIR}/libs/headers/include>")
message(STATUS "Boost_BINARY_DIR: ${Boost_BINARY_DIR}")
message(STATUS "Boost_SOURCE_DIR: ${Boost_SOURCE_DIR}")
if(WIN32)
# Windows build is failing to create .h file in this directory
file(MAKE_DIRECTORY ${Boost_BINARY_DIR}/libs/log/src/windows)
endif()
add_subdirectory(${Boost_SOURCE_DIR} ${Boost_BINARY_DIR} SYSTEM)
set(Boost_LIBRARIES "") # cmake-lint: disable=C0103
foreach(component ${BOOST_COMPONENTS})
list(APPEND Boost_LIBRARIES "Boost::${component}")
endforeach()
endif()
endif()
message(STATUS "Boost include dirs: ${Boost_INCLUDE_DIRS}")

View File

@@ -18,7 +18,7 @@ endif()
macro(find_package) # cmake-lint: disable=C0103
string(TOLOWER "${ARGV0}" ARGV0_LOWER)
if(
(("${ARGV0_LOWER}" STREQUAL "boost") AND DEFINED FETCH_CONTENT_BOOST_USED) OR
(("${ARGV0_LOWER}" STREQUAL "boost") AND (DEFINED CPM_BOOST_USED OR DEFINED PREPARED_BOOST_USED)) OR
(("${ARGV0_LOWER}" STREQUAL "libevdev") AND DEFINED EXTERNAL_PROJECT_LIBEVDEV_USED)
)
# Do nothing, as the package has already been fetched

View File

@@ -20,6 +20,9 @@ option(SUNSHINE_ENABLE_TRAY "Enable system tray icon. This option will be ignore
option(SUNSHINE_SYSTEM_WAYLAND_PROTOCOLS "Use system installation of wayland-protocols rather than the submodule." OFF)
option(CPM_USE_LOCAL_PACKAGES "Try to use local packages instead of downloading them." OFF)
option(CPM_LOCAL_PACKAGES_ONLY "Only use local packages, do not download them." OFF)
if(APPLE)
option(BOOST_USE_STATIC "Use static boost libraries." OFF)
else()

20
package-lock.cmake Normal file
View File

@@ -0,0 +1,20 @@
# CPM Package Lock
# This file should be committed to version control
# The first argument of CPMDeclarePackage can be freely chosen and is used as argument in CPMGetPackage.
# The NAME argument should be package name that would also be used in a find_package call.
# Ideally, both are the same, which might not always be possible: https://github.com/cpm-cmake/CPM.cmake/issues/603
# This is needed to support CPM_USE_LOCAL_PACKAGES
# TODO: update dependencies with renovate
# https://joht.github.io/johtizen/automation/2022/08/03/keep-your-cpp-dependencies-up-to-date.html
# Boost
set(BOOST_VERSION 1.87.0)
CPMDeclarePackage(Boost
NAME Boost
VERSION ${BOOST_VERSION}
URL https://github.com/boostorg/boost/releases/download/boost-${BOOST_VERSION}/boost-${BOOST_VERSION}-cmake.tar.xz
URL_HASH SHA256=7da75f171837577a52bbf217e17f8ea576c7c246e4594d617bfde7fafd408be5
DOWNLOAD_ONLY YES # boost is a bit complicated so we handle it separately
)