Commit c03141c0 authored by Gregor Jasny's avatar Gregor Jasny Committed by Brad King

Swift: Default to Swift 3.0 with Xcode 8.3 and later

Xcode 8.3 has dropped support for Swift 2.3 so that compiler and
feature detection failed.

Closes #16742
parent 1adbe223
......@@ -269,7 +269,13 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS}
set(id_toolset "")
endif()
if("${lang}" STREQUAL "Swift")
set(id_lang_version "SWIFT_VERSION = 2.3;")
if(CMAKE_Swift_LANGUAGE_VERSION)
set(id_lang_version "SWIFT_VERSION = ${CMAKE_Swift_LANGUAGE_VERSION};")
elseif(XCODE_VERSION VERSION_GREATER_EQUAL 8.3)
set(id_lang_version "SWIFT_VERSION = 3.0;")
else()
set(id_lang_version "SWIFT_VERSION = 2.3;")
endif()
else()
set(id_lang_version "")
endif()
......
......@@ -3075,10 +3075,14 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
this->CreateString(this->GeneratorToolset));
}
if (this->GetLanguageEnabled("Swift")) {
std::string swiftVersion = "2.3";
std::string swiftVersion;
if (const char* vers = this->CurrentMakefile->GetDefinition(
"CMAKE_Swift_LANGUAGE_VERSION")) {
swiftVersion = vers;
} else if (this->XcodeVersion >= 83) {
swiftVersion = "3.0";
} else {
swiftVersion = "2.3";
}
buildSettings->AddAttribute("SWIFT_VERSION",
this->CreateString(swiftVersion));
......
#import "SwiftMix-Swift.h"
int ObjCMain(int argc, char const* const argv[]) {
return [SwiftMainClass SwiftMain:argc argv:argv];
if ([SwiftMainClass respondsToSelector:@selector(SwiftMain:argv:)]) {
return [SwiftMainClass SwiftMain:argc argv:argv];
}
if ([SwiftMainClass respondsToSelector:@selector(SwiftMainWithArgc:argv:)]) {
return [SwiftMainClass SwiftMainWithArgc:argc argv:argv];
}
return -1;
}
......@@ -3,10 +3,17 @@ import Foundation
@objc class SwiftMainClass : NSObject {
class func SwiftMain(argc:Int, argv:UnsafePointer<UnsafePointer<CChar>>) -> Int32 {
dump("argc: \(argc)")
#if swift(>=3.0)
for i in 0 ..< argc {
let argi = String(cString:argv[i]);
dump("arg[\(i)]: \(argi)");
}
#else
for (var i = 0; i < argc; ++i) {
let argi = String.fromCString(argv[i])
dump("arg[\(i)]: \(argi)");
}
#endif
return 0;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment