From c7f0172b256ea3f29e6e2ef25cd43fcc2c12614e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 19 Aug 2023 11:10:14 +0800 Subject: [PATCH] CMake: Add option `ENABLE_SYSTEM_YYJSON` Fix: #525 --- CMakeLists.txt | 19 ++++++++++++++++++- src/common/option.h | 5 +++-- src/fastfetch.h | 6 +++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e12d945f..1aa9041df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,7 @@ cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR BSD" OFF) cmake_dependent_option(ENABLE_DDCUTIL "Enable ddcutil" ON "LINUX" OFF) cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF) cmake_dependent_option(ENABLE_PCI_MEMORY "Enable detecting GPU memory size with libpci" OFF "LINUX OR BSD" OFF) +cmake_dependent_option(ENABLE_SYSTEM_YYJSON "Use system provided (instead of fastfetch embeded) yyjson library" OFF "LINUX OR APPLE OR BSD OR WIN32 OR ANDROID" OFF) option(BUILD_TESTS "Build tests" OFF) # Also create test executables option(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds @@ -251,7 +252,6 @@ file(GENERATE OUTPUT logo_builtin.h CONTENT "${LOGO_BUILTIN_H}") ####################### set(LIBFASTFETCH_SRC - src/3rdparty/yyjson/yyjson.c src/common/bar.c src/common/commandoption.c src/common/font.c @@ -605,9 +605,26 @@ if(NOT HAVE_WCWIDTH) list(APPEND LIBFASTFETCH_SRC src/3rdparty/mk_wcwidch/wcwidth.c) endif() +if(ENABLE_SYSTEM_YYJSON) + find_package(yyjson) + if(yyjson_FOUND) + message(STATUS "System provided yyjson is used") + else() + message(FATAL_ERROR "ENABLE_SYSTEM_YYJSON is set but system provided yyjson is not found") + endif() +else() + list(APPEND LIBFASTFETCH_SRC + src/3rdparty/yyjson/yyjson.c + ) +endif() + add_library(libfastfetch OBJECT ${LIBFASTFETCH_SRC} ) +if(yyjson_FOUND) + target_compile_definitions(libfastfetch PRIVATE FF_USE_SYSTEM_YYJSON) + target_link_libraries(libfastfetch PRIVATE yyjson) +endif() target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE) if(WIN32) diff --git a/src/common/option.h b/src/common/option.h index c77376188..342b48083 100644 --- a/src/common/option.h +++ b/src/common/option.h @@ -1,14 +1,15 @@ #pragma once #include "util/FFstrbuf.h" -#include "3rdparty/yyjson/yyjson.h" + +struct yyjson_val; // Must be the first field of FFModuleOptions typedef struct FFModuleBaseInfo { const char* name; bool (*parseCommandOptions)(void* options, const char* key, const char* value); - void (*parseJsonObject)(void* options, yyjson_val *module); + void (*parseJsonObject)(void* options, struct yyjson_val *module); void (*printModule)(void* options); } FFModuleBaseInfo; diff --git a/src/fastfetch.h b/src/fastfetch.h index ce68fd873..dd4b4a821 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -8,7 +8,11 @@ #include #include -#include "3rdparty/yyjson/yyjson.h" +#ifdef FF_USE_SYSTEM_YYJSON + #include +#else + #include "3rdparty/yyjson/yyjson.h" +#endif #include "util/FFstrbuf.h" #include "util/FFlist.h"