From 8ae07945845eab0cb350d6f72bd6eb5a12766114 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 29 Apr 2021 22:58:05 +0200 Subject: [PATCH] CMake: Fix building libraries on macOS When building libraries on macOS they'd be missing the SONAME attribute which causes the linker to embed relative paths into other libraries and executables: Dynamic section at offset 0x52794 contains 28 entries: Type Name/Value (NEEDED) Shared library: [libgcc_s.so] (NEEDED) Shared library: [Userland/Libraries/LibCrypt/libcrypt.so] (NEEDED) Shared library: [Userland/Libraries/LibCrypto/libcrypto.so] (NEEDED) Shared library: [Userland/Libraries/LibC/libc.so] (NEEDED) Shared library: [libsystem.so] (NEEDED) Shared library: [libm.so] (NEEDED) Shared library: [libc.so] The dynamic linker then fails to load those libraries which makes the system unbootable. --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 88bca2e1f9f..a4b186cad2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,9 +140,10 @@ foreach(lang ASM C CXX OBJC OBJCXX) unset(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG) unset(CMAKE_${lang}_SYSROOT_FLAG) if (CMAKE_SYSTEM_NAME MATCHES Darwin) - ## MacOS Workaround. Don't generate install_name flag when cross compiling + ## macOS workaround. Use GNU ld flags for SONAMEs. set(CMAKE_${lang}_CREATE_SHARED_LIBRARY - " -o ") + " -o ") + set(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG "-Wl,-soname,") endif() endforeach()