290 lines
11 KiB
CMake
290 lines
11 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(TARGET SQLite3::SQLite3)
|
|
return()
|
|
endif()
|
|
if(TARGET SQLite::SQLite3)
|
|
add_library(SQLite3::SQLite3 ALIAS SQLite::SQLite3)
|
|
return()
|
|
endif()
|
|
|
|
set(_void_sqlite_dir "${VOID_SQLITE3_AMALGAMATION_DIR}")
|
|
if(NOT _void_sqlite_dir)
|
|
find_package(SQLite3 QUIET)
|
|
if(TARGET SQLite3::SQLite3)
|
|
return()
|
|
endif()
|
|
if(TARGET SQLite::SQLite3)
|
|
add_library(SQLite3::SQLite3 ALIAS SQLite::SQLite3)
|
|
return()
|
|
endif()
|
|
endif()
|
|
|
|
option(VOID_FETCH_SQLITE3
|
|
"Allow FetchContent SQLite3 amalgamation fallback when system SQLite3 is unavailable"
|
|
ON)
|
|
set(VOID_SQLITE3_AMALGAMATION_DIR "" CACHE PATH
|
|
"Path containing pre-downloaded sqlite3.c and sqlite3.h amalgamation sources")
|
|
set(VOID_SQLITE3_FETCH_URL
|
|
"https://www.sqlite.org/2025/sqlite-amalgamation-3490100.zip"
|
|
CACHE STRING "SQLite3 amalgamation archive URL for FetchContent fallback")
|
|
set(VOID_SQLITE3_FETCH_HASH "" CACHE STRING
|
|
"Optional SHA256 hash (SHA256=...) for VOID_SQLITE3_FETCH_URL")
|
|
|
|
if(NOT _void_sqlite_dir AND VOID_FETCH_SQLITE3 AND
|
|
NOT CMAKE_DISABLE_FIND_PACKAGE_SQLite3)
|
|
message(STATUS "[Void] System SQLite3 not found — falling back to SQLite3 amalgamation")
|
|
if(VOID_SQLITE3_FETCH_HASH)
|
|
FetchContent_Declare(SQLite3
|
|
URL "${VOID_SQLITE3_FETCH_URL}"
|
|
URL_HASH "${VOID_SQLITE3_FETCH_HASH}"
|
|
SYSTEM
|
|
)
|
|
else()
|
|
FetchContent_Declare(SQLite3
|
|
URL "${VOID_SQLITE3_FETCH_URL}"
|
|
SYSTEM
|
|
)
|
|
endif()
|
|
FetchContent_MakeAvailable(SQLite3)
|
|
if(EXISTS "${sqlite3_SOURCE_DIR}/sqlite3.c")
|
|
set(_void_sqlite_dir "${sqlite3_SOURCE_DIR}")
|
|
else()
|
|
file(GLOB _found_sqlite_c LIST_DIRECTORIES FALSE
|
|
"${sqlite3_SOURCE_DIR}/*/sqlite3.c")
|
|
if(_found_sqlite_c)
|
|
list(GET _found_sqlite_c 0 _first_sqlite_c)
|
|
get_filename_component(_void_sqlite_dir "${_first_sqlite_c}" DIRECTORY)
|
|
endif()
|
|
endif()
|
|
endif()
|
|
|
|
if(_void_sqlite_dir AND EXISTS "${_void_sqlite_dir}/sqlite3.c" AND
|
|
EXISTS "${_void_sqlite_dir}/sqlite3.h")
|
|
void_fetch_dependency(Threads)
|
|
add_library(void_sqlite3_amalgamation STATIC
|
|
"${_void_sqlite_dir}/sqlite3.c")
|
|
set_target_properties(void_sqlite3_amalgamation PROPERTIES
|
|
POSITION_INDEPENDENT_CODE ON
|
|
C_STANDARD 11
|
|
SYSTEM TRUE)
|
|
target_include_directories(void_sqlite3_amalgamation SYSTEM PUBLIC
|
|
"${_void_sqlite_dir}")
|
|
target_compile_definitions(void_sqlite3_amalgamation PRIVATE
|
|
SQLITE_THREADSAFE=1
|
|
SQLITE_ENABLE_FTS5
|
|
SQLITE_ENABLE_JSON1
|
|
SQLITE_DQS=0)
|
|
target_link_libraries(void_sqlite3_amalgamation PUBLIC
|
|
Threads::Threads
|
|
"$<$<NOT:$<PLATFORM_ID:Windows>>:${CMAKE_DL_LIBS};m>")
|
|
add_library(SQLite3::SQLite3 ALIAS void_sqlite3_amalgamation)
|
|
return()
|
|
endif()
|
|
|
|
find_package(SQLite3 REQUIRED)
|
|
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()
|