Skip to content

Commit 5703dc2

Browse files
authored
update cmake setup so that the library can be used by SwiftPM cmake build (#73)
Update cmake setup so that the library can be used by SwiftPM cmake build Motivation: integrate with SwiftPM changes: * rename the top level project to SwiftSystem instead of swift-system to align with other projects * rename System to SystemPackage to align with SwifPM setup * update architectures to include arm64 * Update cmake/modules/SwiftSystemConfig.cmake.in * Update cmake/modules/SwiftSupport.cmake
1 parent 2fa2678 commit 5703dc2

File tree

5 files changed

+49
-15
lines changed

5 files changed

+49
-15
lines changed

CMakeLists.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ See https://swift.org/LICENSE.txt for license information
88
#]]
99

1010
cmake_minimum_required(VERSION 3.16.0)
11-
project(swift-system
11+
project(SwiftSystem
1212
LANGUAGES C Swift)
1313

1414
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
@@ -21,9 +21,4 @@ set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
2121
include(SwiftSupport)
2222

2323
add_subdirectory(Sources)
24-
25-
get_property(SWIFT_SYSTEM_EXPORTS GLOBAL PROPERTY SWIFT_SYSTEM_EXPORTS)
26-
export(TARGETS ${SWIFT_SYSTEM_EXPORTS}
27-
NAMESPACE SwiftSystem::
28-
FILE swift-system-config.cmake
29-
EXPORT_LINK_INTERFACE_LIBRARIES)
24+
add_subdirectory(cmake/modules)

Sources/System/CMakeLists.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Licensed under Apache License v2.0 with Runtime Library Exception
77
See https://swift.org/LICENSE.txt for license information
88
#]]
99

10-
add_library(System
10+
add_library(SystemPackage
1111
Errno.swift
1212
FileDescriptor.swift
1313
FileHelpers.swift
@@ -17,24 +17,26 @@ add_library(System
1717
SystemString.swift
1818
Util.swift
1919
UtilConsumers.swift)
20-
target_sources(System PRIVATE
20+
set_target_properties(SystemPackage PROPERTIES
21+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
22+
target_sources(SystemPackage PRIVATE
2123
FilePath/FilePath.swift
2224
FilePath/FilePathComponents.swift
2325
FilePath/FilePathComponentView.swift
2426
FilePath/FilePathParsing.swift
2527
FilePath/FilePathString.swift
2628
FilePath/FilePathSyntax.swift
2729
FilePath/FilePathWindows.swift)
28-
target_sources(System PRIVATE
30+
target_sources(SystemPackage PRIVATE
2931
Internals/CInterop.swift
3032
Internals/Constants.swift
3133
Internals/Exports.swift
3234
Internals/Mocking.swift
3335
Internals/Syscalls.swift
3436
Internals/WindowsSyscallAdapters.swift)
35-
target_link_libraries(System PRIVATE
37+
target_link_libraries(SystemPackage PRIVATE
3638
CSystem)
3739

3840

39-
_install_target(System)
40-
set_property(GLOBAL APPEND PROPERTY SWIFT_SYSTEM_EXPORTS System)
41+
_install_target(SystemPackage)
42+
set_property(GLOBAL APPEND PROPERTY SWIFT_SYSTEM_EXPORTS SystemPackage)

cmake/modules/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#[[
2+
This source file is part of the Swift System open source Project
3+
4+
Copyright (c) 2021 Apple Inc. and the Swift System project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
#]]
9+
10+
set(SWIFT_SYSTEM_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/SwiftSystemExports.cmake)
11+
12+
configure_file(SwiftSystemConfig.cmake.in
13+
${CMAKE_CURRENT_BINARY_DIR}/SwiftSystemConfig.cmake)
14+
15+
get_property(SWIFT_SYSTEM_EXPORTS GLOBAL PROPERTY SWIFT_SYSTEM_EXPORTS)
16+
export(TARGETS ${SWIFT_SYSTEM_EXPORTS}
17+
NAMESPACE SwiftSystem::
18+
FILE ${SWIFT_SYSTEM_EXPORTS_FILE}
19+
EXPORT_LINK_INTERFACE_LIBRARIES)

cmake/modules/SwiftSupport.cmake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ See https://swift.org/LICENSE.txt for license information
1717
function(get_swift_host_arch result_var_name)
1818
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
1919
set("${result_var_name}" "x86_64" PARENT_SCOPE)
20-
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
21-
set("${result_var_name}" "aarch64" PARENT_SCOPE)
20+
elseif ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "AArch64|aarch64|arm64")
21+
if(CMAKE_SYSTEM_NAME MATCHES Darwin)
22+
set("${result_var_name}" "arm64" PARENT_SCOPE)
23+
else()
24+
set("${result_var_name}" "aarch64" PARENT_SCOPE)
25+
endif()
2226
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
2327
set("${result_var_name}" "powerpc64" PARENT_SCOPE)
2428
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")
@@ -31,6 +35,8 @@ function(get_swift_host_arch result_var_name)
3135
set("${result_var_name}" "armv7" PARENT_SCOPE)
3236
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a")
3337
set("${result_var_name}" "armv7" PARENT_SCOPE)
38+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "amd64")
39+
set("${result_var_name}" "amd64" PARENT_SCOPE)
3440
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
3541
set("${result_var_name}" "x86_64" PARENT_SCOPE)
3642
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#[[
2+
This source file is part of the Swift System open source Project
3+
4+
Copyright (c) 2021 Apple Inc. and the Swift System project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
#]]
9+
10+
if(NOT TARGET SystemPackage)
11+
include(@SWIFT_SYSTEM_EXPORTS_FILE@)
12+
endif()

0 commit comments

Comments
 (0)