From b174286698b163ae4826b3dd7ebe7ab2f3787108 Mon Sep 17 00:00:00 2001 From: ChatGPT Date: Fri, 5 Jun 2026 15:11:30 +0000 Subject: [PATCH] Build yyjson into nwcore --- CMakeLists.txt | 32 ++++---------------------------- src/CMakeLists.txt | 2 +- src/core/CMakeLists.txt | 25 ++++++++++++++++++++++--- src/nwsalvage.c | 2 +- 4 files changed, 28 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a3b9bd2..5627565 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -205,37 +205,13 @@ set(MARS_NWE_YYJSON_SOURCE_DIR "${CMAKE_SOURCE_DIR}/third_party/yyjson" CACHE PATH "Path to the bundled yyjson source tree") -if(NOT EXISTS "${MARS_NWE_YYJSON_SOURCE_DIR}/CMakeLists.txt") +if(NOT EXISTS "${MARS_NWE_YYJSON_SOURCE_DIR}/src/yyjson.c" OR + NOT EXISTS "${MARS_NWE_YYJSON_SOURCE_DIR}/src/yyjson.h") message(FATAL_ERROR - "Bundled yyjson is required. Run: git submodule update --init --recursive third_party/yyjson") + "Bundled yyjson source is required. Run: git submodule update --init --recursive third_party/yyjson") endif() -set(YYJSON_BUILD_TESTS OFF CACHE BOOL "" FORCE) -set(YYJSON_BUILD_FUZZER OFF CACHE BOOL "" FORCE) -set(YYJSON_BUILD_MISC OFF CACHE BOOL "" FORCE) -set(YYJSON_BUILD_DOC OFF CACHE BOOL "" FORCE) -set(YYJSON_ENABLE_COVERAGE OFF CACHE BOOL "" FORCE) -set(YYJSON_ENABLE_VALGRIND OFF CACHE BOOL "" FORCE) -set(YYJSON_ENABLE_FASTMATH OFF CACHE BOOL "" FORCE) -set(YYJSON_FORCE_32_BIT OFF CACHE BOOL "" FORCE) -set(YYJSON_INSTALL OFF CACHE BOOL "" FORCE) -set(YYJSON_SANITIZER "" CACHE STRING "" FORCE) -set(YYJSON_DISABLE_READER OFF CACHE BOOL "" FORCE) -set(YYJSON_DISABLE_WRITER OFF CACHE BOOL "" FORCE) -set(YYJSON_DISABLE_INCR_READER ON CACHE BOOL "" FORCE) -set(YYJSON_DISABLE_UTILS ON CACHE BOOL "" FORCE) -set(YYJSON_DISABLE_FAST_FP_CONV ON CACHE BOOL "" FORCE) -set(YYJSON_DISABLE_NON_STANDARD ON CACHE BOOL "" FORCE) -set(YYJSON_DISABLE_UTF8_VALIDATION OFF CACHE BOOL "" FORCE) - -set(MARS_NWE_SAVED_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) -set(BUILD_SHARED_LIBS OFF) -add_subdirectory("${MARS_NWE_YYJSON_SOURCE_DIR}" - "${CMAKE_BINARY_DIR}/third_party/yyjson" - EXCLUDE_FROM_ALL) -set(BUILD_SHARED_LIBS ${MARS_NWE_SAVED_BUILD_SHARED_LIBS}) - -message(STATUS "Salvage JSON backend: bundled static yyjson") +message(STATUS "Salvage JSON backend: yyjson built into nwcore") # mars-nwe private third-party stack. These are built with the nw namespace so # they can be installed next to system libraries and headers without collisions. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c1cb0b2..00bcbe8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -77,7 +77,7 @@ add_executable(ftrustee ftrustee.c tools.c nwfname.c unxfile.c nwvolume.c nwattr ############## target_link_libraries(nwserv ${CRYPT_LIBRARIES} ) -target_link_libraries(nwconn ${CRYPT_LIBRARIES} ${XATTR_LIBRARIES} yyjson ) +target_link_libraries(nwconn ${CRYPT_LIBRARIES} ${XATTR_LIBRARIES} mars_nwe::core ) target_link_libraries(ncpserv ${CRYPT_LIBRARIES} ) target_link_libraries(nwclient ${CRYPT_LIBRARIES} ) target_link_libraries(nwbind ${CRYPT_LIBRARIES} ${GDBM_LIBRARIES} ) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index e283f28..c71aa04 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -4,10 +4,19 @@ set(NWCORE_ZLOG_DIR "${CMAKE_SOURCE_DIR}/third_party/zlog" CACHE PATH "Path to bundled zlog source tree") +set(NWCORE_YYJSON_DIR + "${MARS_NWE_YYJSON_SOURCE_DIR}" + CACHE PATH "Path to bundled yyjson source tree") + if(NOT EXISTS "${NWCORE_ZLOG_DIR}/src/zlog.h") message(FATAL_ERROR "Bundled zlog is required. Run: git submodule update --init --recursive third_party/zlog") endif() +if(NOT EXISTS "${NWCORE_YYJSON_DIR}/src/yyjson.c" OR + NOT EXISTS "${NWCORE_YYJSON_DIR}/src/yyjson.h") + message(FATAL_ERROR "Bundled yyjson is required. Run: git submodule update --init --recursive third_party/yyjson") +endif() + file(GLOB NWCORE_ZLOG_SOURCES CONFIGURE_DEPENDS "${NWCORE_ZLOG_DIR}/src/*.c") @@ -26,10 +35,15 @@ configure_file( "${NWCORE_ZLOG_DIR}/src/zlog.h" "${NWCORE_BUILD_INCLUDE_DIR}/zlog.h" COPYONLY) +configure_file( + "${NWCORE_YYJSON_DIR}/src/yyjson.h" + "${NWCORE_BUILD_INCLUDE_DIR}/yyjson.h" + COPYONLY) add_library(nwcore SHARED core.c - ${NWCORE_ZLOG_SOURCES}) + ${NWCORE_ZLOG_SOURCES} + "${NWCORE_YYJSON_DIR}/src/yyjson.c") add_library(mars_nwe::core ALIAS nwcore) set_target_properties(nwcore PROPERTIES @@ -40,7 +54,11 @@ set_target_properties(nwcore PROPERTIES target_compile_features(nwcore PRIVATE c_std_99) target_compile_definitions(nwcore PRIVATE _GNU_SOURCE - MARS_NWE_VERSION_STRING="${MARS_NWE_VERSION}") + MARS_NWE_VERSION_STRING="${MARS_NWE_VERSION}" + YYJSON_DISABLE_INCR_READER + YYJSON_DISABLE_UTILS + YYJSON_DISABLE_FAST_FP_CONV + YYJSON_DISABLE_NON_STANDARD) target_include_directories(nwcore PUBLIC @@ -48,7 +66,8 @@ target_include_directories(nwcore "$" "$" PRIVATE - "${NWCORE_ZLOG_DIR}/src") + "${NWCORE_ZLOG_DIR}/src" + "${NWCORE_YYJSON_DIR}/src") target_link_libraries(nwcore PUBLIC Threads::Threads) diff --git a/src/nwsalvage.c b/src/nwsalvage.c index 6dca0c5..ba695cc 100644 --- a/src/nwsalvage.c +++ b/src/nwsalvage.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include