From c1d41a36bb28136e2ea54f2f10e6ad0e79e0928a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 15 Jan 2024 14:04:56 +0800 Subject: [PATCH] CMake: fix build in macOS with -DENABLE_SYSTEM_YYJSON --- CMakeLists.txt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4449034b6..6e17bfd66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,12 +114,6 @@ elseif(APPLE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fobjc-arc") endif() -# Used for dlopen finding dylibs installed by homebrew -# `/opt/homebrew/lib` is not on in dlopen search path by default -if(APPLE AND DEFINED ENV{HOMEBREW_PREFIX}) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,$ENV{HOMEBREW_PREFIX}/lib") -endif() - set(FASTFETCH_FLAGS_DEBUG "-fno-omit-frame-pointer") if(ENABLE_ASAN) message(STATUS "Address sanitizer enabled (DEBUG only)") @@ -713,7 +707,14 @@ endif() if(yyjson_FOUND) target_compile_definitions(libfastfetch PRIVATE FF_USE_SYSTEM_YYJSON) - target_link_libraries(libfastfetch PRIVATE yyjson) + target_link_libraries(libfastfetch PRIVATE yyjson::yyjson) + # `target_link_libraries(yyjson::yyjson)` sets rpath implicitly +else() + # Used for dlopen finding dylibs installed by homebrew + # `/opt/homebrew/lib` is not on in dlopen search path by default + if(APPLE AND DEFINED ENV{HOMEBREW_PREFIX}) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,$ENV{HOMEBREW_PREFIX}/lib") + endif() endif() if(LINUX AND EXISTS "/lib/ld-musl-${CMAKE_HOST_SYSTEM_PROCESSOR}.so.1") @@ -1007,7 +1008,9 @@ set_target_properties(flashfetch PROPERTIES LINKER_LANGUAGE C) if(yyjson_FOUND) target_compile_definitions(fastfetch PRIVATE FF_USE_SYSTEM_YYJSON) + target_link_libraries(fastfetch PRIVATE yyjson::yyjson) target_compile_definitions(flashfetch PRIVATE FF_USE_SYSTEM_YYJSON) + target_link_libraries(flashfetch PRIVATE yyjson::yyjson) endif() if(WIN32)