Skip to content

Commit 8b7cbe9

Browse files
ryandesignbagder
authored andcommitted
macOS: fix target detection more
Now SCDynamicStoreCopyProxies is called (and the required frameworks are linked in) on all versions of macOS and only on macOS. Fixes crash due to undefined symbol when built with the macOS 10.11 SDK or earlier. CURL_OSX_CALL_COPYPROXIES is renamed to CURL_MACOS_CALL_COPYPROXIES and is now only defined when SCDynamicStoreCopyProxies will actually be called. Previously, it was defined when ENABLE_IPV6 was not defined but SCDynamicStoreCopyProxies is not called in that case. TARGET_OS_OSX is only defined in the macOS 10.12 SDK and later and only when dynamic targets are enabled. TARGET_OS_MAC is always defined but means any Mac OS or derivative including macOS, iOS, tvOS, and watchOS. TARGET_OS_IPHONE means any Darwin OS other than macOS. Follow-up to c73b2f8 Fixes #11502 Closes #11516
1 parent 29bce98 commit 8b7cbe9

File tree

4 files changed

+12
-17
lines changed

4 files changed

+12
-17
lines changed

lib/curl_setup.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,9 @@
258258
#if defined(__APPLE__) && !defined(USE_ARES)
259259
#include <TargetConditionals.h>
260260
#define USE_RESOLVE_ON_IPS 1
261-
# if !defined(TARGET_OS_OSX) || TARGET_OS_OSX
262-
# define CURL_OSX_CALL_COPYPROXIES 1
261+
# if TARGET_OS_MAC && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && \
262+
defined(ENABLE_IPV6)
263+
# define CURL_MACOS_CALL_COPYPROXIES 1
263264
# endif
264265
#endif
265266

lib/macos.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,32 @@
2424

2525
#include "curl_setup.h"
2626

27-
#if defined(__APPLE__)
28-
29-
#if !defined(TARGET_OS_OSX) || TARGET_OS_OSX
27+
#ifdef CURL_MACOS_CALL_COPYPROXIES
3028

3129
#include <curl/curl.h>
3230

3331
#include "macos.h"
3432

35-
#if defined(ENABLE_IPV6) && defined(CURL_OSX_CALL_COPYPROXIES)
3633
#include <SystemConfiguration/SCDynamicStoreCopySpecific.h>
37-
#endif
3834

3935
CURLcode Curl_macos_init(void)
4036
{
41-
#if defined(ENABLE_IPV6) && defined(CURL_OSX_CALL_COPYPROXIES)
4237
{
4338
/*
4439
* The automagic conversion from IPv4 literals to IPv6 literals only
4540
* works if the SCDynamicStoreCopyProxies system function gets called
4641
* first. As Curl currently doesn't support system-wide HTTP proxies, we
4742
* therefore don't use any value this function might return.
4843
*
49-
* This function is only available on a macOS and is not needed for
50-
* IPv4-only builds, hence the conditions above.
44+
* This function is only available on macOS and is not needed for
45+
* IPv4-only builds, hence the conditions for defining
46+
* CURL_MACOS_CALL_COPYPROXIES in curl_setup.h.
5147
*/
5248
CFDictionaryRef dict = SCDynamicStoreCopyProxies(NULL);
5349
if(dict)
5450
CFRelease(dict);
5551
}
56-
#endif
5752
return CURLE_OK;
5853
}
5954

60-
#endif /* TARGET_OS_OSX */
61-
62-
#endif /* __APPLE__ */
55+
#endif

lib/macos.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
* SPDX-License-Identifier: curl
2424
*
2525
***************************************************************************/
26+
2627
#include "curl_setup.h"
2728

28-
#if defined(__APPLE__) && (!defined(TARGET_OS_OSX) || TARGET_OS_OSX)
29+
#ifdef CURL_MACOS_CALL_COPYPROXIES
2930

3031
CURLcode Curl_macos_init(void);
3132

m4/curl-sysconfig.m4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ case $host_os in
3030
AC_LANG_PROGRAM([[
3131
#include <TargetConditionals.h>
3232
]],[[
33-
#if (TARGET_OS_OSX)
33+
#if TARGET_OS_MAC && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
3434
return 0;
3535
#else
36-
#error Not a macOS
36+
#error Not macOS
3737
#endif
3838
]])
3939
],[

0 commit comments

Comments
 (0)