-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Introduce Cmake support for SwiftCorelibsFoundation #4959
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
Merged
iCharlesHu
merged 1 commit into
swiftlang:package
from
iCharlesHu:charles/cmake-support
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
##===----------------------------------------------------------------------===## | ||
## | ||
## This source file is part of the Swift open source project | ||
## | ||
## Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
## Licensed under Apache License v2.0 | ||
## | ||
## See LICENSE.txt for license information | ||
## See CONTRIBUTORS.md for the list of Swift project authors | ||
## | ||
## SPDX-License-Identifier: Apache-2.0 | ||
## | ||
##===----------------------------------------------------------------------===## | ||
|
||
cmake_minimum_required(VERSION 3.24) | ||
|
||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) | ||
|
||
if(POLICY CMP0156) | ||
# Deduplicate linked libraries where appropriate | ||
cmake_policy(SET CMP0156 NEW) | ||
endif() | ||
|
||
if(POLICY CMP0157) | ||
# New Swift build model: improved incremental build performance and LSP support | ||
cmake_policy(SET CMP0157 NEW) | ||
endif() | ||
|
||
if (NOT DEFINED CMAKE_C_COMPILER) | ||
set(CMAKE_C_COMPILER clang) | ||
endif() | ||
|
||
project(Foundation | ||
LANGUAGES C Swift) | ||
|
||
if(NOT SWIFT_SYSTEM_NAME) | ||
if(CMAKE_SYSTEM_NAME STREQUAL Darwin) | ||
set(SWIFT_SYSTEM_NAME macosx) | ||
else() | ||
set(SWIFT_SYSTEM_NAME "$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>") | ||
iCharlesHu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
endif() | ||
endif() | ||
|
||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) | ||
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift) | ||
|
||
# Fetchable dependcies | ||
include(FetchContent) | ||
if (_SwiftFoundationICU_SourceDIR) | ||
FetchContent_Declare(SwiftFoundationICU | ||
SOURCE_DIR ${_SwiftFoundationICU_SourceDIR}) | ||
else() | ||
FetchContent_Declare(SwiftFoundationICU | ||
GIT_REPOSITORY https://github.com/apple/swift-foundation-icu.git | ||
GIT_TAG 0.0.8) | ||
endif() | ||
|
||
if (_SwiftFoundation_SourceDIR) | ||
FetchContent_Declare(SwiftFoundation | ||
SOURCE_DIR ${_SwiftFoundation_SourceDIR}) | ||
else() | ||
FetchContent_Declare(SwiftFoundation | ||
GIT_REPOSITORY https://github.com/apple/swift-foundation.git | ||
GIT_TAG main) | ||
endif() | ||
FetchContent_MakeAvailable(SwiftFoundationICU SwiftFoundation) | ||
|
||
# Precompute module triple for installation | ||
if(NOT SwiftFoundation_MODULE_TRIPLE) | ||
set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info) | ||
if(CMAKE_Swift_COMPILER_TARGET) | ||
list(APPEND module_triple_command -target ${CMAKE_Swift_COMPILER_TARGET}) | ||
endif() | ||
execute_process(COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json) | ||
string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple") | ||
set(SwiftFoundation_MODULE_TRIPLE "${module_triple}" CACHE STRING "swift module triple used for installed swiftmodule and swiftinterface files") | ||
mark_as_advanced(SwiftFoundation_MODULE_TRIPLE) | ||
endif() | ||
|
||
# System dependencies (fail fast if dependencies are missing) | ||
find_package(LibXml2 REQUIRED) | ||
find_package(CURL REQUIRED) | ||
find_package(dispatch CONFIG REQUIRED) | ||
|
||
# Common build flags (_CFURLSessionInterface, _CFXMLInterface, CoreFoundation) | ||
list(APPEND _Foundation_common_build_flags | ||
"-DDEPLOYMENT_RUNTIME_SWIFT" | ||
"-DCF_BUILDING_CF" | ||
"-DDEPLOYMENT_ENABLE_LIBDISPATCH" | ||
"-DHAVE_STRUCT_TIMESPEC" | ||
"-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS" | ||
"-Wno-shorten-64-to-32" | ||
"-Wno-deprecated-declarations" | ||
"-Wno-unreachable-code" | ||
"-Wno-conditional-uninitialized" | ||
"-Wno-unused-variable" | ||
"-Wno-unused-function" | ||
"-Wno-microsoft-enum-forward-reference" | ||
"-fconstant-cfstrings" | ||
"-fexceptions" # TODO: not on OpenBSD | ||
"-fdollars-in-identifiers" | ||
"-fno-common" | ||
"-fcf-runtime-abi=swift" | ||
"-fblocks") | ||
|
||
if(CMAKE_BUILD_TYPE STREQUAL Debug) | ||
list(APPEND _Foundation_common_build_flags | ||
"-DDEBUG") | ||
endif() | ||
|
||
# Swift build flags (Foundation, FoundationNetworking, FoundationXML) | ||
set(_Foundation_swift_build_flags) | ||
list(APPEND _Foundation_swift_build_flags | ||
"-DDEPLOYMENT_RUNTIME_SWIFT" | ||
"-DSWIFT_CORELIBS_FOUNDATION_HAS_THREADS") | ||
|
||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android") | ||
list(APPEND _Foundation_common_build_flags | ||
"-D_GNU_SOURCE" | ||
"-I/usr/lib/swift") # dispatch | ||
endif() | ||
|
||
include(FoundationSwiftSupport) | ||
|
||
add_subdirectory(Sources) | ||
add_subdirectory(cmake/modules) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
##===----------------------------------------------------------------------===## | ||
## | ||
## This source file is part of the Swift open source project | ||
## | ||
## Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
## Licensed under Apache License v2.0 | ||
## | ||
## See LICENSE.txt for license information | ||
## See CONTRIBUTORS.md for the list of Swift project authors | ||
## | ||
## SPDX-License-Identifier: Apache-2.0 | ||
## | ||
##===----------------------------------------------------------------------===## | ||
|
||
add_subdirectory(CoreFoundation) | ||
add_subdirectory(_CFXMLInterface) | ||
add_subdirectory(_CFURLSessionInterface) | ||
add_subdirectory(Foundation) | ||
add_subdirectory(FoundationXML) | ||
add_subdirectory(FoundationNetworking) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.