1 parent
3851aeb703
commit
053ee5b296
23 files changed
+845
-93
No files matched your search
+73
-3
@@ -35,15 +35,42 @@ function(void_add_module MODULE_NAME)
|
||||
target_sources(${TGT} PRIVATE ${SRC})
|
||||
target_compile_features(${TGT} PUBLIC cxx_std_26)
|
||||
endif()
|
||||
get_target_property(_module_target_type ${TGT} TYPE)
|
||||
if(_module_target_type STREQUAL "SHARED_LIBRARY" OR
|
||||
_module_target_type STREQUAL "MODULE_LIBRARY")
|
||||
# External packages are implementation details of compiled shared
|
||||
# modules: Void's installed public headers do not expose their types.
|
||||
# Keeping these links private also lets a shared Void SDK carry a
|
||||
# fetched runtime dependency without requiring that dependency's CMake
|
||||
# development package on every consumer machine.
|
||||
set(_external_scope PRIVATE)
|
||||
set(_record_external_dependencies FALSE)
|
||||
else()
|
||||
set(_external_scope ${SCOPE})
|
||||
set(_record_external_dependencies TRUE)
|
||||
endif()
|
||||
add_library(${ALIAS} ALIAS ${TGT})
|
||||
|
||||
set_property(GLOBAL APPEND PROPERTY VOID_MODULES ${MODULE_NAME})
|
||||
set(_module_external_deps "")
|
||||
foreach(ext_dep IN LISTS ARG_EXTERNAL_DEPS)
|
||||
string(REGEX REPLACE "::.*" "" BASE_DEP ${ext_dep})
|
||||
list(APPEND _module_external_deps ${BASE_DEP})
|
||||
# FindSQLite3's package name and imported-target namespace differ.
|
||||
# Preserve the package name in exported dependency metadata.
|
||||
if(ext_dep MATCHES "^SQLite::")
|
||||
set(BASE_DEP SQLite3)
|
||||
else()
|
||||
string(REGEX REPLACE "::.*" "" BASE_DEP ${ext_dep})
|
||||
endif()
|
||||
if(_record_external_dependencies)
|
||||
list(APPEND _module_external_deps ${BASE_DEP})
|
||||
endif()
|
||||
include(cmake/Dependencies.cmake)
|
||||
void_fetch_dependency(${BASE_DEP})
|
||||
if(NOT TARGET ${ext_dep})
|
||||
message(FATAL_ERROR
|
||||
"[Void] Dependency '${ext_dep}' required by module "
|
||||
"'${MODULE_NAME}' was not provided")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(_module_internal_deps ${ARG_INTERNAL_DEPS} ${ARG_OPTIONAL_DEPS})
|
||||
@@ -78,7 +105,41 @@ function(void_add_module MODULE_NAME)
|
||||
endif()
|
||||
|
||||
if(ARG_EXTERNAL_DEPS)
|
||||
target_link_libraries(${TGT} ${SCOPE} ${ARG_EXTERNAL_DEPS})
|
||||
if(_external_scope STREQUAL "PRIVATE")
|
||||
foreach(_external_dep IN LISTS ARG_EXTERNAL_DEPS)
|
||||
string(MAKE_C_IDENTIFIER "${_external_dep}"
|
||||
_external_dep_identifier)
|
||||
set(_build_external_target
|
||||
"_void_${MODULE_NAME}_${_external_dep_identifier}")
|
||||
add_library(${_build_external_target} INTERFACE IMPORTED)
|
||||
set_property(TARGET ${_build_external_target} PROPERTY
|
||||
INTERFACE_LINK_LIBRARIES "${_external_dep}")
|
||||
target_link_libraries(${TGT} PRIVATE
|
||||
"$<BUILD_INTERFACE:${_build_external_target}>")
|
||||
endforeach()
|
||||
else()
|
||||
# Keep fetched dependency build targets out of Void's install
|
||||
# export. Static and interface consumers still receive the same
|
||||
# canonical targets after find_dependency().
|
||||
foreach(_external_dep IN LISTS ARG_EXTERNAL_DEPS)
|
||||
string(MAKE_C_IDENTIFIER "${_external_dep}"
|
||||
_external_dep_identifier)
|
||||
set(_build_external_target
|
||||
"_void_${MODULE_NAME}_${_external_dep_identifier}")
|
||||
add_library(${_build_external_target} INTERFACE IMPORTED)
|
||||
set_property(TARGET ${_build_external_target} PROPERTY
|
||||
INTERFACE_LINK_LIBRARIES "${_external_dep}")
|
||||
# Defer namespace reconstruction until a consumer evaluates
|
||||
# the installed target. Otherwise CMake canonicalizes aliases
|
||||
# from a FetchContent dependency (Boost::url -> boost_url) and
|
||||
# requires the third-party target in Void's export set.
|
||||
string(REPLACE "::" "$<1:::>" _install_external_dep
|
||||
"${_external_dep}")
|
||||
target_link_libraries(${TGT} ${_external_scope}
|
||||
"$<BUILD_INTERFACE:${_build_external_target}>"
|
||||
"$<INSTALL_INTERFACE:${_install_external_dep}>")
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
foreach(_lib IN LISTS ARG_DEPS_WIN32)
|
||||
@@ -140,6 +201,15 @@ function(void_add_module MODULE_NAME)
|
||||
CXX_EXTENSIONS OFF
|
||||
EXPORT_NAME ${MODULE_NAME}
|
||||
)
|
||||
if(UNIX AND _module_target_type STREQUAL "SHARED_LIBRARY")
|
||||
set_property(TARGET ${TGT} PROPERTY INSTALL_RPATH "$ORIGIN")
|
||||
endif()
|
||||
if(WIN32 AND _module_target_type STREQUAL "SHARED_LIBRARY")
|
||||
# Void's public headers do not require consumers to opt into a DLL
|
||||
# import macro. Generate the export table for compiled shared modules
|
||||
# so the same installed targets remain usable on Windows.
|
||||
set_property(TARGET ${TGT} PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
endif()
|
||||
|
||||
# GCC 16+ exposes experimental C++26 reflection (P2996) via -freflection.
|
||||
# Apply it to every module unconditionally so any module is free to use
|
||||
|
||||
Reference in new issue
Block a user