Skip to content

Commit f3d3cb1

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 cb3fec8 commit f3d3cb1

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

CMakeLists.txt

+21
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,29 @@ endif()
7777
FetchContent_MakeAvailable(SwiftFoundationICU SwiftFoundation)
7878

7979
include(CheckLinkerFlag)
80+
include(CheckSymbolExists)
8081

8182
check_linker_flag(C "LINKER:--build-id=sha1" LINKER_SUPPORTS_BUILD_ID)
8283

84+
check_symbol_exists("strlcat" "string.h" HAVE_STRLCAT)
85+
check_symbol_exists("strlcpy" "string.h" HAVE_STRLCPY)
86+
check_symbol_exists("issetugid" "unistd.h" HAVE_ISSETUGID)
87+
add_compile_definitions(
88+
$<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_STRLCAT}>>:HAVE_STRLCAT>
89+
$<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_STRLCPY}>>:HAVE_STRLCPY>
90+
$<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_ISSETUGID}>>:HAVE_ISSETUGID>)
91+
92+
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR ANDROID)
93+
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:_GNU_SOURCE>)
94+
endif()
95+
96+
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
97+
check_symbol_exists(sched_getaffinity "sched.h" HAVE_SCHED_GETAFFINITY)
98+
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:HAVE_SCHED_GETAFFINITY>)
99+
endif()
100+
101+
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fblocks>)
102+
83103
# Precompute module triple for installation
84104
if(NOT SwiftFoundation_MODULE_TRIPLE)
85105
set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info)
@@ -93,6 +113,7 @@ if(NOT SwiftFoundation_MODULE_TRIPLE)
93113
endif()
94114

95115
# System dependencies
116+
find_package(LibRT)
96117
find_package(dispatch CONFIG)
97118
if(NOT dispatch_FOUND)
98119
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")

cmake/modules/FindLibRT.cmake

+1-1
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)