deps: move json/httplib to CPM

This commit is contained in:
scawful
2025-12-22 14:28:24 -05:00
parent ca71140a88
commit 62734f3727
8 changed files with 110 additions and 20 deletions

View File

@@ -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")

View File

@@ -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")