Skip to content

Commit c772413

Browse files
committed
Introduce Cmake support for SwiftCorelibsFoundation
1 parent fbbe6fa commit c772413

File tree

127 files changed

+840
-148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+840
-148
lines changed

CMakeLists.txt

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0
7+
##
8+
## See LICENSE.txt for license information
9+
## See CONTRIBUTORS.md for the list of Swift project authors
10+
##
11+
## SPDX-License-Identifier: Apache-2.0
12+
##
13+
##===----------------------------------------------------------------------===##
14+
15+
cmake_minimum_required(VERSION 3.24)
16+
17+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
18+
19+
if(POLICY CMP0156)
20+
# Deduplicate linked libraries where appropriate
21+
cmake_policy(SET CMP0156 NEW)
22+
endif()
23+
24+
if(POLICY CMP0157)
25+
# New Swift build model: improved incremental build performance and LSP support
26+
cmake_policy(SET CMP0157 NEW)
27+
endif()
28+
29+
if (NOT DEFINED CMAKE_C_COMPILER)
30+
set(CMAKE_C_COMPILER clang)
31+
endif()
32+
33+
project(Foundation
34+
LANGUAGES C Swift)
35+
36+
if(NOT SWIFT_SYSTEM_NAME)
37+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
38+
set(SWIFT_SYSTEM_NAME macosx)
39+
else()
40+
set(SWIFT_SYSTEM_NAME "$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
41+
endif()
42+
endif()
43+
44+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
45+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
46+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
47+
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
48+
49+
# Fetchable dependcies
50+
include(FetchContent)
51+
if (_SwiftFoundationICU_SourceDIR)
52+
FetchContent_Declare(SwiftFoundationICU
53+
SOURCE_DIR ${_SwiftFoundationICU_SourceDIR})
54+
else()
55+
FetchContent_Declare(SwiftFoundationICU
56+
GIT_REPOSITORY https://github.com/apple/swift-foundation-icu.git
57+
GIT_TAG 0.0.8)
58+
endif()
59+
60+
if (_SwiftFoundation_SourceDIR)
61+
FetchContent_Declare(SwiftFoundation
62+
SOURCE_DIR ${_SwiftFoundation_SourceDIR})
63+
else()
64+
FetchContent_Declare(SwiftFoundation
65+
GIT_REPOSITORY https://github.com/apple/swift-foundation.git
66+
GIT_TAG main)
67+
endif()
68+
FetchContent_MakeAvailable(SwiftFoundationICU SwiftFoundation)
69+
70+
# Precompute module triple for installation
71+
if(NOT SwiftFoundation_MODULE_TRIPLE)
72+
set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info)
73+
if(CMAKE_Swift_COMPILER_TARGET)
74+
list(APPEND module_triple_command -target ${CMAKE_Swift_COMPILER_TARGET})
75+
endif()
76+
execute_process(COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json)
77+
string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple")
78+
set(SwiftFoundation_MODULE_TRIPLE "${module_triple}" CACHE STRING "swift module triple used for installed swiftmodule and swiftinterface files")
79+
mark_as_advanced(SwiftFoundation_MODULE_TRIPLE)
80+
endif()
81+
82+
# System dependencies (fail fast if dependencies are missing)
83+
find_package(LibXml2 REQUIRED)
84+
find_package(CURL REQUIRED)
85+
find_package(dispatch CONFIG REQUIRED)
86+
87+
# Common build flags (_CFURLSessionInterface, _CFXMLInterface, CoreFoundation)
88+
list(APPEND _Foundation_common_build_flags
89+
"-DDEPLOYMENT_RUNTIME_SWIFT"
90+
"-DCF_BUILDING_CF"
91+
"-DDEPLOYMENT_ENABLE_LIBDISPATCH"
92+
"-DHAVE_STRUCT_TIMESPEC"
93+
"-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS"
94+
"-Wno-shorten-64-to-32"
95+
"-Wno-deprecated-declarations"
96+
"-Wno-unreachable-code"
97+
"-Wno-conditional-uninitialized"
98+
"-Wno-unused-variable"
99+
"-Wno-unused-function"
100+
"-Wno-microsoft-enum-forward-reference"
101+
"-fconstant-cfstrings"
102+
"-fexceptions" # TODO: not on OpenBSD
103+
"-fdollars-in-identifiers"
104+
"-fno-common"
105+
"-fcf-runtime-abi=swift"
106+
"-fblocks")
107+
108+
if(CMAKE_BUILD_TYPE STREQUAL Debug)
109+
list(APPEND _Foundation_common_build_flags
110+
"-DDEBUG")
111+
endif()
112+
113+
# Swift build flags (Foundation, FoundationNetworking, FoundationXML)
114+
set(_Foundation_swift_build_flags)
115+
list(APPEND _Foundation_swift_build_flags
116+
"-DDEPLOYMENT_RUNTIME_SWIFT"
117+
"-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS")
118+
119+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
120+
list(APPEND _Foundation_common_build_flags
121+
"-D_GNU_SOURCE"
122+
"-I/usr/lib/swift") # dispatch
123+
endif()
124+
125+
include(FoundationSwiftSupport)
126+
127+
add_subdirectory(Sources)
128+
add_subdirectory(cmake/modules)

Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ let package = Package(
7878
dependencies: [
7979
.package(
8080
url: "https://github.com/apple/swift-foundation-icu",
81-
from: "0.0.5"
81+
from: "0.0.7"
8282
),
8383
.package(
8484
url: "https://github.com/apple/swift-foundation",
@@ -121,7 +121,7 @@ let package = Package(
121121
.target(
122122
name: "_CoreFoundation",
123123
dependencies: [
124-
.product(name: "FoundationICU", package: "swift-foundation-icu"),
124+
.product(name: "_FoundationICU", package: "swift-foundation-icu"),
125125
],
126126
path: "Sources/CoreFoundation",
127127
cSettings: coreFoundationBuildSettings

Sources/CMakeLists.txt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0
7+
##
8+
## See LICENSE.txt for license information
9+
## See CONTRIBUTORS.md for the list of Swift project authors
10+
##
11+
## SPDX-License-Identifier: Apache-2.0
12+
##
13+
##===----------------------------------------------------------------------===##
14+
15+
add_subdirectory(CoreFoundation)
16+
add_subdirectory(_CFXMLInterface)
17+
add_subdirectory(_CFURLSessionInterface)
18+
add_subdirectory(Foundation)
19+
add_subdirectory(FoundationXML)
20+
add_subdirectory(FoundationNetworking)

Sources/CoreFoundation/CFBundle_Locale.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
#include "CFPreferences.h"
1616

1717
#if __HAS_APPLE_ICU__
18-
#include <unicode/ualoc.h>
18+
#include <_foundation_unicode/ualoc.h>
1919
#endif
20-
#include <unicode/uloc.h>
20+
#include <_foundation_unicode/uloc.h>
2121
#include <ctype.h>
2222

2323
static CFStringRef _CFBundleCopyLanguageFoundInLocalizations(CFArrayRef localizations, CFStringRef language);

Sources/CoreFoundation/CFCharacterSet.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include <stdlib.h>
2121
#include <string.h>
2222
#include "CFPriv.h"
23-
#include <unicode/uchar.h>
24-
#include <unicode/uset.h>
23+
#include <_foundation_unicode/uchar.h>
24+
#include <_foundation_unicode/uset.h>
2525

2626
#define BITSPERBYTE 8 /* (CHAR_BIT * sizeof(unsigned char)) */
2727
#define LOG_BPB 3

Sources/CoreFoundation/CFDateIntervalFormatter.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "CFLocale.h"
2121
#include "CFTimeZone.h"
2222

23-
#include <unicode/udateintervalformat.h>
23+
#include <_foundation_unicode/udateintervalformat.h>
2424

2525
#if TARGET_OS_WASI
2626
#define LOCK() do {} while (0)

Sources/CoreFoundation/CFICUConverters.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include "CFICUConverters.h"
1414
#include "CFStringEncodingExt.h"
1515
#include "CFUniChar.h"
16-
#include <unicode/ucnv.h>
17-
#include <unicode/uversion.h>
16+
#include <_foundation_unicode/ucnv.h>
17+
#include <_foundation_unicode/uversion.h>
1818
#include "CFInternal.h"
1919
#include <stdio.h>
2020

Sources/CoreFoundation/CFLocale.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424
#include "CFLocaleInternal.h"
2525
#include <stdatomic.h>
2626
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WASI
27-
#include <unicode/uloc.h> // ICU locales
28-
#include <unicode/ulocdata.h> // ICU locale data
29-
#include <unicode/ucal.h>
30-
#include <unicode/ucurr.h> // ICU currency functions
31-
#include <unicode/uset.h> // ICU Unicode sets
32-
#include <unicode/putil.h> // ICU low-level utilities
33-
#include <unicode/umsg.h> // ICU message formatting
34-
#include <unicode/ucol.h>
35-
#include <unicode/unumsys.h> // ICU numbering systems
36-
#include <unicode/uvernum.h>
37-
#if U_ICU_VERSION_MAJOR_NUM > 53 && __has_include(<unicode/uameasureformat.h>)
38-
#include <unicode/uameasureformat.h>
27+
#include <_foundation_unicode/uloc.h> // ICU locales
28+
#include <_foundation_unicode/ulocdata.h> // ICU locale data
29+
#include <_foundation_unicode/ucal.h>
30+
#include <_foundation_unicode/ucurr.h> // ICU currency functions
31+
#include <_foundation_unicode/uset.h> // ICU Unicode sets
32+
#include <_foundation_unicode/putil.h> // ICU low-level utilities
33+
#include <_foundation_unicode/umsg.h> // ICU message formatting
34+
#include <_foundation_unicode/ucol.h>
35+
#include <_foundation_unicode/unumsys.h> // ICU numbering systems
36+
#include <_foundation_unicode/uvernum.h>
37+
#if U_ICU_VERSION_MAJOR_NUM > 53 && __has_include(<_foundation_unicode/uameasureformat.h>)
38+
#include <_foundation_unicode/uameasureformat.h>
3939

4040
extern int32_t
4141
uameasfmt_getUnitsForUsage( const char* locale,
@@ -1745,7 +1745,7 @@ static bool __CFLocaleCopyTemperatureUnit(CFLocaleRef locale, bool user, CFTypeR
17451745
if (!done) {
17461746
char localeID[ULOC_FULLNAME_CAPACITY+ULOC_KEYWORD_AND_VALUES_CAPACITY];
17471747
if (CFStringGetCString(locale->_identifier, localeID, sizeof(localeID)/sizeof(char), kCFStringEncodingASCII)) {
1748-
#if U_ICU_VERSION_MAJOR_NUM > 53 && __has_include(<unicode/uameasureformat.h>)
1748+
#if U_ICU_VERSION_MAJOR_NUM > 53 && __has_include(<_foundation_unicode/uameasureformat.h>)
17491749
UErrorCode icuStatus = U_ZERO_ERROR;
17501750
UAMeasureUnit unit;
17511751
int32_t unitCount = uameasfmt_getUnitsForUsage(localeID, "temperature", "weather", &unit, 1, &icuStatus);

Sources/CoreFoundation/CFLocaleIdentifier.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#include <stdlib.h>
6060
#include <stdio.h>
6161
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
62-
#include <unicode/uloc.h>
62+
#include <_foundation_unicode/uloc.h>
6363
#else
6464
#define ULOC_KEYWORD_SEPARATOR '@'
6565
#define ULOC_FULLNAME_CAPACITY 56

Sources/CoreFoundation/CFRegularExpression.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "CFInternal.h"
1616
#define U_SHOW_DRAFT_API 1
1717
#define U_SHOW_INTERNAL_API 1
18-
#include <unicode/uregex.h>
18+
#include <_foundation_unicode/uregex.h>
1919

2020
#define STACK_BUFFER_SIZE 256
2121

Sources/CoreFoundation/CFString.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "CFString_Internal.h"
2828
#include "CFRuntime_Internal.h"
2929
#include <assert.h>
30-
#include <unicode/uchar.h>
30+
#include <_foundation_unicode/uchar.h>
3131
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
3232
#include "CFConstantKeys.h"
3333
#include "CFStringLocalizedFormattingInternal.h"

Sources/CoreFoundation/CFStringTransform.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "CFUniChar.h"
2020
#include "CFPriv.h"
2121
#include "CFInternal.h"
22-
#include <unicode/utrans.h>
22+
#include <_foundation_unicode/utrans.h>
2323

2424
static const char *__CFStringTransformGetICUIdentifier(CFStringRef identifier);
2525

Sources/CoreFoundation/CFStringUtilities.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include <limits.h>
2020
#include <stdlib.h>
2121
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_WASI
22-
#include <unicode/ucol.h>
23-
#include <unicode/ucoleitr.h>
22+
#include <_foundation_unicode/ucol.h>
23+
#include <_foundation_unicode/ucoleitr.h>
2424
#endif
2525
#include <string.h>
2626

Sources/CoreFoundation/CFTimeZone.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#include <fcntl.h>
2222
#include <stdlib.h>
2323
#include <string.h>
24-
#include <unicode/ucal.h>
25-
#include <unicode/udat.h>
26-
#include <unicode/ustring.h>
24+
#include <_foundation_unicode/ucal.h>
25+
#include <_foundation_unicode/udat.h>
26+
#include <_foundation_unicode/ustring.h>
2727
#include "CFDateFormatter.h"
2828
#if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WASI
2929
#include <dirent.h>

0 commit comments

Comments
 (0)