Skip to content

Commit 1bd5574

Browse files
committed
Bring back defines and flags
Several definitions and flags were dropped from the build when moving to swift-froundation. This patch puts back the ones that we need in order to build against musl. Since the musl builds are static, we also need to pick up the link to libRT or dispatch will fail to link.
1 parent 951f353 commit 1bd5574

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,29 @@ endif()
9595
FetchContent_MakeAvailable(SwiftFoundationICU SwiftFoundation)
9696

9797
include(CheckLinkerFlag)
98+
include(CheckSymbolExists)
9899

99100
check_linker_flag(C "LINKER:--build-id=sha1" LINKER_SUPPORTS_BUILD_ID)
100101

102+
check_symbol_exists("strlcat" "string.h" HAVE_STRLCAT)
103+
check_symbol_exists("strlcpy" "string.h" HAVE_STRLCPY)
104+
check_symbol_exists("issetugid" "unistd.h" HAVE_ISSETUGID)
105+
add_compile_definitions(
106+
$<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_STRLCAT}>>:HAVE_STRLCAT>
107+
$<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_STRLCPY}>>:HAVE_STRLCPY>
108+
$<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_ISSETUGID}>>:HAVE_ISSETUGID>)
109+
110+
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR ANDROID)
111+
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:_GNU_SOURCE>)
112+
endif()
113+
114+
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
115+
check_symbol_exists(sched_getaffinity "sched.h" HAVE_SCHED_GETAFFINITY)
116+
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:HAVE_SCHED_GETAFFINITY>)
117+
endif()
118+
119+
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fblocks>)
120+
101121
# Precompute module triple for installation
102122
if(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
116136
if(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")

cmake/modules/FindLibRT.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Find librt library and headers.
66
#
7-
# The mdoule defines the following variables:
7+
# The module defines the following variables:
88
#
99
# ::
1010
#

0 commit comments

Comments
 (0)