diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index d949e9ce89b58..924b661c8dfde 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -301,14 +301,19 @@ elseif(CLR_CMAKE_HOST_SUNOS) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector") add_definitions(-D__EXTENSIONS__ -D_XPG4_2 -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT) -elseif(CLR_CMAKE_HOST_OSX AND NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS) +elseif(CLR_CMAKE_HOST_APPLE) + # enable support for X/Open and POSIX APIs, like the header file add_definitions(-D_XOPEN_SOURCE) - - # the new linker in Xcode 15 (ld_new/ld_prime) deprecated the -bind_at_load flag for macOS which causes a warning - # that fails the build since we build with -Werror. Only pass the flag if we need it, i.e. older linkers. - check_linker_flag(C "-Wl,-bind_at_load,-fatal_warnings" LINKER_SUPPORTS_BIND_AT_LOAD_FLAG) - if(LINKER_SUPPORTS_BIND_AT_LOAD_FLAG) - add_linker_flag("-Wl,-bind_at_load") + # enable support for Darwin extension APIs, like pthread_getthreadid_np + add_definitions(-D_DARWIN_C_SOURCE) + + if(CLR_CMAKE_HOST_OSX) + # the new linker in Xcode 15 (ld_new/ld_prime) deprecated the -bind_at_load flag for macOS which causes a warning + # that fails the build since we build with -Werror. Only pass the flag if we need it, i.e. older linkers. + check_linker_flag(C "-Wl,-bind_at_load,-fatal_warnings" LINKER_SUPPORTS_BIND_AT_LOAD_FLAG) + if(LINKER_SUPPORTS_BIND_AT_LOAD_FLAG) + add_linker_flag("-Wl,-bind_at_load") + endif() endif() elseif(CLR_CMAKE_HOST_HAIKU) add_compile_options($<$:-Wa,--noexecstack>) diff --git a/src/coreclr/nativeaot/CMakeLists.txt b/src/coreclr/nativeaot/CMakeLists.txt index 74ee982ab9805..20deb87a60bb1 100644 --- a/src/coreclr/nativeaot/CMakeLists.txt +++ b/src/coreclr/nativeaot/CMakeLists.txt @@ -20,7 +20,6 @@ if(CLR_CMAKE_HOST_UNIX) add_compile_options(-nostdlib) if(CLR_CMAKE_TARGET_APPLE) - add_definitions(-D_XOPEN_SOURCE) add_definitions(-DFEATURE_OBJCMARSHAL) endif(CLR_CMAKE_TARGET_APPLE) diff --git a/src/native/libs/System.Native/CMakeLists.txt b/src/native/libs/System.Native/CMakeLists.txt index ea059b923e057..7712f25560202 100644 --- a/src/native/libs/System.Native/CMakeLists.txt +++ b/src/native/libs/System.Native/CMakeLists.txt @@ -4,10 +4,6 @@ if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CM add_definitions(-DHAS_CONSOLE_SIGNALS) endif () -if (CLR_CMAKE_TARGET_OSX) - add_definitions(-D_DARWIN_C_SOURCE) -endif () - set(NATIVE_SOURCES pal_errno.c pal_interfaceaddresses.c