From 2d6bb5ba0e42c67eb923e891b823040ce99ec8fd Mon Sep 17 00:00:00 2001 From: attila Date: Thu, 24 Oct 2024 17:00:47 +0200 Subject: [PATCH] Linux: CMake: Omit linking browser related dynamic libraries We've already had a mechanism in place which loads these libraries, such as libwebkit2gtk-4.1.so, only if they are available on the system during runtime. This way we can run with either version 4.1 or 4.0 of the library depending on which one is available. It's also possible to run apps on headless systems with the relevant features being effectively disabled in such situations. --- extras/Build/CMake/JUCEModuleSupport.cmake | 10 ++++++++-- extras/Build/CMake/JUCEUtils.cmake | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/extras/Build/CMake/JUCEModuleSupport.cmake b/extras/Build/CMake/JUCEModuleSupport.cmake index 349d7ab9b2..0149b409e8 100644 --- a/extras/Build/CMake/JUCEModuleSupport.cmake +++ b/extras/Build/CMake/JUCEModuleSupport.cmake @@ -376,12 +376,15 @@ endfunction() # ================================================================================================== function(_juce_create_pkgconfig_target name) + set(options NOLINK) + cmake_parse_arguments(JUCE_ARG "${options}" "" "" ${ARGN}) + if(TARGET juce::pkgconfig_${name}) return() endif() find_package(PkgConfig REQUIRED) - pkg_check_modules(${name} ${ARGN}) + pkg_check_modules(${name} ${JUCE_ARG_UNPARSED_ARGUMENTS}) add_library(pkgconfig_${name} INTERFACE) add_library(juce::pkgconfig_${name} ALIAS pkgconfig_${name}) @@ -389,10 +392,13 @@ function(_juce_create_pkgconfig_target name) set(pairs "INCLUDE_DIRECTORIES\;INCLUDE_DIRS" - "LINK_LIBRARIES\;LINK_LIBRARIES" "LINK_OPTIONS\;LDFLAGS_OTHER" "COMPILE_OPTIONS\;CFLAGS_OTHER") + if(NOT JUCE_ARG_NOLINK) + list(APPEND pairs "LINK_LIBRARIES\;LINK_LIBRARIES") + endif() + foreach(pair IN LISTS pairs) list(GET pair 0 key) list(GET pair 1 value) diff --git a/extras/Build/CMake/JUCEUtils.cmake b/extras/Build/CMake/JUCEUtils.cmake index ef8ebd7266..c429bf6e29 100644 --- a/extras/Build/CMake/JUCEUtils.cmake +++ b/extras/Build/CMake/JUCEUtils.cmake @@ -107,7 +107,9 @@ endfunction() if((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR (CMAKE_SYSTEM_NAME MATCHES ".*BSD")) _juce_create_pkgconfig_target(JUCE_CURL_LINUX_DEPS libcurl) _juce_available_pkgconfig_module_or_else(webkit_package_name webkit2gtk-4.1 webkit2gtk-4.0) - _juce_create_pkgconfig_target(JUCE_BROWSER_LINUX_DEPS ${webkit_package_name} gtk+-x11-3.0) + + # All browser related libs are loaded dynamically only if they are available during runtime + _juce_create_pkgconfig_target(JUCE_BROWSER_LINUX_DEPS NOLINK ${webkit_package_name} gtk+-x11-3.0) endif() # We set up default/fallback copy dirs here. If you need different copy dirs, use