From 3f2988b58b1ed074b6fb71f439625ffd0e04cf9e 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 | 4 ++++ Sources/Foundation/CMakeLists.txt | 4 ++++ Sources/FoundationNetworking/CMakeLists.txt | 4 ++++ Sources/FoundationXML/CMakeLists.txt | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 62b22af84d..6c59d13120 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,10 @@ else() endif() FetchContent_MakeAvailable(SwiftFoundationICU SwiftFoundation) +include(CheckLinkerFlag) + +check_linker_flag(C "LINKER:--build-id=sha1" LINKER_SUPPORTS_BUILD_ID) + # Precompute module triple for installation if(NOT SwiftFoundation_MODULE_TRIPLE) set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info) diff --git a/Sources/Foundation/CMakeLists.txt b/Sources/Foundation/CMakeLists.txt index b591310cda..d382f15c94 100644 --- a/Sources/Foundation/CMakeLists.txt +++ b/Sources/Foundation/CMakeLists.txt @@ -171,5 +171,9 @@ set_target_properties(Foundation PROPERTIES target_link_libraries(Foundation PUBLIC swiftDispatch) +if(LINKER_SUPPORTS_BUILD_ID) + target_link_options(Foundation PRIVATE "LINKER:--build-id=sha1") +endif() + set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS Foundation) _foundation_install_target(Foundation) diff --git a/Sources/FoundationNetworking/CMakeLists.txt b/Sources/FoundationNetworking/CMakeLists.txt index 33d6872ae7..75c8505060 100644 --- a/Sources/FoundationNetworking/CMakeLists.txt +++ b/Sources/FoundationNetworking/CMakeLists.txt @@ -71,5 +71,9 @@ target_link_options(FoundationNetworking PRIVATE set_target_properties(FoundationNetworking PROPERTIES INSTALL_RPATH "$ORIGIN") +if(LINKER_SUPPORTS_BUILD_ID) + target_link_options(FoundationNetworking PRIVATE "LINKER:--build-id=sha1") +endif() + set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS FoundationNetworking) _foundation_install_target(FoundationNetworking) diff --git a/Sources/FoundationXML/CMakeLists.txt b/Sources/FoundationXML/CMakeLists.txt index e27bd67308..9640298a71 100644 --- a/Sources/FoundationXML/CMakeLists.txt +++ b/Sources/FoundationXML/CMakeLists.txt @@ -46,5 +46,9 @@ target_link_options(FoundationXML PRIVATE set_target_properties(FoundationXML PROPERTIES INSTALL_RPATH "$ORIGIN") +if(LINKER_SUPPORTS_BUILD_ID) + target_link_options(FoundationXML PRIVATE "LINKER:--build-id=sha1") +endif() + set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS FoundationXML) _foundation_install_target(FoundationXML)