Skip to content

Commit 2ba3887

Browse files
authored
Introduce CMake support for SwiftFoundationICU (#22)
1 parent dc0d5b8 commit 2ba3887

File tree

952 files changed

+4333
-3508
lines changed

Some content is hidden

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

952 files changed

+4333
-3508
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
/.swiftpm
33
/.build
4+
/build
45
/Packages
56
/*.xcodeproj
67
xcuserdata/

CMakeLists.txt

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
project(SwiftFoundationICU
18+
LANGUAGES CXX Swift)
19+
20+
set(CMAKE_CXX_STANDARD 14)
21+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
22+
23+
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
24+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
25+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
26+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
27+
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
28+
29+
# Build flags
30+
add_compile_definitions(
31+
$<$<COMPILE_LANGUAGE:C,CXX>:U_ATTRIBUTE_DEPRECATED="">
32+
$<$<COMPILE_LANGUAGE:C,CXX>:U_SHOW_CPLUSPLUS_API=1>
33+
$<$<COMPILE_LANGUAGE:C,CXX>:U_SHOW_INTERNAL_API=1>
34+
$<$<COMPILE_LANGUAGE:C,CXX>:U_STATIC_IMPLEMENTATION>
35+
$<$<COMPILE_LANGUAGE:C,CXX>:U_TIMEZONE_PACKAGE="icutz44l">
36+
$<$<COMPILE_LANGUAGE:C,CXX>:FORTIFY_SOURCE=2>
37+
$<$<COMPILE_LANGUAGE:C,CXX>:STD_INSPIRED>
38+
$<$<COMPILE_LANGUAGE:C,CXX>:MAC_OS_X_VERSION_MIN_REQUIRED=101500>
39+
$<$<COMPILE_LANGUAGE:C,CXX>:U_HAVE_STRTOD_L=1>
40+
$<$<COMPILE_LANGUAGE:C,CXX>:U_HAVE_XLOCALE_H=1>
41+
$<$<COMPILE_LANGUAGE:C,CXX>:U_HAVE_STRING_VIEW=1>
42+
$<$<COMPILE_LANGUAGE:C,CXX>:U_DISABLE_RENAMING=1>
43+
$<$<COMPILE_LANGUAGE:C,CXX>:U_COMMON_IMPLEMENTATION>
44+
$<$<COMPILE_LANGUAGE:C,CXX>:ICU_DATA_DIR="/usr/share/icu">
45+
$<$<COMPILE_LANGUAGE:C,CXX>:USE_PACKAGE_DATA=1>
46+
$<$<COMPILE_LANGUAGE:C,CXX>:APPLE_ICU_CHANGES=1>)
47+
48+
# Window specific settings
49+
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
50+
add_compile_definitions(
51+
$<$<COMPILE_LANGUAGE:C,CXX>:U_TIMEZONE=_timezone>
52+
$<$<COMPILE_LANGUAGE:C,CXX>:_CRT_SECURE_NO_DEPRECATE>
53+
$<$<COMPILE_LANGUAGE:C,CXX>:U_PLATFORM_USES_ONLY_WIN32_API>)
54+
else()
55+
add_compile_definitions(
56+
$<$<COMPILE_LANGUAGE:C,CXX>:U_TIMEZONE=timezone>)
57+
endif()
58+
# WASI specific settings
59+
if(CMAKE_SYSTEM_NAME STREQUAL WASI)
60+
add_compile_definitions(
61+
$<$<COMPILE_LANGUAGE:C,CXX>:U_HAVE_TZSET=0>
62+
$<$<COMPILE_LANGUAGE:C,CXX>:U_HAVE_TZNAME=0>
63+
$<$<COMPILE_LANGUAGE:C,CXX>:U_HAVE_TIMEZONE=0>
64+
$<$<COMPILE_LANGUAGE:C,CXX>:_WASI_EMULATED_SIGNAL>
65+
$<$<COMPILE_LANGUAGE:C,CXX>:_WASI_EMULATED_MMAN>)
66+
add_link_options("-Lwasi-emulated-signal")
67+
add_link_options("-Lwasi-emulated-mman")
68+
endif()
69+
70+
if(BUILD_SHARED_LIBS)
71+
set(install_directory swift)
72+
else()
73+
set(install_directory swift_static)
74+
endif()
75+
76+
if(NOT SWIFT_SYSTEM_NAME)
77+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
78+
set(SWIFT_SYSTEM_NAME macosx)
79+
else()
80+
set(SWIFT_SYSTEM_NAME "$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
81+
endif()
82+
endif()
83+
84+
add_subdirectory(icuSources)
85+
add_subdirectory(cmake/modules)

Package.swift

Lines changed: 18 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ var buildSettings: [CXXSetting] = [
3838
// Where data are stored
3939
.define("ICU_DATA_DIR", to: "\"/usr/share/icu/\""),
4040
.define("USE_PACKAGE_DATA", to: "1"),
41-
.define("APPLE_ICU_CHANGES", to: "1")
41+
.define("APPLE_ICU_CHANGES", to: "1"),
42+
43+
.headerSearchPath("common"),
44+
.headerSearchPath("io"),
45+
.headerSearchPath("i18n"),
46+
.headerSearchPath("include"),
47+
.define("U_I18N_IMPLEMENTATION"),
48+
.define("SWIFT_PACKAGE", to: "1", .when(platforms: [.linux])),
49+
.define("U_IO_IMPLEMENTATION"),
4250
]
4351

4452
#if os(Windows)
@@ -48,30 +56,6 @@ buildSettings.append(contentsOf: [
4856
])
4957
#endif
5058

51-
let commonBuildSettings: [CXXSetting] = buildSettings.appending([
52-
.headerSearchPath("."),
53-
])
54-
55-
let i18nBuildSettings: [CXXSetting] = buildSettings.appending([
56-
.define("U_I18N_IMPLEMENTATION"),
57-
.define("SWIFT_PACKAGE", to: "1", .when(platforms: [.linux])),
58-
.headerSearchPath("../common"),
59-
.headerSearchPath("."),
60-
])
61-
62-
let ioBuildSettings: [CXXSetting] = buildSettings.appending([
63-
.define("U_IO_IMPLEMENTATION"),
64-
.headerSearchPath("../common"),
65-
.headerSearchPath("../i18n"),
66-
.headerSearchPath("."),
67-
])
68-
69-
let stubDataBuildSettings: [CXXSetting] = buildSettings.appending([
70-
.headerSearchPath("../common"),
71-
.headerSearchPath("../i18n"),
72-
.headerSearchPath("."),
73-
])
74-
7559
let linkerSettings: [LinkerSetting] = [
7660
.linkedLibrary("wasi-emulated-signal", .when(platforms: [.wasi])),
7761
.linkedLibrary("wasi-emulated-mman", .when(platforms: [.wasi])),
@@ -82,62 +66,19 @@ let package = Package(
8266
products: [
8367
.library(
8468
name: "_FoundationICU",
85-
targets: ["_FoundationICU"]),
86-
.library(
87-
name: "_FoundationICUCommon",
88-
targets: ["_FoundationICUCommon"]),
89-
.library(
90-
name: "_FoundationICUI18N",
91-
targets: ["_FoundationICUI18N"]),
92-
.library(
93-
name: "_FoundationICUIO",
94-
targets: ["_FoundationICUIO"]),
69+
targets: [
70+
"_FoundationICU"
71+
]
72+
)
9573
],
9674
targets: [
9775
.target(
9876
name: "_FoundationICU",
99-
dependencies: [
100-
"_FoundationICUCommon",
101-
"_FoundationICUI18N",
102-
"_FoundationICUIO",
103-
"_FoundationICUStubData"
104-
],
105-
path: "swift/FoundationICU"),
106-
.target(
107-
name: "_FoundationICUCommon",
108-
path: "icuSources/common",
109-
publicHeadersPath: "include",
110-
cxxSettings: commonBuildSettings),
111-
.target(
112-
name: "_FoundationICUI18N",
113-
dependencies: ["_FoundationICUCommon"],
114-
path: "icuSources/i18n",
115-
publicHeadersPath: "include",
116-
cxxSettings: i18nBuildSettings),
117-
.target(
118-
name: "_FoundationICUIO",
119-
dependencies: ["_FoundationICUCommon", "_FoundationICUI18N"],
120-
path: "icuSources/io",
121-
publicHeadersPath: "include",
122-
cxxSettings: ioBuildSettings),
123-
.target(
124-
name: "_FoundationICUStubData",
125-
dependencies: ["_FoundationICUCommon"],
126-
path: "icuSources/stubdata",
127-
publicHeadersPath: ".",
128-
cxxSettings: stubDataBuildSettings),
77+
path: "icuSources",
78+
exclude: ["stubdata"],
79+
cxxSettings: buildSettings,
80+
linkerSettings: linkerSettings
81+
)
12982
],
13083
cxxLanguageStandard: .cxx14
13184
)
132-
133-
for target in package.targets {
134-
target.linkerSettings = linkerSettings
135-
}
136-
137-
fileprivate extension Array {
138-
func appending(_ other: Self) -> Self {
139-
var me = self
140-
me.append(contentsOf: other)
141-
return me
142-
}
143-
}

cmake/modules/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
set(SWIFT_FOUNDATION_ICU_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/SwiftFoundationICUExports.cmake)
16+
17+
configure_file(SwiftFoundationICUConfig.cmake.in
18+
${CMAKE_CURRENT_BINARY_DIR}/SwiftFoundationICUConfig.cmake)
19+
20+
get_property(SWIFT_FOUNDATION_ICU_EXPORTS GLOBAL PROPERTY SWIFT_FOUNDATION_ICU_EXPORTS)
21+
export(TARGETS ${SWIFT_FOUNDATION_ICU_EXPORTS}
22+
NAMESPACE SwiftFoundationICU::
23+
FILE ${SWIFT_FOUNDATION_ICU_EXPORTS_FILE}
24+
EXPORT_LINK_INTERFACE_LIBRARIES)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
if(NOT TARGET SwiftFoundationICU)
16+
include(@SWIFT_FOUNDATION_ICU_EXPORTS_FILE@)
17+
endif()

icuSources/CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the SwiftFoundation open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the SwiftFoundation 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 SwiftFoundation project authors
10+
##
11+
## SPDX-License-Identifier: Apache-2.0
12+
##
13+
##===----------------------------------------------------------------------===##
14+
15+
add_library(_FoundationICU)
16+
17+
target_include_directories(_FoundationICU
18+
PUBLIC
19+
include/)
20+
21+
add_subdirectory(common)
22+
add_subdirectory(i18n)
23+
add_subdirectory(io)
24+
25+
target_link_libraries(_FoundationICU PRIVATE stdc++)
26+
target_compile_definitions(_FoundationICU PRIVATE U_I18N_IMPLEMENTATION U_IO_IMPLEMENTATION)
27+
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
28+
target_compile_definitions(_FoundationICU PRIVATE SWIFT_PACKAGE=1)
29+
endif()
30+
set_target_properties(_FoundationICU PROPERTIES
31+
INSTALL_RPATH "$ORIGIN")
32+
33+
# Install binary
34+
install(TARGETS _FoundationICU
35+
ARCHIVE DESTINATION lib/${install_directory}/${SWIFT_SYSTEM_NAME}
36+
LIBRARY DESTINATION lib/${install_directory}/${SWIFT_SYSTEM_NAME}
37+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
38+
39+
# Install headers
40+
install(DIRECTORY
41+
include/
42+
DESTINATION
43+
lib/${install_directory})
44+
45+
set_property(GLOBAL APPEND PROPERTY SWIFT_FOUNDATION_ICU_EXPORTS _FoundationICU)

0 commit comments

Comments
 (0)