210 lines
8.0 KiB
CMake
210 lines
8.0 KiB
CMake
include(FetchContent)
|
|
|
|
function(void_ensure_boost_header_targets)
|
|
if(NOT TARGET Boost::headers AND TARGET Boost::boost)
|
|
add_library(Boost::headers INTERFACE IMPORTED)
|
|
set_property(TARGET Boost::headers PROPERTY
|
|
INTERFACE_LINK_LIBRARIES Boost::boost)
|
|
endif()
|
|
foreach(_component IN ITEMS beast asio)
|
|
if(NOT TARGET Boost::${_component} AND
|
|
TARGET boost_${_component})
|
|
add_library(Boost::${_component} ALIAS boost_${_component})
|
|
elseif(NOT TARGET Boost::${_component} AND TARGET Boost::headers)
|
|
# System Boost packages commonly expose one aggregate include
|
|
# target rather than per-header-library targets.
|
|
add_library(Boost::${_component} INTERFACE IMPORTED)
|
|
set_property(TARGET Boost::${_component} PROPERTY
|
|
INTERFACE_LINK_LIBRARIES Boost::headers)
|
|
endif()
|
|
endforeach()
|
|
endfunction()
|
|
|
|
function(void_install_fetched_boost_runtime)
|
|
get_property(_runtime_registered GLOBAL
|
|
PROPERTY VOID_FETCHED_BOOST_RUNTIME_REGISTERED)
|
|
if(_runtime_registered)
|
|
return()
|
|
endif()
|
|
set_property(GLOBAL PROPERTY VOID_FETCHED_BOOST_RUNTIME_REGISTERED TRUE)
|
|
|
|
# Boost disables its install rules when consumed through add_subdirectory.
|
|
# Register the selected shared runtime closure explicitly so an installed
|
|
# shared Void package never points back into its build tree.
|
|
foreach(_target IN ITEMS
|
|
boost_container
|
|
boost_context
|
|
boost_coroutine
|
|
boost_date_time
|
|
boost_stacktrace_addr2line
|
|
boost_stacktrace_windbg
|
|
boost_url)
|
|
if(TARGET ${_target})
|
|
get_target_property(_type ${_target} TYPE)
|
|
if(_type STREQUAL "SHARED_LIBRARY" OR
|
|
_type STREQUAL "MODULE_LIBRARY")
|
|
if(UNIX)
|
|
set_property(TARGET ${_target} PROPERTY
|
|
INSTALL_RPATH "$ORIGIN")
|
|
endif()
|
|
install(TARGETS ${_target}
|
|
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
|
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
|
|
endif()
|
|
endif()
|
|
endforeach()
|
|
endfunction()
|
|
|
|
function(void_fetch_dependency DEP_NAME)
|
|
if(DEP_NAME STREQUAL "Boost")
|
|
if(WIN32 AND NOT CYGWIN)
|
|
set(_stacktrace_component stacktrace_windbg)
|
|
else()
|
|
set(_stacktrace_component stacktrace_addr2line)
|
|
endif()
|
|
|
|
# Components Void uses across modules: a platform Stacktrace backend,
|
|
# plus url, beast, and asio (Net).
|
|
if(TARGET Boost::${_stacktrace_component} AND TARGET Boost::url)
|
|
void_ensure_boost_header_targets()
|
|
return()
|
|
endif()
|
|
|
|
# Probe in a child directory because a failed component-aware
|
|
# find_package(Boost) can still leave partial imported targets such as
|
|
# Boost::headers in its directory scope. Those partial targets collide
|
|
# with Boost's FetchContent build. Imported targets created by this
|
|
# probe stay in the child scope; only a boolean result is exported.
|
|
get_property(_boost_probe_ran GLOBAL
|
|
PROPERTY VOID_COMPLETE_SYSTEM_BOOST SET)
|
|
if(NOT _boost_probe_ran)
|
|
set_property(GLOBAL PROPERTY VOID_COMPLETE_SYSTEM_BOOST FALSE)
|
|
add_subdirectory(
|
|
"${CMAKE_CURRENT_FUNCTION_LIST_DIR}/BoostProbe"
|
|
"${PROJECT_BINARY_DIR}/void-boost-probe"
|
|
EXCLUDE_FROM_ALL)
|
|
endif()
|
|
get_property(_complete_system_boost GLOBAL
|
|
PROPERTY VOID_COMPLETE_SYSTEM_BOOST)
|
|
if(_complete_system_boost)
|
|
# On modern Boost, beast/asio are header-only and folded into
|
|
# Boost::headers. The fetched Asio target carries its own System
|
|
# dependency; requiring a separate system component here rejects
|
|
# otherwise complete distro packages where Boost.System is folded
|
|
# into Boost::headers.
|
|
find_package(Boost CONFIG REQUIRED
|
|
COMPONENTS ${_stacktrace_component} url)
|
|
void_ensure_boost_header_targets()
|
|
return()
|
|
endif()
|
|
|
|
if(TARGET Boost::headers OR TARGET Boost::boost)
|
|
message(FATAL_ERROR
|
|
"[Void] Incomplete Boost targets already exist in the parent "
|
|
"project. Provide ${_stacktrace_component} and url before "
|
|
"adding Void, or let Void resolve Boost first.")
|
|
endif()
|
|
|
|
message(STATUS "[Void] Boost (stacktrace/url) not found — falling back to FetchContent")
|
|
# Keep Boost's selection local to this dependency resolution. Avoid
|
|
# overwriting a parent project's cache when Void is embedded.
|
|
set(BOOST_INCLUDE_LIBRARIES "stacktrace;url;system;beast;asio")
|
|
FetchContent_Declare(Boost
|
|
URL https://github.com/boostorg/boost/releases/download/boost-1.84.0/boost-1.84.0.tar.xz
|
|
URL_HASH SHA256=2e64e5d79a738d0fa6fb546c6e5c2bd28f88d268a2a080546f74e5ff98f29d0e
|
|
SYSTEM
|
|
)
|
|
FetchContent_MakeAvailable(Boost)
|
|
|
|
foreach(_boost_target IN ITEMS
|
|
boost_headers
|
|
boost_beast
|
|
boost_asio
|
|
boost_url
|
|
boost_system
|
|
boost_stacktrace_addr2line
|
|
boost_stacktrace_windbg
|
|
boost_intrusive
|
|
boost_core
|
|
boost_mp11)
|
|
if(TARGET ${_boost_target})
|
|
set_property(TARGET ${_boost_target} PROPERTY SYSTEM TRUE)
|
|
endif()
|
|
endforeach()
|
|
|
|
if(NOT TARGET Boost::${_stacktrace_component} AND
|
|
TARGET boost_${_stacktrace_component})
|
|
add_library(Boost::${_stacktrace_component}
|
|
ALIAS boost_${_stacktrace_component})
|
|
endif()
|
|
void_ensure_boost_header_targets()
|
|
void_install_fetched_boost_runtime()
|
|
return()
|
|
endif()
|
|
|
|
if(DEP_NAME STREQUAL "OpenSSL")
|
|
if(NOT TARGET OpenSSL::SSL)
|
|
find_package(OpenSSL REQUIRED)
|
|
endif()
|
|
return()
|
|
endif()
|
|
|
|
if(DEP_NAME STREQUAL "Threads")
|
|
if(NOT TARGET Threads::Threads)
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
find_package(Threads REQUIRED)
|
|
endif()
|
|
return()
|
|
endif()
|
|
|
|
if(DEP_NAME STREQUAL "SQLite3")
|
|
if(NOT TARGET SQLite3::SQLite3 AND NOT TARGET SQLite::SQLite3)
|
|
find_package(SQLite3 REQUIRED)
|
|
endif()
|
|
if(NOT TARGET SQLite3::SQLite3 AND TARGET SQLite::SQLite3)
|
|
add_library(SQLite3::SQLite3 ALIAS SQLite::SQLite3)
|
|
endif()
|
|
return()
|
|
endif()
|
|
|
|
if(DEP_NAME STREQUAL "Sodium")
|
|
if(TARGET Sodium::Sodium)
|
|
return()
|
|
endif()
|
|
find_package(PkgConfig REQUIRED)
|
|
pkg_check_modules(SODIUM REQUIRED IMPORTED_TARGET libsodium)
|
|
add_library(Sodium::Sodium INTERFACE IMPORTED)
|
|
set_property(TARGET Sodium::Sodium PROPERTY
|
|
INTERFACE_LINK_LIBRARIES PkgConfig::SODIUM)
|
|
return()
|
|
endif()
|
|
|
|
if(DEP_NAME STREQUAL "LibArchive")
|
|
if(NOT TARGET LibArchive::LibArchive)
|
|
find_package(LibArchive REQUIRED)
|
|
endif()
|
|
return()
|
|
endif()
|
|
# FIXME: Add if needed external
|
|
# if(DEP_NAME STREQUAL "glaze")
|
|
# if(NOT glaze_POPULATED)
|
|
# message(STATUS "[MyLib] Fetching Glaze on-demand...")
|
|
# FetchContent_Declare(glaze
|
|
# GIT_REPOSITORY https://github.com/stephenberry/glaze.git
|
|
# GIT_TAG v2.8.5
|
|
# )
|
|
# FetchContent_MakeAvailable(glaze)
|
|
# endif()
|
|
#
|
|
# elseif(DEP_NAME STREQUAL "fmt")
|
|
# if(NOT fmt_POPULATED)
|
|
# message(STATUS "[MyLib] Fetching fmt on-demand...")
|
|
# FetchContent_Declare(fmt
|
|
# GIT_REPOSITORY https://github.com/fmtlib/fmt.git
|
|
# GIT_TAG 10.2.1
|
|
# )
|
|
# FetchContent_MakeAvailable(fmt)
|
|
# endif()
|
|
# endif()
|
|
endfunction()
|