[glaze] Make asio dependency optional (#53588)

This commit is contained in:
xiaozhuai 2026-08-31 02:02:00 +08:00 committed by GitHub
parent d36bc2792a
commit 32017522e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 64 additions and 20 deletions

View File

@ -1,20 +1,39 @@
diff --git a/cmake/install-config.cmake.in b/cmake/install-config.cmake.in
index dbd6977f..7227a9a8 100644
index dbd6977f..b2ea2c64 100644
--- a/cmake/install-config.cmake.in
+++ b/cmake/install-config.cmake.in
@@ -10,6 +10,8 @@ if(_glaze_EETF_FORMAT)
@@ -10,6 +10,26 @@ if(_glaze_EETF_FORMAT)
endif()
unset(_glaze_EETF_FORMAT)
+find_dependency(asio REQUIRED)
+set(_glaze_ENABLE_NETWORKING "@glaze_ENABLE_NETWORKING@")
+if(_glaze_ENABLE_NETWORKING)
+ # vcpkg always uses standalone Asio, as declared in the port manifest.
+ # Preserve the documented networking interface without selecting Boost or
+ # downloading an undeclared dependency.
+ find_dependency(asio REQUIRED)
+ if(NOT TARGET glaze::asio)
+ add_library(glaze::asio INTERFACE IMPORTED)
+ set_property(TARGET glaze::asio PROPERTY INTERFACE_LINK_LIBRARIES asio::asio)
+ endif()
+
+ function(glaze_setup_asio)
+ endfunction()
+else()
+ function(glaze_setup_asio)
+ message(FATAL_ERROR "glaze_setup_asio() called but glaze was built without networking support")
+ endfunction()
+endif()
+unset(_glaze_ENABLE_NETWORKING)
+
# Handle SSL dependency (OpenSSL)
set(_glaze_ENABLE_SSL "@glaze_ENABLE_SSL@")
if(_glaze_ENABLE_SSL)
@@ -19,13 +21,13 @@ unset(_glaze_ENABLE_SSL)
@@ -18,14 +38,3 @@ endif()
unset(_glaze_ENABLE_SSL)
include("${CMAKE_CURRENT_LIST_DIR}/glazeTargets.cmake")
-
-# Make the Asio backend selector available to networking consumers. This only
-# declares the glaze_USE_BUNDLED_ASIO option and the glaze_setup_asio() function;
-# nothing is resolved until the consumer calls glaze_setup_asio() and links
@ -25,16 +44,6 @@ index dbd6977f..7227a9a8 100644
-if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/glaze-asio.cmake")
- include("${CMAKE_CURRENT_LIST_DIR}/glaze-asio.cmake")
-endif()
+# vcpkg always uses standalone Asio, as declared in the port manifest.
+# Preserve the documented networking interface without selecting Boost or
+# downloading an undeclared dependency.
+if(NOT TARGET glaze::asio)
+ add_library(glaze::asio INTERFACE IMPORTED)
+ set_property(TARGET glaze::asio PROPERTY INTERFACE_LINK_LIBRARIES asio::asio)
+endif()
+
+function(glaze_setup_asio)
+endfunction()
diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake
index cae895a7..42accbfc 100644
--- a/cmake/install-rules.cmake

View File

@ -14,7 +14,8 @@ vcpkg_from_github(
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
ssl glaze_ENABLE_SSL
networking glaze_ENABLE_NETWORKING
ssl glaze_ENABLE_SSL
)
vcpkg_cmake_configure(
@ -29,8 +30,11 @@ vcpkg_cmake_configure(
vcpkg_cmake_install()
vcpkg_cmake_config_fixup()
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/glaze/ext/glaze_asio.hpp" "#if __has_include(<asio.hpp>) && !defined(GLZ_USE_BOOST_ASIO)" "#if 1")
if("networking" IN_LIST FEATURES)
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/glaze/ext/glaze_asio.hpp" "#if __has_include(<asio.hpp>) && !defined(GLZ_USE_BOOST_ASIO)" "#if 1")
endif()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
file(INSTALL "${CURRENT_PORT_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")

7
ports/glaze/usage Normal file
View File

@ -0,0 +1,7 @@
glaze provides CMake targets:
find_package(glaze CONFIG REQUIRED)
target_link_libraries(main PRIVATE glaze::glaze)
# Glaze's networking features, this requires glaze[networking] to be on
glaze_setup_asio()
target_link_libraries(main PRIVATE glaze::asio)

View File

@ -1,12 +1,12 @@
{
"name": "glaze",
"version": "8.2.0",
"port-version": 1,
"description": "One of the fastest JSON libraries in the world. Glaze reads and writes from C++ memory, simplifying interfaces and offering incredible performance.",
"homepage": "https://github.com/stephenberry/glaze",
"license": "MIT",
"supports": "!uwp",
"dependencies": [
"asio",
{
"name": "vcpkg-cmake",
"host": true
@ -17,9 +17,22 @@
}
],
"features": {
"networking": {
"description": "Enable networking support",
"dependencies": [
"asio"
]
},
"ssl": {
"description": "Enable SSL/TLS support for HTTPS servers",
"dependencies": [
{
"name": "glaze",
"default-features": false,
"features": [
"networking"
]
},
"openssl"
]
}

View File

@ -3,7 +3,13 @@
"version-string": "ci",
"description": "Validates Glaze networking CMake integration",
"dependencies": [
"glaze",
{
"name": "glaze",
"default-features": false,
"features": [
"networking"
]
},
{
"name": "vcpkg-cmake",
"host": true

View File

@ -3466,7 +3466,7 @@
},
"glaze": {
"baseline": "8.2.0",
"port-version": 0
"port-version": 1
},
"glbinding": {
"baseline": "3.1.0",

View File

@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "8900ed8cedf36274dfc2ce646140d74fe469d378",
"version": "8.2.0",
"port-version": 1
},
{
"git-tree": "cbb70bf9b288bccae1e248bc148ec1da3a918df2",
"version": "8.2.0",