Skip to content

Commit 0f1edfb

Browse files
committed
build: add Darwin/macOS support
Adds platform handling for macOS: - Guard GCC-only -Wno-stringop-truncation behind a compiler check and silence Clang warnings promoted to errors by -Werror. - Wire up empty RT/SOCKET libraries and test libraries for Darwin. - Use the macOS pthread_setname_np signature (current thread only) and skip pthread_condattr_setclock(CLOCK_MONOTONIC), which is unavailable.
1 parent fd1fbf8 commit 0f1edfb

4 files changed

Lines changed: 30 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,23 @@ add_compile_options(
261261
-Wcast-qual
262262
-Wno-system-headers
263263
-Wno-unused-function
264-
-Wno-stringop-truncation
264+
$<$<C_COMPILER_ID:GNU>:-Wno-stringop-truncation>
265265
)
266266

267+
if(APPLE)
268+
# Clang on macOS is stricter than GCC on some warnings that are promoted to
269+
# errors by -Werror above. Suppress the ones triggered by current code until
270+
# the upstream sources are fixed.
271+
add_compile_options(
272+
-Wno-sign-conversion
273+
-Wno-implicit-int-conversion
274+
-Wno-shorten-64-to-32
275+
-Wno-strict-prototypes
276+
-Wno-static-in-inline
277+
-Wno-gnu-folding-constant
278+
)
279+
endif()
280+
267281
if(WITH_DOC STREQUAL "OFF")
268282
set(PACKAGE_DOC "#")
269283
else()

src/lib/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ add_library(dlt ${dlt_LIB_SRCS})
3434
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux|CYGWIN|MSYS")
3535
set(RT_LIBRARY rt)
3636
set(SOCKET_LIBRARY "")
37+
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
38+
set(RT_LIBRARY "")
39+
set(SOCKET_LIBRARY "")
3740
else()
3841
set(RT_LIBRARY "")
3942
set(SOCKET_LIBRARY socket)

src/lib/dlt_user.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3949,7 +3949,11 @@ void *dlt_user_trace_network_segmented_thread(void *unused)
39493949
/* Unused on purpose. */
39503950
(void)unused;
39513951
#ifdef DLT_USE_PTHREAD_SETNAME_NP
3952+
#ifdef __APPLE__
3953+
if (pthread_setname_np("dlt_segmented"))
3954+
#else
39523955
if (pthread_setname_np(dlt_user.dlt_segmented_nwt_handle, "dlt_segmented"))
3956+
#endif
39533957
dlt_log(LOG_WARNING, "Failed to rename segmented thread!\n");
39543958
#elif linux
39553959
if (prctl(PR_SET_NAME, "dlt_segmented", 0, 0, 0) < 0)
@@ -4835,7 +4839,11 @@ void *dlt_user_housekeeperthread_function(void *ptr)
48354839
#endif
48364840

48374841
#ifdef DLT_USE_PTHREAD_SETNAME_NP
4842+
#ifdef __APPLE__
4843+
if (pthread_setname_np("dlt_housekeeper"))
4844+
#else
48384845
if (pthread_setname_np(dlt_housekeeperthread_handle, "dlt_housekeeper"))
4846+
#endif
48394847
dlt_log(LOG_WARNING, "Failed to rename housekeeper thread!\n");
48404848
#elif linux
48414849
if (prctl(PR_SET_NAME, "dlt_housekeeper", 0, 0, 0) < 0)
@@ -7362,7 +7370,9 @@ int dlt_start_threads()
73627370
*/
73637371
pthread_condattr_t attr;
73647372
pthread_condattr_init(&attr);
7373+
#ifndef __APPLE__
73657374
pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
7375+
#endif
73667376
pthread_cond_init(&dlt_housekeeper_running_cond, &attr);
73677377

73687378
if (pthread_create(&(dlt_housekeeperthread_handle),

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux|CYGWIN")
2727
set(LIBRARIES "")
2828
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "QNX")
2929
set(LIBRARIES regex)
30+
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
31+
set(LIBRARIES "")
3032
else()
3133
set(LIBRARIES socket)
3234
endif()

0 commit comments

Comments
 (0)