From 0d198eca9fd9db7641d2cc4349fd6ed70205cd4b Mon Sep 17 00:00:00 2001 From: Alastair Houghton Date: Wed, 26 Jun 2024 13:51:54 +0100 Subject: [PATCH] [Linux] Enable build-ids. We should use build IDs on Linux so that we can identify the built artefacts, and also so that we can match them up with debug information should we choose to separate it. rdar://130582768 --- CMakeLists.txt | 3 +++ CoreFoundation/CMakeLists.txt | 4 ++++ Sources/Foundation/CMakeLists.txt | 3 +++ Sources/FoundationNetworking/CMakeLists.txt | 3 +++ Sources/FoundationXML/CMakeLists.txt | 4 ++++ 5 files changed, 17 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4dac9a46f1..4df77eb88e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,9 @@ endif() include(SwiftSupport) include(GNUInstallDirs) include(XCTest) +include(CheckLinkerFlag) + +check_linker_flag(C "LINKER:-build-id=sha1" LINKER_SUPPORTS_BUILD_ID) set(CF_DEPLOYMENT_SWIFT YES CACHE BOOL "Build for Swift" FORCE) diff --git a/CoreFoundation/CMakeLists.txt b/CoreFoundation/CMakeLists.txt index f126c2983a..c4028b4b20 100644 --- a/CoreFoundation/CMakeLists.txt +++ b/CoreFoundation/CMakeLists.txt @@ -433,6 +433,10 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) endif() endif() +if(LINKER_SUPPORTS_BUILD_ID) + target_link_options(CoreFoundation PRIVATE "LINKER:-build-id=sha1") +endif() + if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) if((NS_CURL_ASSUME_FEATURES_MISSING) OR (CURL_VERSION_STRING VERSION_LESS "7.32.0")) add_compile_definitions($<$:NS_CURL_MISSING_XFERINFOFUNCTION>) diff --git a/Sources/Foundation/CMakeLists.txt b/Sources/Foundation/CMakeLists.txt index d7a999f9b8..60248da7c0 100644 --- a/Sources/Foundation/CMakeLists.txt +++ b/Sources/Foundation/CMakeLists.txt @@ -237,6 +237,9 @@ if(CMAKE_SYSTEM_NAME STREQUAL WASI) "SHELL:-Xfrontend -public-autolink-library -Xfrontend wasi-emulated-getpid") endif() +if(LINKER_SUPPORTS_BUILD_ID) + target_link_options(Foundation PRIVATE "LINKER:-build-id=sha1") +endif() set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS Foundation) _install_target(Foundation) diff --git a/Sources/FoundationNetworking/CMakeLists.txt b/Sources/FoundationNetworking/CMakeLists.txt index ebb8dc405b..9fc73fa0cf 100644 --- a/Sources/FoundationNetworking/CMakeLists.txt +++ b/Sources/FoundationNetworking/CMakeLists.txt @@ -98,6 +98,9 @@ if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows") target_link_options(FoundationNetworking PRIVATE "SHELL:-no-toolchain-stdlib-rpath") endif() +if(LINKER_SUPPORTS_BUILD_ID) + target_link_options(FoundationNetworking PRIVATE "LINKER:-build-id=sha1") +endif() set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS FoundationNetworking) _install_target(FoundationNetworking) diff --git a/Sources/FoundationXML/CMakeLists.txt b/Sources/FoundationXML/CMakeLists.txt index a09d059417..a544e98b70 100644 --- a/Sources/FoundationXML/CMakeLists.txt +++ b/Sources/FoundationXML/CMakeLists.txt @@ -50,5 +50,9 @@ if(CMAKE_SYSTEM_NAME STREQUAL WASI) -Xcc -D_WASI_EMULATED_MMAN") endif() +if(LINKER_SUPPORTS_BUILD_ID) + target_link_options(FoundationXML PRIVATE "LINKER:-build-id=sha1") +endif() + set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS FoundationXML) _install_target(FoundationXML)