Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmake] Complete target usage for dependency libs, and remove some old globals and other cmake cleanups #25228

Open
wants to merge 76 commits into
base: master
Choose a base branch
from

Conversation

fuzzard
Copy link
Contributor

@fuzzard fuzzard commented May 18, 2024

Description

Well this PR got bigger than i first intended. This completes moving all find modules to target usage. I wouldnt consider all the modules "final" as such, but for this part, they are functional and complete (as best i could test/see).
This allowed to remove a number of global variable usage. Ive also done some minor cleanups/relocations of some cmake stuff i saw along the way.

Motivation and context

Modern cmake usage

How has this been tested?

Jenkins has been doing some work. Ive runtime tested macos, and spent a bit of time comparing master builds to outputs from this branch. As best i can see i believe ive covered everything, however this is obviously a massive change, so if anyone comes across cmake issues, or specific features from libs no longer functioning, let me know.

What is the effect on users?

N/A

Screenshots (if appropriate):

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • Student submission (PR was done for educational purposes and will be treated as such)
  • None of the above (please explain below)

Checklist:

  • My code follows the Code Guidelines of this project
  • My change requires a change to the documentation, either Doxygen or wiki
  • I have updated the documentation accordingly
  • I have read the Contributing document
  • I have added tests to cover my change
  • All new and existing tests passed

@fuzzard fuzzard added this to the "P" 22.0 Alpha 1 milestone May 18, 2024
@fuzzard fuzzard force-pushed the cmake_cleanup3 branch 5 times, most recently from 5e1f35d to 00cba2a Compare May 18, 2024 23:46
@howie-f
Copy link
Contributor

howie-f commented May 19, 2024

i‘ve picked those commits and didn‘t see any issues during build of my daily driver kodi on debian bookworm

fuzzard added 18 commits May 20, 2024 20:37
fuzzard added 12 commits May 20, 2024 20:37
With full target usage, and removal of globals like *_LIBRARIES, *_INCLUDE_DIRS
we introduce a wrapper find module that still uses cmakes system find_package(OpenSSL)
and make an alias using "our" standard
With full target usage, and removal of globals like *_LIBRARIES, *_INCLUDE_DIRS
we introduce a wrapper find module that still uses cmakes system find_package(ZLIB)
and make an alias using "our" standard for macro usage
This function is only used in CPackConfigDEB, so move out of generic Macros.cmake
userstamp is only used in CPackConfigDEB. remove out of Macros.cmake
@garbear
Copy link
Member

garbear commented May 28, 2024

I've pulled this into my test builds. I'll let you know if anything comes up.

@garbear
Copy link
Member

garbear commented May 29, 2024

Something came up, when applying this PR and building LibreELEC 12.0.0 I get the following error. Reverting the PR fixes the problem:

libmicrohttpd.a(libmicrohttpd_la-connection.o):connection.c:function MHD_get_connection_info:(.text+0x2cd8): error: undefined reference to 'gnutls_cipher_get'
libmicrohttpd.a(libmicrohttpd_la-connection.o):connection.c:function MHD_get_connection_info:(.text+0x2d00): error: undefined reference to 'gnutls_protocol_get_version'
libmicrohttpd.a(libmicrohttpd_la-connection.o):connection.c:function MHD_connection_handle_idle:(.text+0x5158): error: undefined reference to 'gnutls_record_get_direction'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function psk_gnutls_adapter:(.text+0x5df): error: undefined reference to 'gnutls_session_get_ptr'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function psk_gnutls_adapter:(.text+0x626): error: undefined reference to 'gnutls_malloc'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function process_urh:(.text+0xa6a): error: undefined reference to 'gnutls_record_recv'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function process_urh:(.text+0xb25): error: undefined reference to 'gnutls_record_send'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function process_urh:(.text+0xbfc): error: undefined reference to 'gnutls_record_check_pending'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function process_urh:(.text+0xc53): error: undefined reference to 'gnutls_strerror'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function daemon_tls_priorities_init_default:(.text+0xe4c): error: undefined reference to 'gnutls_priority_init'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function daemon_tls_priorities_init_default:(.text+0xe64): error: undefined reference to 'gnutls_strerror'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function daemon_tls_priorities_init_append_inner_.constprop.0:(.text+0xfb7): error: undefined reference to 'gnutls_priority_init'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function daemon_tls_priorities_init_append_inner_.constprop.0:(.text+0xfcf): error: undefined reference to 'gnutls_strerror'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function daemon_tls_priorities_init_append_inner_.constprop.0:(.text+0x1011): error: undefined reference to 'gnutls_priority_init2'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function parse_options_va:(.text+0x1153): error: undefined reference to 'gnutls_priority_deinit'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function parse_options_va:(.text+0x1946): error: undefined reference to 'gnutls_dh_params_init'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function parse_options_va:(.text+0x1980): error: undefined reference to 'gnutls_dh_params_import_pkcs3'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function parse_options_va:(.text+0x21fb): error: undefined reference to 'gnutls_priority_init'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function parse_options_va:(.text+0x220a): error: undefined reference to 'gnutls_strerror'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function parse_options_va:(.text+0x22df): error: undefined reference to 'gnutls_dh_params_deinit'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_cleanup_connections:(.text+0x2d27): error: undefined reference to 'gnutls_deinit'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_cleanup_connections:(.text+0x2e8d): error: undefined reference to 'gnutls_bye'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function new_connection_process_:(.text+0x31ce): error: undefined reference to 'gnutls_deinit'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function internal_add_connection.constprop.0:(.text+0x392a): error: undefined reference to 'gnutls_init'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function internal_add_connection.constprop.0:(.text+0x3943): error: undefined reference to 'gnutls_deinit'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function internal_add_connection.constprop.0:(.text+0x3bdf): error: undefined reference to 'gnutls_priority_set'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function internal_add_connection.constprop.0:(.text+0x3c04): error: undefined reference to 'gnutls_session_set_ptr'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function internal_add_connection.constprop.0:(.text+0x3c38): error: undefined reference to 'gnutls_deinit'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function internal_add_connection.constprop.0:(.text+0x3d04): error: undefined reference to 'gnutls_credentials_set'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function internal_add_connection.constprop.0:(.text+0x3d15): error: undefined reference to 'gnutls_psk_set_server_credentials_function'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function internal_add_connection.constprop.0:(.text+0x3d25): error: undefined reference to 'gnutls_transport_set_int2'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function internal_add_connection.constprop.0:(.text+0x3d44): error: undefined reference to 'gnutls_certificate_server_set_request'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function internal_add_connection.constprop.0:(.text+0x3d61): error: undefined reference to 'gnutls_credentials_set'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function internal_add_connection.constprop.0:(.text+0x3d74): error: undefined reference to 'gnutls_alpn_set_protocols'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_stop_daemon:(.text+0x7ae0): error: undefined reference to 'gnutls_priority_deinit'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_stop_daemon:(.text+0x7af1): error: undefined reference to 'gnutls_certificate_free_credentials'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_stop_daemon:(.text+0x7b06): error: undefined reference to 'gnutls_psk_free_server_credentials'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_stop_daemon:(.text+0x7b17): error: undefined reference to 'gnutls_dh_params_deinit'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_start_daemon_va:(.text+0x844c): error: undefined reference to 'gnutls_priority_deinit'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_start_daemon_va:(.text+0x8890): error: undefined reference to 'gnutls_priority_deinit'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_start_daemon_va:(.text+0x8a79): error: undefined reference to 'gnutls_certificate_free_credentials'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_start_daemon_va:(.text+0x8a8e): error: undefined reference to 'gnutls_psk_free_server_credentials'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_start_daemon_va:(.text+0x915f): error: undefined reference to 'gnutls_certificate_allocate_credentials'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_start_daemon_va:(.text+0x9183): error: undefined reference to 'gnutls_certificate_set_retrieve_function2'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_start_daemon_va:(.text+0x91c3): error: undefined reference to 'gnutls_certificate_set_x509_trust_mem'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_start_daemon_va:(.text+0x925d): error: undefined reference to 'gnutls_certificate_set_x509_key_mem2'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_start_daemon_va:(.text+0x9281): error: undefined reference to 'gnutls_psk_allocate_server_credentials'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_start_daemon_va:(.text+0x9710): error: undefined reference to 'gnutls_certificate_set_retrieve_function3'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_start_daemon_va:(.text+0x97d6): error: undefined reference to 'gnutls_certificate_set_dh_params'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_start_daemon_va:(.text+0x99d2): error: undefined reference to 'gnutls_certificate_set_x509_key_mem'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_init:(.text+0x9fde): error: undefined reference to 'gnutls_global_init'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function MHD_fini:(.text+0xa005): error: undefined reference to 'gnutls_global_deinit'
libmicrohttpd.a(libmicrohttpd_la-daemon.o):daemon.c:function _GNUC_deinit_helper_MHD_fini:(.text.exit+0x5): error: undefined reference to 'gnutls_global_deinit'
libmicrohttpd.a(libmicrohttpd_la-mhd_send.o):mhd_send.c:function MHD_send_data_:(.text+0x402): error: undefined reference to 'gnutls_record_send'
libmicrohttpd.a(libmicrohttpd_la-connection_https.o):connection_https.c:function recv_tls_adapter:(.text+0x26): error: undefined reference to 'gnutls_record_recv'
libmicrohttpd.a(libmicrohttpd_la-connection_https.o):connection_https.c:function recv_tls_adapter:(.text+0x119): error: undefined reference to 'gnutls_record_check_pending'
libmicrohttpd.a(libmicrohttpd_la-connection_https.o):connection_https.c:function MHD_run_tls_handshake_:(.text+0x1d4): error: undefined reference to 'gnutls_handshake'
libmicrohttpd.a(libmicrohttpd_la-connection_https.o):connection_https.c:function MHD_tls_connection_shutdown:(.text+0x281): error: undefined reference to 'gnutls_bye'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
FAILURE: scripts/build kodi:target during make_target (default)

@fuzzard
Copy link
Contributor Author

fuzzard commented May 29, 2024

So whats libreelec using, shared libs or static? I would have assumed they are meant to be using shared libs, therefore it shouldnt be trying to link a static lib.

you could try the following to get more information about what is populated for link libraries

--- a/cmake/modules/FindMicroHttpd.cmake
+++ b/cmake/modules/FindMicroHttpd.cmake
@@ -60,7 +60,7 @@ if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
                                                                      IMPORTED_LOCATION "${MICROHTTPD_LIBRARY}"
                                                                      INTERFACE_INCLUDE_DIRECTORIES "${MICROHTTPD_INCLUDE_DIR}"
                                                                      INTERFACE_COMPILE_DEFINITIONS "HAS_WEB_SERVER;HAS_WEB_INTERFACE")
-
+message(WARNING "PC_MICROHTTPD_LINK_LIBRARIES: ${PC_MICROHTTPD_LINK_LIBRARIES}")
       # Add link libraries for static lib usage found from pkg-config
       if(PC_MICROHTTPD_LINK_LIBRARIES)
         set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES

A shared library should show up like

-- Found MicroHttpd: /Users/Shared/xbmc-depends/macosx14.5_arm64-target-debug/lib/libmicrohttpd.dylib (found suitable version "0.9.77", minimum required is "0.9.40")
CMake Warning at cmake/modules/FindMicroHttpd.cmake:63 (message):
  PC_MICROHTTPD_LINK_LIBRARIES:
Call Stack (most recent call first):
  cmake/scripts/common/Macros.cmake:390 (find_package)
  cmake/scripts/common/Macros.cmake:440 (find_package_with_ver)
  CMakeLists.txt:262 (core_optional_dep)

whereas a static lib should show something along the lines of (obviously more platform specific)

-- Found MicroHttpd: /Users/Shared/xbmc-depends/macosx14.5_arm64-target-debug/lib/libmicrohttpd.a (found suitable version "0.9.77", minimum required is "0.9.40")
CMake Warning at cmake/modules/FindMicroHttpd.cmake:63 (message):
  PC_MICROHTTPD_LINK_LIBRARIES:
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/lib/libpthread.tbd;/Users/Shared/xbmc-depends/macosx14.5_arm64-target-debug/lib/libgnutls.a;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/lib/libz.tbd;/Users/Shared/xbmc-depends/macosx14.5_arm64-target-debug/lib/libgmp.a;-framework
  Security;-framework
  CoreFoundation;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/lib/libdl.tbd;/Users/Shared/xbmc-depends/macosx14.5_arm64-target-debug/lib/libhogweed.a;/Users/Shared/xbmc-depends/macosx14.5_arm64-target-debug/lib/libnettle.a
Call Stack (most recent call first):
  cmake/scripts/common/Macros.cmake:390 (find_package)
  cmake/scripts/common/Macros.cmake:440 (find_package_with_ver)
  CMakeLists.txt:262 (core_optional_dep)

Either way, if libreelec intends to link a static version of libmicrohttpd, it is required to also provide static libs of its dependencies, as they are required to link.

@lrusak
Copy link
Contributor

lrusak commented May 29, 2024

So whats libreelec using, shared libs or static? I would have assumed they are meant to be using shared libs, therefore it shouldnt be trying to link a static lib.

It is static for some reason https://github.com/LibreELEC/LibreELEC.tv/blob/e92d34bfcad590c172292a03b2ccc6dc31180fb9/packages/web/libmicrohttpd/package.mk#L15

@fuzzard
Copy link
Contributor Author

fuzzard commented May 29, 2024

I imagine thats not the normal? Looks like that flag has been enabled for 11+ years. oversight?

@garbear
Copy link
Member

garbear commented May 29, 2024

@fuzzard

<<< kodi:target seq 308 <<<
BUILD      kodi (target)
    TOOLCHAIN      cmake (auto-detect)
Executing (target): cmake -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE=LibreELEC.tv/build.LibreELEC-Generic.x86_64-12.0-devel/toolchain/etc/cmake-x86_64-libreelec-linux-gnu.conf -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=MinSizeRel -DNATIVEPREFIX=LibreELEC.tv/build.LibreELEC-Generic.x86_64-12.0-devel/toolchain -DWITH_TEXTUREPACKER=LibreELEC.tv/build.LibreELEC-Generic.x86_64-12.0-devel/toolchain/bin/TexturePacker -DWITH_JSONSCHEMABUILDER=LibreELEC.tv/build.LibreELEC-Generic.x86_64-12.0-devel/toolchain/bin/JsonSchemaBuilder -DSWIG_EXECUTABLE=LibreELEC.tv/build.LibreELEC-Generic.x86_64-12.0-devel/toolchain/bin/swig -DPYTHON_EXECUTABLE=LibreELEC.tv/build.LibreELEC-Generic.x86_64-12.0-devel/toolchain/bin/python3.11 -DPYTHON_INCLUDE_DIRS=LibreELEC.tv/build.LibreELEC-Generic.x86_64-12.0-devel/toolchain/x86_64-libreelec-linux-gnu/sysroot/usr/include/python3.11 -DGIT_VERSION=d4cc84f8f6bd0bba78511c78d574de13a552527f -DFFMPEG_PATH=LibreELEC.tv/build.LibreELEC-Generic.x86_64-12.0-devel/toolchain/x86_64-libreelec-linux-gnu/sysroot/usr -DENABLE_INTERNAL_FFMPEG=OFF -DENABLE_INTERNAL_CROSSGUID=OFF -DENABLE_INTERNAL_UDFREAD=OFF -DENABLE_INTERNAL_SPDLOG=OFF -DENABLE_INTERNAL_RapidJSON=OFF -DENABLE_UDEV=ON -DENABLE_DBUS=ON -DENABLE_XSLT=ON -DENABLE_CCACHE=OFF -DENABLE_LIRCCLIENT=ON -DENABLE_EVENTCLIENTS=ON -DENABLE_DEBUGFISSION=OFF -DENABLE_APP_AUTONAME=OFF -DENABLE_TESTING=OFF -DENABLE_INTERNAL_FLATBUFFERS=OFF -DENABLE_LCMS2=OFF -DADDONS_CONFIGURE_AT_STARTUP=OFF -Dgroovy_SOURCE_DIR=LibreELEC.tv/build.LibreELEC-Generic.x86_64-12.0-devel/build/groovy-4.0.18 -Dapache-commons-lang_SOURCE_DIR=LibreELEC.tv/build.LibreELEC-Generic.x86_64-12.0-devel/build/commons-lang3-3.14.0 -Dapache-commons-text_SOURCE_DIR=LibreELEC.tv/build.LibreELEC-Generic.x86_64-12.0-devel/build/commons-text-1.11.0 -DUSE_LTO=16 -DENABLE_GOLD=ON -DENABLE_MOLD=OFF -DWITH_CPU=x86_64 -DENABLE_VDPAU=OFF -DENABLE_VAAPI=ON -DENABLE_CEC=ON -DCORE_PLATFORM_NAME=gbm -DAPP_RENDER_SYSTEM=gles -DENABLE_SMBCLIENT=ON -DENABLE_NFS=ON -DENABLE_DVDCSS=ON -DLIBDVDCSS_URL=LibreELEC.tv/sources/libdvdcss/libdvdcss-1.4.3-Next-Nexus-Alpha2-2.tar.gz -DLIBDVDNAV_URL=LibreELEC.tv/sources/libdvdnav/libdvdnav-6.1.1-Next-Nexus-Alpha2-2.tar.gz -DLIBDVDREAD_URL=LibreELEC.tv/sources/libdvdread/libdvdread-6.1.3-Next-Nexus-Alpha2-2.tar.gz -DENABLE_AVAHI=ON -DENABLE_UPNP=ON -DENABLE_MARIADBCLIENT=ON -DENABLE_MYSQLCLIENT=OFF -DENABLE_PLIST=ON -DENABLE_AIRTUNES=ON -DENABLE_OPTICAL=ON -DENABLE_BLURAY=ON -DENABLE_ALSA=ON -DENABLE_PULSEAUDIO=ON -DENABLE_PIPEWIRE=OFF LibreELEC.tv/build.LibreELEC-Generic.x86_64-12.0-devel/build/kodi-d4cc84f8f6bd0bba78511c78d574de13a552527f
-- Mirror download location: http://mirrors.kodi.tv
-- Source directory: LibreELEC.tv/build.LibreELEC-Generic.x86_64-12.0-devel/build/kodi-d4cc84f8f6bd0bba78511c78d574de13a552527f
-- Build directory: LibreELEC.tv/build.LibreELEC-Generic.x86_64-12.0-devel/build/kodi-d4cc84f8f6bd0bba78511c78d574de13a552527f/.x86_64-libreelec-linux-gnu
-- Generator: Single-configuration: MinSizeRel (Ninja)
-- CMake Version: 3.28.3
-- System type: Linux
-- Linker: GNU gold
-- Host architecture is little-endian
-- Core system type: linux
-- Platform: gbm
-- CPU: x86_64, ARCH: x86_64-linux
-- Cross-Compiling: TRUE
-- Execute build artefacts on host: 
-- Depends based build: 
-- statx is available
CMake Warning (dev) at cmake/modules/FindSSE.cmake:7 (exec_program):
  Policy CMP0153 is not set: The exec_program command should not be called.
  Run "cmake --help-policy CMP0153" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  Use execute_process() instead.
Call Stack (most recent call first):
  cmake/scripts/common/ArchSetup.cmake:131 (find_package)
  CMakeLists.txt:65 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Checking to see if CXX compiler accepts flag -msse
-- Checking to see if CXX compiler accepts flag -msse - yes
-- Checking to see if CXX compiler accepts flag -msse2
-- Checking to see if CXX compiler accepts flag -msse2 - yes
-- Checking to see if CXX compiler accepts flag -msse3
-- Checking to see if CXX compiler accepts flag -msse3 - yes
-- Checking to see if CXX compiler accepts flag -mssse3
-- Checking to see if CXX compiler accepts flag -mssse3 - yes
-- Checking to see if CXX compiler accepts flag -msse4.1
-- Checking to see if CXX compiler accepts flag -msse4.1 - yes
-- Checking to see if CXX compiler accepts flag -msse4.2
-- Checking to see if CXX compiler accepts flag -msse4.2 - yes
-- Checking to see if CXX compiler accepts flag -mavx
-- Checking to see if CXX compiler accepts flag -mavx - yes
-- Checking to see if CXX compiler accepts flag -mavx2
-- Checking to see if CXX compiler accepts flag -mavx2 - yes
-- Found external TexturePacker: LibreELEC.tv/build.LibreELEC-Generic.x86_64-12.0-devel/toolchain/bin/TexturePacker
-- External TexturePacker will be executed during build: LibreELEC.tv/build.LibreELEC-Generic.x86_64-12.0-devel/toolchain/bin/TexturePacker
-- Could NOT find libcec (missing: libcec_DIR)
-- Could NOT find MDNS (missing: MDNS_LIBRARY MDNS_INCLUDE_DIR) 
CMake Warning at cmake/modules/FindMicroHttpd.cmake:63 (message):
  PC_MICROHTTPD_LINK_LIBRARIES:
Call Stack (most recent call first):
  cmake/scripts/common/Macros.cmake:390 (find_package)
  cmake/scripts/common/Macros.cmake:440 (find_package_with_ver)
  CMakeLists.txt:264 (core_optional_dep)


-- Could NOT find Sndio (missing: SNDIO_LIBRARY SNDIO_INCLUDE_DIR) 
-- RapidJSON found. Headers: /usr/include
<string>:1: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
<string>:1: DeprecationWarning: The distutils.sysconfig module is deprecated, use sysconfig instead
-- #---- CONFIGURATION ----#
...

@fuzzard
Copy link
Contributor Author

fuzzard commented May 29, 2024

im guess that wasnt a clean rerun of the cmake configure. cmakecache is playing games there, so not really useful.

@garbear
Copy link
Member

garbear commented May 29, 2024

Clean build will follow in 1hr

@fuzzard
Copy link
Contributor Author

fuzzard commented May 29, 2024

Either way, the information comes from pkg-config. libmicrohttpd says it needs gnutls, gnutls isnt made available for it to statically link. Id say you'll need the libreelec guys to look into whats best

@garbear
Copy link
Member

garbear commented May 29, 2024

I've asked in their slack about static linking. In the past, the answer I received was that everything was static linked, everything, even including add-ons that ship with LE. This is probably due to performance constraints across their ecosystem of devices. I'll update if I hear back, but I think it's still safe to assume that everything is static linked for LE.

@fuzzard
Copy link
Contributor Author

fuzzard commented May 29, 2024

their gnutls package says otherwise. https://github.com/LibreELEC/LibreELEC.tv/blob/e92d34bfcad590c172292a03b2ccc6dc31180fb9/packages/security/gnutls/package.mk#L15-L28
Its at least building the shared lib (ie no --disable-shared), and shared libs generally get preference over static usage in cmake searches.

@heitbaum
Copy link
Contributor

Clean build will follow in 1hr

The libmicrohttpd is built as static (and only used by kodi)

docker@11c54a5b381d:/var/media/DATA/home-rudi/LibreELEC.tv$ git grep libmicrohttpd
packages/mediacenter/kodi/package.mk:    PKG_DEPENDS_TARGET+=" libmicrohttpd"

Here are the libraries of interest:

docker@11c54a5b381d:/var/media/DATA/home-rudi/LibreELEC.tv$ find build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/libmicrohttpd-1.0.1/ | grep lib
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/libmicrohttpd-1.0.1/
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/libmicrohttpd-1.0.1/.libreelec-package
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/libmicrohttpd-1.0.1/usr
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/libmicrohttpd-1.0.1/usr/lib
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/libmicrohttpd-1.0.1/usr/lib/libmicrohttpd.a
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/libmicrohttpd-1.0.1/usr/lib/pkgconfig
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/libmicrohttpd-1.0.1/usr/lib/pkgconfig/libmicrohttpd.pc
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/libmicrohttpd-1.0.1/usr/lib/libmicrohttpd.la
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/libmicrohttpd-1.0.1/usr/include
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/libmicrohttpd-1.0.1/usr/include/microhttpd.h

docker@11c54a5b381d:/var/media/DATA/home-rudi/LibreELEC.tv$ find build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/gnutls-3.8.5/ | grep lib
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/gnutls-3.8.5/.libreelec-package
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/gnutls-3.8.5/usr/lib
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/gnutls-3.8.5/usr/lib/libgnutls.so.30
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/gnutls-3.8.5/usr/lib/libgnutlsxx.la
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/gnutls-3.8.5/usr/lib/libgnutlsxx.so.30.0.0
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/gnutls-3.8.5/usr/lib/pkgconfig
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/gnutls-3.8.5/usr/lib/pkgconfig/gnutls.pc
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/gnutls-3.8.5/usr/lib/libgnutls.so
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/gnutls-3.8.5/usr/lib/libgnutlsxx.so
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/gnutls-3.8.5/usr/lib/libgnutls.la
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/gnutls-3.8.5/usr/lib/libgnutls.so.30.39.0
build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/gnutls-3.8.5/usr/lib/libgnutlsxx.so.30

@fuzzard
Copy link
Contributor Author

fuzzard commented May 29, 2024

Duplicating a static libmicrohttpd that is using a shared gnutls i get the following (using the above patch). It still shows the shared lib of gnutls.

CMake Error at cmake/modules/FindMicroHttpd.cmake:63 (message):
  PC_MICROHTTPD_LINK_LIBRARIES:
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/lib/libpthread.tbd;/Users/Shared/xbmc-depends/macosx14.5_arm64-target-debug/lib/libgnutls.dylib;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/lib/libz.tbd;/Users/Shared/xbmc-depends/macosx14.5_arm64-target-debug/lib/libgmp.a;-framework
  Security;-framework
  CoreFoundation;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/lib/libdl.tbd;/Users/Shared/xbmc-depends/macosx14.5_arm64-target-debug/lib/libhogweed.a;/Users/Shared/xbmc-depends/macosx14.5_arm64-target-debug/lib/libnettle.a
Call Stack (most recent call first):
  cmake/scripts/common/Macros.cmake:390 (find_package)
  cmake/scripts/common/Macros.cmake:440 (find_package_with_ver)
  CMakeLists.txt:262 (core_optional_dep)

You can see a shared library is still made available from the pkgconfig output. Kodi successfully links with correctly

MacBook-Pro-2 build % otool -L Kodi.app/Contents/MacOS/Kodi 
Kodi.app/Contents/MacOS/Kodi:
	/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
<snip>
	/System/Library/Frameworks/Metal.framework/Versions/A/Metal (compatibility version 1.0.0, current version 343.19.0)
	/System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage (compatibility version 1.0.1, current version 6.0.0)
	@executable_path/../Libraries/libgnutls.30.dylib (compatibility version 65.0.0, current version 65.2.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1345.120.2)
<snip>

Someone on the libreelec side is going to have to dig in further to whatever is happening on their side. As far as i can see, things work as intended.

@heitbaum
Copy link
Contributor

heitbaum commented May 29, 2024

I’ve done test build with HEAD and this patch - successful with the .so (not with the .a)

for interest the kodi.bin + the .do is actually smaller than that of the kodi.bin compiled against .a

232680 May 29 09:44 build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/libmicrohttpd-1.0.1/usr/lib/libmicrohttpd.so.12.62.1

359688 May 25 09:19 build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/libmicrohttpd-1.0.1/usr/lib/libmicrohttpd.a

26878992 May 29 10:24 build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/kodi-42120bb9047912b9379dadffdbdef9968062cf70/usr/lib/kodi/kodi.bin

26635528 May 29 10:02 build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/kodi-42120bb9047912b9379dadffdbdef9968062cf70/usr/lib/kodi/kodi.bin 

Kodi is 243464 smaller with the .so
Overall 10784 bytes smaller

run testing this now - have written up a draft PR to allow some testing.

@jenkins4kodi jenkins4kodi added the Rebase needed PR that does not apply/merge cleanly to current base branch label Jun 1, 2024
@jenkins4kodi
Copy link
Contributor

@fuzzard this needs a rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CMake Rebase needed PR that does not apply/merge cleanly to current base branch v22 "P"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants