Skip to content

Commit c7f0172

Browse files
committed
CMake: Add option ENABLE_SYSTEM_YYJSON
Fix: #525
1 parent 125759d commit c7f0172

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

CMakeLists.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR BSD" OFF)
6969
cmake_dependent_option(ENABLE_DDCUTIL "Enable ddcutil" ON "LINUX" OFF)
7070
cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF)
7171
cmake_dependent_option(ENABLE_PCI_MEMORY "Enable detecting GPU memory size with libpci" OFF "LINUX OR BSD" OFF)
72+
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)
7273

7374
option(BUILD_TESTS "Build tests" OFF) # Also create test executables
7475
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}")
251252
#######################
252253

253254
set(LIBFASTFETCH_SRC
254-
src/3rdparty/yyjson/yyjson.c
255255
src/common/bar.c
256256
src/common/commandoption.c
257257
src/common/font.c
@@ -605,9 +605,26 @@ if(NOT HAVE_WCWIDTH)
605605
list(APPEND LIBFASTFETCH_SRC src/3rdparty/mk_wcwidch/wcwidth.c)
606606
endif()
607607

608+
if(ENABLE_SYSTEM_YYJSON)
609+
find_package(yyjson)
610+
if(yyjson_FOUND)
611+
message(STATUS "System provided yyjson is used")
612+
else()
613+
message(FATAL_ERROR "ENABLE_SYSTEM_YYJSON is set but system provided yyjson is not found")
614+
endif()
615+
else()
616+
list(APPEND LIBFASTFETCH_SRC
617+
src/3rdparty/yyjson/yyjson.c
618+
)
619+
endif()
620+
608621
add_library(libfastfetch OBJECT
609622
${LIBFASTFETCH_SRC}
610623
)
624+
if(yyjson_FOUND)
625+
target_compile_definitions(libfastfetch PRIVATE FF_USE_SYSTEM_YYJSON)
626+
target_link_libraries(libfastfetch PRIVATE yyjson)
627+
endif()
611628

612629
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE)
613630
if(WIN32)

src/common/option.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#pragma once
22

33
#include "util/FFstrbuf.h"
4-
#include "3rdparty/yyjson/yyjson.h"
4+
5+
struct yyjson_val;
56

67
// Must be the first field of FFModuleOptions
78
typedef struct FFModuleBaseInfo
89
{
910
const char* name;
1011
bool (*parseCommandOptions)(void* options, const char* key, const char* value);
11-
void (*parseJsonObject)(void* options, yyjson_val *module);
12+
void (*parseJsonObject)(void* options, struct yyjson_val *module);
1213
void (*printModule)(void* options);
1314
} FFModuleBaseInfo;
1415

src/fastfetch.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
#include <stdint.h>
99
#include <stdbool.h>
1010

11-
#include "3rdparty/yyjson/yyjson.h"
11+
#ifdef FF_USE_SYSTEM_YYJSON
12+
#include <yyjson.h>
13+
#else
14+
#include "3rdparty/yyjson/yyjson.h"
15+
#endif
1216

1317
#include "util/FFstrbuf.h"
1418
#include "util/FFlist.h"

0 commit comments

Comments
 (0)