@@ -95,9 +95,29 @@ endif()
9595FetchContent_MakeAvailable(SwiftFoundationICU SwiftFoundation)
9696
9797include (CheckLinkerFlag)
98+ include (CheckSymbolExists)
9899
99100check_linker_flag(C "LINKER:--build-id=sha1" LINKER_SUPPORTS_BUILD_ID)
100101
102+ # Detect if the system libc defines symbols for these functions.
103+ # If it is not availble, swift-corelibs-foundation has its own implementations
104+ # that will be used. If it is available, it should not redefine them.
105+ # Note: SwiftPM does not have the ability to introspect the contents of the SDK
106+ # and therefore will always include these functions in the build and will
107+ # cause build failures on platforms that define these functions.
108+ check_symbol_exists("strlcat" "string.h" HAVE_STRLCAT)
109+ check_symbol_exists("strlcpy" "string.h" HAVE_STRLCPY)
110+ check_symbol_exists("issetugid" "unistd.h" HAVE_ISSETUGID)
111+ add_compile_definitions (
112+ $<$<AND :$<COMPILE_LANGUAGE:C>,$<BOOL :${HAVE_STRLCAT} >>:HAVE_STRLCAT>
113+ $<$<AND :$<COMPILE_LANGUAGE:C>,$<BOOL :${HAVE_STRLCPY} >>:HAVE_STRLCPY>
114+ $<$<AND :$<COMPILE_LANGUAGE:C>,$<BOOL :${HAVE_ISSETUGID} >>:HAVE_ISSETUGID>)
115+
116+ if (CMAKE_SYSTEM_NAME STREQUAL Linux)
117+ check_symbol_exists(sched_getaffinity "sched.h" HAVE_SCHED_GETAFFINITY)
118+ add_compile_definitions ($<$<COMPILE_LANGUAGE:C>:HAVE_SCHED_GETAFFINITY>)
119+ endif ()
120+
101121# Precompute module triple for installation
102122if (NOT SwiftFoundation_MODULE_TRIPLE)
103123 set (module_triple_command "${CMAKE_Swift_COMPILER} " -print-target -info)
@@ -114,6 +134,7 @@ endif()
114134
115135# We know libdispatch is always unavailable on WASI
116136if (NOT CMAKE_SYSTEM_NAME STREQUAL WASI)
137+ find_package (LibRT)
117138 find_package (dispatch CONFIG)
118139 if (NOT dispatch_FOUND)
119140 if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android" )
0 commit comments