From 369c48ee437263a9702c8725f6e73bc4b9d0fe16 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sun, 11 Aug 2019 18:36:06 -0700 Subject: Swift: honour `-swift-version` in Ninja generator Swift has supported `CMAKE_Swift_LANGUAGE_VERSION` and `Swift_LANGUAGE_VERSION` but didn't apply that to Ninja generated targets. Consider the property when calculating the flags. --- Help/manual/cmake-properties.7.rst | 1 + Help/prop_tgt/Swift_LANGUAGE_VERSION.rst | 6 ++++++ Source/cmLocalGenerator.cxx | 11 +++++++++++ Source/cmTarget.cxx | 1 + 4 files changed, 19 insertions(+) create mode 100644 Help/prop_tgt/Swift_LANGUAGE_VERSION.rst diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index 62d23c7..def9700 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -316,6 +316,7 @@ Properties on Targets /prop_tgt/STATIC_LIBRARY_OPTIONS /prop_tgt/SUFFIX /prop_tgt/Swift_DEPENDENCIES_FILE + /prop_tgt/Swift_LANGUAGE_VERSION /prop_tgt/Swift_MODULE_DIRECTORY /prop_tgt/Swift_MODULE_NAME /prop_tgt/TYPE diff --git a/Help/prop_tgt/Swift_LANGUAGE_VERSION.rst b/Help/prop_tgt/Swift_LANGUAGE_VERSION.rst new file mode 100644 index 0000000..7579447 --- /dev/null +++ b/Help/prop_tgt/Swift_LANGUAGE_VERSION.rst @@ -0,0 +1,6 @@ +Swift_LANGUAGE_VERSION +---------------------- + +This property sets the language version for the Swift sources in the target. If +one is not specified, it will default to ```` if +specified, otherwise it is the latest version supported by the compiler. diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 1827a42..5ee1717 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1566,6 +1566,17 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags, this->AddConfigVariableFlags(flags, cmStrCat("CMAKE_", lang, "_FLAGS"), config); + if (lang == "Swift") { + if (const char* v = target->GetProperty("Swift_LANGUAGE_VERSION")) { + if (cmSystemTools::VersionCompare( + cmSystemTools::OP_GREATER_EQUAL, + this->Makefile->GetDefinition("CMAKE_Swift_COMPILER_VERSION"), + "4.2")) { + this->AppendFlags(flags, "-swift-version " + std::string(v)); + } + } + } + // Add MSVC runtime library flags. This is activated by the presence // of a default selection whether or not it is overridden by a property. const char* msvcRuntimeLibraryDefault = diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index bc1b9de..e3e175a 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -347,6 +347,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, initProp("LINK_SEARCH_START_STATIC"); initProp("LINK_SEARCH_END_STATIC"); initProp("FOLDER"); + initProp("Swift_LANGUAGE_VERSION"); initProp("Swift_MODULE_DIRECTORY"); initProp("VS_JUST_MY_CODE_DEBUGGING"); #ifdef __APPLE__ -- cgit v0.12