From 62734f3727b71cc3dc59b537fc5cf7a437297d15 Mon Sep 17 00:00:00 2001 From: scawful Date: Mon, 22 Dec 2025 14:28:24 -0500 Subject: [PATCH] deps: move json/httplib to CPM --- .gitmodules | 9 ------ cmake/CPM.cmake | 9 ++++-- cmake/dependencies.cmake | 13 ++++++++ cmake/dependencies.lock | 3 +- cmake/dependencies/httplib.cmake | 55 ++++++++++++++++++++++++++++++++ cmake/dependencies/json.cmake | 39 +++++++++++++++++++--- ext/httplib | 1 - ext/json | 1 - 8 files changed, 110 insertions(+), 20 deletions(-) create mode 100644 cmake/dependencies/httplib.cmake delete mode 160000 ext/httplib delete mode 160000 ext/json diff --git a/.gitmodules b/.gitmodules index 61b8bb1a..74827af6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,12 +13,3 @@ [submodule "ext/nativefiledialog-extended"] path = ext/nativefiledialog-extended url = https://github.com/btzy/nativefiledialog-extended.git -[submodule "assets/asm/usdasm"] - path = assets/asm/usdasm - url = https://github.com/spannerisms/usdasm.git -[submodule "ext/json"] - path = ext/json - url = https://github.com/nlohmann/json.git -[submodule "ext/httplib"] - path = ext/httplib - url = https://github.com/yhirose/cpp-httplib.git diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index ff82ff09..bc15609b 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -35,8 +35,12 @@ endif() include(${CPM_DOWNLOAD_LOCATION}) # Set CPM options for better caching and performance -set(CPM_USE_LOCAL_PACKAGES ON) -set(CPM_LOCAL_PACKAGES_ONLY OFF) +if(NOT DEFINED CPM_USE_LOCAL_PACKAGES) + set(CPM_USE_LOCAL_PACKAGES OFF) +endif() +if(NOT DEFINED CPM_LOCAL_PACKAGES_ONLY) + set(CPM_LOCAL_PACKAGES_ONLY OFF) +endif() set(CPM_DONT_CREATE_PACKAGE_LOCK ON) set(CPM_DONT_UPDATE_MODULE_PATH ON) set(CPM_DONT_PREPEND_TO_MODULE_PATH ON) @@ -46,4 +50,3 @@ if(DEFINED ENV{GITHUB_ACTIONS}) set(CPM_SOURCE_CACHE "$ENV{HOME}/.cpm-cache") message(STATUS "CPM cache directory: ${CPM_SOURCE_CACHE}") endif() - diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 385e6e3c..1f61e580 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -8,6 +8,9 @@ include(cmake/dependencies.lock) message(STATUS "=== Setting up YAZE dependencies with CPM.cmake ===") +# Only prefer local/system packages when explicitly requested. +set(CPM_USE_LOCAL_PACKAGES ${YAZE_USE_SYSTEM_DEPS} CACHE BOOL "" FORCE) + # Clear any previous dependency targets set(YAZE_ALL_DEPENDENCIES "") set(YAZE_SDL2_TARGETS "") @@ -15,6 +18,7 @@ set(YAZE_YAML_TARGETS "") set(YAZE_IMGUI_TARGETS "") set(YAZE_IMPLOT_TARGETS "") set(YAZE_JSON_TARGETS "") +set(YAZE_HTTPLIB_TARGETS "") set(YAZE_GRPC_TARGETS "") set(YAZE_FTXUI_TARGETS "") set(YAZE_TESTING_TARGETS "") @@ -54,6 +58,12 @@ if(YAZE_ENABLE_JSON) list(APPEND YAZE_ALL_DEPENDENCIES ${YAZE_JSON_TARGETS}) endif() +# Native HTTP/HTTPS (cpp-httplib) for non-WASM builds +if(NOT EMSCRIPTEN) + include(cmake/dependencies/httplib.cmake) + list(APPEND YAZE_ALL_DEPENDENCIES ${YAZE_HTTPLIB_TARGETS}) +endif() + # CRITICAL: Load testing dependencies BEFORE gRPC when both are enabled # This ensures gmock is available before Abseil (bundled with gRPC) tries to export test_allocator # which depends on gmock. This prevents CMake export errors. @@ -95,6 +105,9 @@ endif() if(YAZE_ENABLE_GRPC) message(STATUS "gRPC: ${YAZE_GRPC_TARGETS}") endif() +if(NOT EMSCRIPTEN) + message(STATUS "httplib: ${YAZE_HTTPLIB_TARGETS}") +endif() if(YAZE_BUILD_CLI AND NOT EMSCRIPTEN) message(STATUS "FTXUI: ${YAZE_FTXUI_TARGETS}") endif() diff --git a/cmake/dependencies.lock b/cmake/dependencies.lock index 935df2cb..706485f9 100644 --- a/cmake/dependencies.lock +++ b/cmake/dependencies.lock @@ -5,6 +5,8 @@ # Core dependencies set(SDL2_VERSION "2.30.0" CACHE STRING "SDL2 version") set(YAML_CPP_VERSION "0.8.0" CACHE STRING "yaml-cpp version") +set(NLOHMANN_JSON_VERSION "3.11.3" CACHE STRING "nlohmann/json version") +set(HTTPLIB_VERSION "0.26.0" CACHE STRING "cpp-httplib version") # gRPC and related # Using v1.67.1 for MSVC compatibility (v1.75.1 has UPB compilation errors on Windows) @@ -26,4 +28,3 @@ set(IMGUI_VERSION "1.90.4" CACHE STRING "Dear ImGui version") # ASAR set(ASAR_VERSION "main" CACHE STRING "ASAR version") - diff --git a/cmake/dependencies/httplib.cmake b/cmake/dependencies/httplib.cmake new file mode 100644 index 00000000..acc5fa2d --- /dev/null +++ b/cmake/dependencies/httplib.cmake @@ -0,0 +1,55 @@ +# cpp-httplib dependency management + +if(EMSCRIPTEN) + set(YAZE_HTTPLIB_TARGETS "" CACHE INTERNAL "cpp-httplib targets") + return() +endif() + +include(cmake/CPM.cmake) +include(cmake/dependencies.lock) + +message(STATUS "Setting up cpp-httplib ${HTTPLIB_VERSION}") + +set(_YAZE_USE_SYSTEM_HTTPLIB ${YAZE_USE_SYSTEM_DEPS}) + +# Try to use system packages first +if(_YAZE_USE_SYSTEM_HTTPLIB) + find_package(httplib QUIET) + if(httplib_FOUND) + message(STATUS "Using system httplib") + set(YAZE_HTTPLIB_TARGETS httplib::httplib CACHE INTERNAL "cpp-httplib targets") + return() + elseif(YAZE_USE_SYSTEM_DEPS) + message(WARNING "System httplib not found despite YAZE_USE_SYSTEM_DEPS=ON; falling back to CPM download") + endif() +endif() + +CPMAddPackage( + NAME httplib + VERSION ${HTTPLIB_VERSION} + GITHUB_REPOSITORY yhirose/cpp-httplib + GIT_TAG v${HTTPLIB_VERSION} + OPTIONS + "HTTPLIB_INSTALL OFF" + "HTTPLIB_TEST OFF" + "HTTPLIB_COMPILE OFF" + "HTTPLIB_USE_OPENSSL_IF_AVAILABLE OFF" + "HTTPLIB_USE_ZLIB_IF_AVAILABLE OFF" + "HTTPLIB_USE_BROTLI_IF_AVAILABLE OFF" + "HTTPLIB_USE_ZSTD_IF_AVAILABLE OFF" +) + +# Verify target is available +if(TARGET httplib::httplib) + message(STATUS "httplib::httplib target found") +elseif(TARGET httplib) + add_library(httplib::httplib ALIAS httplib) + message(STATUS "Created httplib::httplib alias") +else() + message(FATAL_ERROR "httplib target not found after CPM fetch") +endif() + +set(YAZE_HTTPLIB_TARGETS httplib::httplib) +set(YAZE_HTTPLIB_TARGETS httplib::httplib CACHE INTERNAL "cpp-httplib targets") + +message(STATUS "cpp-httplib setup complete") diff --git a/cmake/dependencies/json.cmake b/cmake/dependencies/json.cmake index 80ead608..2f08c0e3 100644 --- a/cmake/dependencies/json.cmake +++ b/cmake/dependencies/json.cmake @@ -4,14 +4,43 @@ if(NOT YAZE_ENABLE_JSON) return() endif() -message(STATUS "Setting up nlohmann_json with local ext directory") +include(cmake/CPM.cmake) +include(cmake/dependencies.lock) + +message(STATUS "Setting up nlohmann_json ${NLOHMANN_JSON_VERSION}") + +set(_YAZE_USE_SYSTEM_JSON ${YAZE_USE_SYSTEM_DEPS}) + +if(NOT _YAZE_USE_SYSTEM_JSON) + unset(nlohmann_json_DIR CACHE) +endif() + +# Try to use system packages first +if(_YAZE_USE_SYSTEM_JSON) + find_package(nlohmann_json QUIET) + if(nlohmann_json_FOUND) + message(STATUS "Using system nlohmann_json") + set(YAZE_JSON_TARGETS nlohmann_json::nlohmann_json CACHE INTERNAL "nlohmann_json targets") + return() + elseif(YAZE_USE_SYSTEM_DEPS) + message(WARNING "System nlohmann_json not found despite YAZE_USE_SYSTEM_DEPS=ON; falling back to CPM download") + endif() +endif() -# Use the bundled nlohmann_json from ext/json set(JSON_BuildTests OFF CACHE BOOL "" FORCE) set(JSON_Install OFF CACHE BOOL "" FORCE) set(JSON_MultipleHeaders OFF CACHE BOOL "" FORCE) -add_subdirectory(${CMAKE_SOURCE_DIR}/ext/json EXCLUDE_FROM_ALL) +CPMAddPackage( + NAME nlohmann_json + VERSION ${NLOHMANN_JSON_VERSION} + GITHUB_REPOSITORY nlohmann/json + GIT_TAG v${NLOHMANN_JSON_VERSION} + OPTIONS + "JSON_BuildTests OFF" + "JSON_Install OFF" + "JSON_MultipleHeaders OFF" +) # Verify target is available if(TARGET nlohmann_json::nlohmann_json) @@ -21,11 +50,11 @@ elseif(TARGET nlohmann_json) add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json) message(STATUS "Created nlohmann_json::nlohmann_json alias") else() - message(FATAL_ERROR "nlohmann_json target not found after add_subdirectory") + message(FATAL_ERROR "nlohmann_json target not found after CPM fetch") endif() # Export for use in other CMake files +set(YAZE_JSON_TARGETS nlohmann_json::nlohmann_json) set(YAZE_JSON_TARGETS nlohmann_json::nlohmann_json CACHE INTERNAL "nlohmann_json targets") message(STATUS "nlohmann_json setup complete") - diff --git a/ext/httplib b/ext/httplib deleted file mode 160000 index 35c52c1a..00000000 --- a/ext/httplib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 35c52c1ab9b8ade2e66548fcec5e417092d8e583 diff --git a/ext/json b/ext/json deleted file mode 160000 index 3ed64e50..00000000 --- a/ext/json +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3ed64e502a6371311af3c2f309e6525b2f5f6f18