Skip to content

Commit f3531a2

Browse files
authored
Merge pull request #319 from Rogiel/feature/freebsd-support
Add support for building libdispatch on FreeBSD
2 parents 8b72f76 + 6436a89 commit f3531a2

33 files changed

+178
-72
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ option(BUILD_SHARED_LIBS "build shared libraries" ON)
8383
option(ENABLE_TESTING "build libdispatch tests" ON)
8484

8585
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR
86+
CMAKE_SYSTEM_NAME STREQUAL FreeBSD OR
8687
CMAKE_SYSTEM_NAME STREQUAL Android)
8788
set(USE_GOLD_LINKER_DEFAULT ON)
8889
else()
@@ -95,6 +96,7 @@ set(DISPATCH_USE_THREAD_LOCAL_STORAGE ${ENABLE_THREAD_LOCAL_STORAGE})
9596

9697
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR
9798
CMAKE_SYSTEM_NAME STREQUAL Android OR
99+
CMAKE_SYSTEM_NAME STREQUAL FreeBSD OR
98100
CMAKE_SYSTEM_NAME STREQUAL Windows)
99101
set(ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT ON)
100102
else()
@@ -120,6 +122,7 @@ option(INSTALL_PRIVATE_HEADERS "installs private headers in the same location as
120122

121123
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR
122124
CMAKE_SYSTEM_NAME STREQUAL Android OR
125+
CMAKE_SYSTEM_NAME STREQUAL FreeBSD OR
123126
CMAKE_SYSTEM_NAME STREQUAL Windows)
124127
add_library(BlocksRuntime
125128
STATIC
@@ -264,6 +267,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL Android)
264267
set(ENABLE_DTRACE_DEFAULT OFF)
265268
endif()
266269

270+
if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
271+
add_definitions(-D_WITH_DPRINTF)
272+
endif()
273+
267274
if(ENABLE_DTRACE STREQUAL "")
268275
find_program(dtrace_EXECUTABLE dtrace)
269276
if(dtrace_EXECUTABLE)

cmake/config.h.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@
139139
#cmakedefine HAVE_PTHREAD_MACHDEP_H
140140

141141
/* Define to 1 if you have the `pthread_main_np' function. */
142-
#cmakedefine HAVE_PTHREAD_MAIN_NP
142+
#cmakedefine01 HAVE_PTHREAD_MAIN_NP
143143

144144
/* Define to 1 if you have the <pthread_np.h> header file. */
145-
#cmakedefine HAVE_PTHREAD_NP_H
145+
#cmakedefine01 HAVE_PTHREAD_NP_H
146146

147147
/* Define to 1 if you have the <pthread/qos.h> header file. */
148148
#cmakedefine HAVE_PTHREAD_QOS_H

dispatch/base.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@
112112
#define DISPATCH_LINUX_UNAVAILABLE()
113113
#endif
114114

115+
#ifdef __FreeBSD__
116+
#define DISPATCH_FREEBSD_UNAVAILABLE() \
117+
DISPATCH_UNAVAILABLE_MSG( \
118+
"This interface is unavailable on FreeBSD systems")
119+
#else
120+
#define DISPATCH_FREEBSD_UNAVAILABLE()
121+
#endif
122+
115123
#ifndef DISPATCH_ALIAS_V2
116124
#if TARGET_OS_MAC
117125
#define DISPATCH_ALIAS_V2(sym) __asm__("_" #sym "$V2")

dispatch/dispatch.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
#include <os/availability.h>
2727
#include <TargetConditionals.h>
2828
#include <os/base.h>
29-
#elif defined(__linux__)
30-
#include <os/linux_base.h>
29+
#elif defined(__linux__) || defined(__FreeBSD__)
30+
#include <os/generic_unix_base.h>
3131
#endif
3232

3333
#include <sys/types.h>
@@ -40,7 +40,7 @@
4040
#endif
4141
#include <fcntl.h>
4242

43-
#if defined(__linux__) && defined(__has_feature)
43+
#if (defined(__linux__) || defined(__FreeBSD__)) && defined(__has_feature)
4444
#if __has_feature(modules)
4545
#if !defined(__arm__)
4646
#include <stdio.h> // for off_t (to match Glibc.modulemap)

os/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
install(FILES
66
object.h
7-
linux_base.h
7+
generic_unix_base.h
88
DESTINATION
99
"${INSTALL_OS_HEADERS_DIR}")
1010

os/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ endif
1010

1111
os_HEADERS= \
1212
object.h \
13-
linux_base.h
13+
generic_unix_base.h
1414

1515
noinst_HEADERS= \
1616
object_private.h \

os/linux_base.h renamed to os/generic_unix_base.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@
1010
*
1111
*/
1212

13-
#ifndef __OS_LINUX_BASE__
14-
#define __OS_LINUX_BASE__
13+
#ifndef __OS_GENERIC_UNIX_BASE__
14+
#define __OS_GENERIC_UNIX_BASE__
1515

1616
#if __has_include(<sys/sysmacros.h>)
1717
#include <sys/sysmacros.h>
1818
#endif
19+
20+
#if defined(__FreeBSD__)
21+
#include <libutil.h>
22+
#include <fcntl.h>
23+
#endif
1924
#include <sys/param.h>
2025

2126
#if __has_include(<sys/cdefs.h>)
@@ -120,4 +125,4 @@ enum { __VA_ARGS__ }; typedef _type _name##_t
120125
#endif
121126
#define OS_NOTHROW
122127

123-
#endif /* __OS_LINUX_BASE__ */
128+
#endif /* __OS_GENERIC_UNIX_BASE__ */

os/object.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
#include <os/availability.h>
2727
#include <TargetConditionals.h>
2828
#include <os/base.h>
29-
#elif defined(__linux__)
30-
#include <os/linux_base.h>
29+
#elif defined(__linux__) || defined(__FreeBSD__)
30+
#include <os/generic_unix_base.h>
3131
#endif
3232

3333
/*!

os/voucher_activity_private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <mach/mach_time.h>
2727
#include <firehose/tracepoint_private.h>
2828
#endif
29-
#ifndef __linux__
29+
#if __APPLE__
3030
#include <os/base.h>
3131
#include <os/availability.h>
3232
#endif

os/voucher_private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#ifndef __OS_VOUCHER_PRIVATE__
2222
#define __OS_VOUCHER_PRIVATE__
2323

24-
#ifndef __linux__
24+
#if __APPLE__
2525
#include <os/base.h>
2626
#include <os/availability.h>
2727
#endif

0 commit comments

Comments
 (0)