@@ -95,9 +95,29 @@ endif()
95
95
FetchContent_MakeAvailable(SwiftFoundationICU SwiftFoundation)
96
96
97
97
include (CheckLinkerFlag)
98
+ include (CheckSymbolExists)
98
99
99
100
check_linker_flag(C "LINKER:--build-id=sha1" LINKER_SUPPORTS_BUILD_ID)
100
101
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
+
101
121
# Precompute module triple for installation
102
122
if (NOT SwiftFoundation_MODULE_TRIPLE)
103
123
set (module_triple_command "${CMAKE_Swift_COMPILER} " -print-target -info)
@@ -114,6 +134,7 @@ endif()
114
134
115
135
# We know libdispatch is always unavailable on WASI
116
136
if (NOT CMAKE_SYSTEM_NAME STREQUAL WASI)
137
+ find_package (LibRT)
117
138
find_package (dispatch CONFIG)
118
139
if (NOT dispatch_FOUND)
119
140
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android" )
0 commit comments