Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update cmake setup so that the library can be used by SwiftPM cmake build #73

Merged
merged 3 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ See https://swift.org/LICENSE.txt for license information
#]]

cmake_minimum_required(VERSION 3.16.0)
project(swift-system
project(SwiftSystem
LANGUAGES C Swift)

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

add_subdirectory(Sources)

get_property(SWIFT_SYSTEM_EXPORTS GLOBAL PROPERTY SWIFT_SYSTEM_EXPORTS)
export(TARGETS ${SWIFT_SYSTEM_EXPORTS}
NAMESPACE SwiftSystem::
FILE swift-system-config.cmake
EXPORT_LINK_INTERFACE_LIBRARIES)
add_subdirectory(cmake/modules)
14 changes: 8 additions & 6 deletions Sources/System/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
#]]

add_library(System
add_library(SystemPackage
Errno.swift
FileDescriptor.swift
FileHelpers.swift
Expand All @@ -17,24 +17,26 @@ add_library(System
SystemString.swift
Util.swift
UtilConsumers.swift)
target_sources(System PRIVATE
set_target_properties(SystemPackage PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
target_sources(SystemPackage PRIVATE
FilePath/FilePath.swift
FilePath/FilePathComponents.swift
FilePath/FilePathComponentView.swift
FilePath/FilePathParsing.swift
FilePath/FilePathString.swift
FilePath/FilePathSyntax.swift
FilePath/FilePathWindows.swift)
target_sources(System PRIVATE
target_sources(SystemPackage PRIVATE
Internals/CInterop.swift
Internals/Constants.swift
Internals/Exports.swift
Internals/Mocking.swift
Internals/Syscalls.swift
Internals/WindowsSyscallAdapters.swift)
target_link_libraries(System PRIVATE
target_link_libraries(SystemPackage PRIVATE
CSystem)


_install_target(System)
set_property(GLOBAL APPEND PROPERTY SWIFT_SYSTEM_EXPORTS System)
_install_target(SystemPackage)
set_property(GLOBAL APPEND PROPERTY SWIFT_SYSTEM_EXPORTS SystemPackage)
19 changes: 19 additions & 0 deletions cmake/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#[[
This source file is part of the Swift System open source Project

Copyright (c) 2021 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
#]]

set(SWIFT_SYSTEM_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/SwiftSystemExports.cmake)

configure_file(SwiftSystemConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/SwiftSystemConfig.cmake)

get_property(SWIFT_SYSTEM_EXPORTS GLOBAL PROPERTY SWIFT_SYSTEM_EXPORTS)
export(TARGETS ${SWIFT_SYSTEM_EXPORTS}
NAMESPACE SwiftSystem::
FILE ${SWIFT_SYSTEM_EXPORTS_FILE}
EXPORT_LINK_INTERFACE_LIBRARIES)
10 changes: 8 additions & 2 deletions cmake/modules/SwiftSupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ See https://swift.org/LICENSE.txt for license information
function(get_swift_host_arch result_var_name)
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
set("${result_var_name}" "x86_64" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
set("${result_var_name}" "aarch64" PARENT_SCOPE)
elseif ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "AArch64|aarch64|arm64")
if(CMAKE_SYSTEM_NAME MATCHES Darwin)
set("${result_var_name}" "arm64" PARENT_SCOPE)
else()
set("${result_var_name}" "aarch64" PARENT_SCOPE)
endif()
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
set("${result_var_name}" "powerpc64" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")
Expand All @@ -31,6 +35,8 @@ function(get_swift_host_arch result_var_name)
set("${result_var_name}" "armv7" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a")
set("${result_var_name}" "armv7" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "amd64")
set("${result_var_name}" "amd64" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
set("${result_var_name}" "x86_64" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64")
Expand Down
12 changes: 12 additions & 0 deletions cmake/modules/SwiftSystemConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#[[
This source file is part of the Swift System open source Project

Copyright (c) 2021 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
#]]

if(NOT TARGET SystemPackage)
include(@SWIFT_SYSTEM_EXPORTS_FILE@)
endif()