Skip to content

Commit e10529d

Browse files
authored
Merge pull request #3038 from apple/maxd/cf-wasi-unavailable
WASI: Make some sources unavailable in CF CMake
2 parents c5b61f6 + eeaf5a9 commit e10529d

File tree

1 file changed

+84
-47
lines changed

1 file changed

+84
-47
lines changed

CoreFoundation/CMakeLists.txt

Lines changed: 84 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,23 @@ endif()
2020

2121
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
2222

23-
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
24-
set(THREADS_PREFER_PTHREAD_FLAG OFF)
25-
find_package(Threads REQUIRED)
23+
24+
if(HAS_LIBDISPATCH_API)
25+
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
26+
set(THREADS_PREFER_PTHREAD_FLAG OFF)
27+
find_package(Threads REQUIRED)
28+
endif()
2629

2730
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
2831
find_package(LibXml2 REQUIRED)
29-
find_package(CURL CONFIG)
30-
if(CURL_FOUND)
31-
set(CURL_VERSION_STRING ${CURL_VERSION})
32-
else()
33-
find_package(CURL REQUIRED)
32+
33+
if(BUILD_NETWORKING)
34+
find_package(CURL CONFIG)
35+
if(CURL_FOUND)
36+
set(CURL_VERSION_STRING ${CURL_VERSION})
37+
else()
38+
find_package(CURL REQUIRED)
39+
endif()
3440
endif()
3541
find_package(ICU COMPONENTS uc i18n REQUIRED)
3642
endif()
@@ -115,6 +121,38 @@ else()
115121
set(FRAMEWORK_LIBRARY_TYPE STATIC)
116122
endif()
117123

124+
set(CF_WASI_UNAVAILABLE_SOURCES)
125+
126+
if(NOT CMAKE_SYSTEM_NAME STREQUAL WASI)
127+
list(APPEND CF_WASI_UNAVAILABLE_SOURCES
128+
# PlugIn
129+
PlugIn.subproj/CFBundle_Binary.c
130+
PlugIn.subproj/CFBundle.c
131+
PlugIn.subproj/CFBundle_DebugStrings.c
132+
PlugIn.subproj/CFBundle_Executable.c
133+
PlugIn.subproj/CFBundle_Grok.c
134+
PlugIn.subproj/CFBundle_InfoPlist.c
135+
PlugIn.subproj/CFBundle_Locale.c
136+
PlugIn.subproj/CFBundle_Main.c
137+
PlugIn.subproj/CFBundle_ResourceFork.c
138+
PlugIn.subproj/CFBundle_Resources.c
139+
PlugIn.subproj/CFBundle_SplitFileName.c
140+
PlugIn.subproj/CFBundle_Strings.c
141+
PlugIn.subproj/CFBundle_Tables.c
142+
PlugIn.subproj/CFPlugIn.c
143+
# Preferences
144+
Preferences.subproj/CFApplicationPreferences.c
145+
Preferences.subproj/CFPreferences.c
146+
Preferences.subproj/CFXMLPreferencesDomain.c
147+
# RunLoop
148+
RunLoop.subproj/CFRunLoop.c
149+
RunLoop.subproj/CFSocket.c
150+
# Stream
151+
Stream.subproj/CFConcreteStreams.c
152+
Stream.subproj/CFSocketStream.c
153+
Stream.subproj/CFStream.c)
154+
endif()
155+
118156
add_framework(CoreFoundation
119157
${FRAMEWORK_LIBRARY_TYPE}
120158
FRAMEWORK_DIRECTORY
@@ -202,7 +240,6 @@ add_framework(CoreFoundation
202240
Locale.subproj/CFDateInterval.h
203241
Locale.subproj/CFLocaleInternal.h
204242
PlugIn.subproj/CFBundlePriv.h
205-
Stream.subproj/CFStreamPriv.h
206243
String.subproj/CFCharacterSetPriv.h
207244
String.subproj/CFRegularExpression.h
208245
String.subproj/CFRunArray.h
@@ -257,6 +294,7 @@ add_framework(CoreFoundation
257294
RunLoop.subproj/CFRunLoop.h
258295
RunLoop.subproj/CFSocket.h
259296
# Stream
297+
Stream.subproj/CFStreamPriv.h
260298
Stream.subproj/CFStream.h
261299
# String
262300
String.subproj/CFAttributedString.h
@@ -312,36 +350,11 @@ add_framework(CoreFoundation
312350
Parsing.subproj/CFBinaryPList.c
313351
Parsing.subproj/CFOldStylePList.c
314352
Parsing.subproj/CFPropertyList.c
315-
# PlugIn
316-
PlugIn.subproj/CFBundle_Binary.c
317-
PlugIn.subproj/CFBundle.c
318-
PlugIn.subproj/CFBundle_DebugStrings.c
319-
PlugIn.subproj/CFBundle_Executable.c
320-
PlugIn.subproj/CFBundle_Grok.c
321-
PlugIn.subproj/CFBundle_InfoPlist.c
322-
PlugIn.subproj/CFBundle_Locale.c
323-
PlugIn.subproj/CFBundle_Main.c
324-
PlugIn.subproj/CFBundle_ResourceFork.c
325-
PlugIn.subproj/CFBundle_Resources.c
326-
PlugIn.subproj/CFBundle_SplitFileName.c
327-
PlugIn.subproj/CFBundle_Strings.c
328-
PlugIn.subproj/CFBundle_Tables.c
329-
PlugIn.subproj/CFPlugIn.c
330-
# Preferences
331-
Preferences.subproj/CFApplicationPreferences.c
332-
Preferences.subproj/CFPreferences.c
333-
Preferences.subproj/CFXMLPreferencesDomain.c
334353
# RunLoop
335354
# TODO(compnerd) make this empty on non-Mach targets
336355
# RunLoop.subproj/CFMachPort.c
337356
# RunLoop.subproj/CFMachPort_Lifetime.c
338357
# RunLoop.subproj/CFMessagePort.c
339-
RunLoop.subproj/CFRunLoop.c
340-
RunLoop.subproj/CFSocket.c
341-
# Stream
342-
Stream.subproj/CFConcreteStreams.c
343-
Stream.subproj/CFSocketStream.c
344-
Stream.subproj/CFStream.c
345358
# String
346359
String.subproj/CFAttributedString.c
347360
String.subproj/CFBurstTrie.c
@@ -369,7 +382,9 @@ add_framework(CoreFoundation
369382
URL.subproj/CFURLAccess.c
370383
URL.subproj/CFURL.c
371384
URL.subproj/CFURLComponents.c
372-
URL.subproj/CFURLComponents_URIParser.c)
385+
URL.subproj/CFURLComponents_URIParser.c
386+
387+
${CF_WASI_UNAVAILABLE_SOURCES})
373388
target_compile_definitions(CoreFoundation
374389
PRIVATE
375390
$<$<COMPILE_LANGUAGE:ASM>:CF_CHARACTERSET_BITMAP="CharacterSets/CFCharacterSetBitmaps.bitmap">
@@ -379,11 +394,27 @@ target_compile_definitions(CoreFoundation
379394
target_include_directories(CoreFoundation
380395
PRIVATE
381396
${PROJECT_SOURCE_DIR})
397+
382398
target_link_libraries(CoreFoundation PRIVATE
383-
Threads::Threads
384399
${CMAKE_DL_LIBS}
385-
BlocksRuntime
386-
dispatch)
400+
BlocksRuntime)
401+
402+
if(HAS_LIBDISPATCH_API)
403+
target_link_libraries(CoreFoundation PRIVATE
404+
Threads::Threads
405+
dispatch)
406+
endif()
407+
408+
if(NOT BUILD_SHARED_LIBS)
409+
set_property(TARGET CoreFoundation PROPERTY STATIC_LIBRARY_OPTIONS
410+
$<TARGET_OBJECTS:BlocksRuntime>)
411+
endif()
412+
413+
if(CMAKE_SYSTEM_NAME STREQUAL WASI)
414+
# Enable emulated mman and constant CFSTRINGS
415+
target_compile_definitions(CoreFoundation PRIVATE _WASI_EMULATED_MMAN __CONSTANT_CFSTRINGS__)
416+
endif()
417+
387418
if(CMAKE_SYSTEM_NAME STREQUAL Android)
388419
target_link_libraries(CoreFoundation PRIVATE
389420
log)
@@ -422,7 +453,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
422453
PRIVATE
423454
CURL_STATICLIB)
424455
endif()
425-
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
456+
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin AND BUILD_NETWORKING)
426457
target_link_libraries(CFURLSessionInterface PRIVATE
427458
CURL::libcurl)
428459
endif()
@@ -440,6 +471,8 @@ add_framework(CFXMLInterface
440471
SOURCES
441472
Parsing.subproj/CFXMLInterface.c)
442473
add_dependencies(CFXMLInterface CoreFoundation)
474+
target_link_libraries(CFXMLInterface PRIVATE BlocksRuntime)
475+
443476
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
444477
target_link_libraries(CFXMLInterface PRIVATE
445478
LibXml2::LibXml2)
@@ -494,15 +527,19 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_SYSTEM_NAME STREQUAL Dar
494527
PRIVATE
495528
m)
496529
endif()
497-
target_link_libraries(CoreFoundation
498-
PRIVATE
499-
dispatch)
500-
target_link_libraries(CFURLSessionInterface
501-
PRIVATE
502-
dispatch)
503-
target_link_libraries(CFXMLInterface
504-
PRIVATE
530+
531+
if(HAS_LIBDISPATCH_API)
532+
target_link_libraries(CoreFoundation
533+
PRIVATE
534+
dispatch)
535+
target_link_libraries(CFURLSessionInterface
536+
PRIVATE
537+
dispatch)
538+
target_link_libraries(CFXMLInterface
539+
PRIVATE
505540
dispatch)
541+
endif()
542+
506543
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
507544
target_link_libraries(CoreFoundation
508545
PRIVATE

0 commit comments

Comments
 (0)