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)