@@ -87,9 +87,29 @@ endif()
8787FetchContent_MakeAvailable(SwiftFoundationICU SwiftFoundation)
8888
8989include (CheckLinkerFlag)
90+ include (CheckSymbolExists)
9091
9192check_linker_flag(C "LINKER:--build-id=sha1" LINKER_SUPPORTS_BUILD_ID)
9293
94+ # Detect if the system libc defines symbols for these functions.
95+ # If it is not availble, swift-corelibs-foundation has its own implementations
96+ # that will be used. If it is available, it should not redefine them.
97+ # Note: SwiftPM does not have the ability to introspect the contents of the SDK
98+ # and therefore will always include these functions in the build and will
99+ # cause build failures on platforms that define these functions.
100+ check_symbol_exists("strlcat" "string.h" HAVE_STRLCAT)
101+ check_symbol_exists("strlcpy" "string.h" HAVE_STRLCPY)
102+ check_symbol_exists("issetugid" "unistd.h" HAVE_ISSETUGID)
103+ add_compile_definitions (
104+ $<$<AND :$<COMPILE_LANGUAGE:C>,$<BOOL :${HAVE_STRLCAT} >>:HAVE_STRLCAT>
105+ $<$<AND :$<COMPILE_LANGUAGE:C>,$<BOOL :${HAVE_STRLCPY} >>:HAVE_STRLCPY>
106+ $<$<AND :$<COMPILE_LANGUAGE:C>,$<BOOL :${HAVE_ISSETUGID} >>:HAVE_ISSETUGID>)
107+
108+ if (CMAKE_SYSTEM_NAME STREQUAL Linux)
109+ check_symbol_exists(sched_getaffinity "sched.h" HAVE_SCHED_GETAFFINITY)
110+ add_compile_definitions ($<$<COMPILE_LANGUAGE:C>:HAVE_SCHED_GETAFFINITY>)
111+ endif ()
112+
93113# Precompute module triple for installation
94114if (NOT SwiftFoundation_MODULE_TRIPLE)
95115 set (module_triple_command "${CMAKE_Swift_COMPILER} " -print-target -info)
@@ -103,6 +123,7 @@ if(NOT SwiftFoundation_MODULE_TRIPLE)
103123endif ()
104124
105125# System dependencies
126+ find_package (LibRT)
106127find_package (dispatch CONFIG)
107128if (NOT dispatch_FOUND)
108129 if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android" )
0 commit comments