diff options
author | Saleem Abdulrasool <compnerd@compnerd.org> | 2019-05-30 21:22:20 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-06-03 13:59:39 (GMT) |
commit | 7456739e2401baa34ccec2989d604ea74ebb2f77 (patch) | |
tree | 608124b43a871a2575946bb73d95111ec09cca0c | |
parent | 5e2d22c177add56b2538ab10954dfb049c5cf945 (diff) | |
download | CMake-7456739e2401baa34ccec2989d604ea74ebb2f77.zip CMake-7456739e2401baa34ccec2989d604ea74ebb2f77.tar.gz CMake-7456739e2401baa34ccec2989d604ea74ebb2f77.tar.bz2 |
Swift: avoid `CMAKE_{EXE,SHARED}_LINKER_FLAGS`
Avoid the use of `CMAKE_{EXE,SHARED}_LINKER_FLAGS` when linking with the
Swift language. This required hoisting the executable flags of
`CMAKE_CREATE_WIN32_EXE`, `CMAKE_CREATE_CONSOLE_EXE`, and
`CMAKE_EXE_EXPORTS_*_FLAG` earlier to avoid a second clause which checks
the language. This allows for mixed-language Swift projects to properly
link on Windows.
Fixes #19298
-rw-r--r-- | Source/cmLocalGenerator.cxx | 111 |
1 files changed, 62 insertions, 49 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 87d2232..a6d22ef 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1169,30 +1169,34 @@ void cmLocalGenerator::GetTargetFlags( libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS"; CM_FALLTHROUGH; case cmStateEnums::SHARED_LIBRARY: { - linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable); - linkFlags += " "; - if (!buildType.empty()) { - std::string build = libraryLinkVariable; - build += "_"; - build += buildType; - linkFlags += this->Makefile->GetSafeDefinition(build); + if (linkLanguage != "Swift") { + linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable); linkFlags += " "; - } - if (this->Makefile->IsOn("WIN32") && - !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW"))) { - std::vector<cmSourceFile*> sources; - target->GetSourceFiles(sources, buildType); - std::string defFlag = - this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG"); - for (cmSourceFile* sf : sources) { - if (sf->GetExtension() == "def") { - linkFlags += defFlag; - linkFlags += this->ConvertToOutputFormat( - cmSystemTools::CollapseFullPath(sf->GetFullPath()), SHELL); - linkFlags += " "; + if (!buildType.empty()) { + std::string build = libraryLinkVariable; + build += "_"; + build += buildType; + linkFlags += this->Makefile->GetSafeDefinition(build); + linkFlags += " "; + } + if (this->Makefile->IsOn("WIN32") && + !(this->Makefile->IsOn("CYGWIN") || + this->Makefile->IsOn("MINGW"))) { + std::vector<cmSourceFile*> sources; + target->GetSourceFiles(sources, buildType); + std::string defFlag = + this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG"); + for (cmSourceFile* sf : sources) { + if (sf->GetExtension() == "def") { + linkFlags += defFlag; + linkFlags += this->ConvertToOutputFormat( + cmSystemTools::CollapseFullPath(sf->GetFullPath()), SHELL); + linkFlags += " "; + } } } } + const char* targetLinkFlags = target->GetProperty("LINK_FLAGS"); if (targetLinkFlags) { linkFlags += targetLinkFlags; @@ -1207,6 +1211,7 @@ void cmLocalGenerator::GetTargetFlags( linkFlags += " "; } } + std::vector<std::string> opts; target->GetLinkOptions(opts, config, linkLanguage); // LINK_OPTIONS are escaped. @@ -1217,25 +1222,49 @@ void cmLocalGenerator::GetTargetFlags( } } break; case cmStateEnums::EXECUTABLE: { - linkFlags += this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS"); - linkFlags += " "; - if (!buildType.empty()) { - std::string build = "CMAKE_EXE_LINKER_FLAGS_"; - build += buildType; - linkFlags += this->Makefile->GetSafeDefinition(build); + if (linkLanguage != "Swift") { + linkFlags += + this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS"); linkFlags += " "; + if (!buildType.empty()) { + std::string build = "CMAKE_EXE_LINKER_FLAGS_"; + build += buildType; + linkFlags += this->Makefile->GetSafeDefinition(build); + linkFlags += " "; + } + if (linkLanguage.empty()) { + cmSystemTools::Error( + "CMake can not determine linker language for target: " + + target->GetName()); + return; + } + + if (target->GetPropertyAsBool("WIN32_EXECUTABLE")) { + linkFlags += + this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE"); + linkFlags += " "; + } else { + linkFlags += + this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE"); + linkFlags += " "; + } + + if (target->IsExecutableWithExports()) { + std::string exportFlagVar = "CMAKE_EXE_EXPORTS_"; + exportFlagVar += linkLanguage; + exportFlagVar += "_FLAG"; + + linkFlags += this->Makefile->GetSafeDefinition(exportFlagVar); + linkFlags += " "; + } } - if (linkLanguage.empty()) { - cmSystemTools::Error( - "CMake can not determine linker language for target: " + - target->GetName()); - return; - } + this->AddLanguageFlagsForLinking(flags, target, linkLanguage, buildType); if (pcli) { this->OutputLinkLibraries(pcli, linkLineComputer, linkLibs, frameworkPath, linkPath); } + if (cmSystemTools::IsOn( this->Makefile->GetDefinition("BUILD_SHARED_LIBS"))) { std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_") + @@ -1243,23 +1272,6 @@ void cmLocalGenerator::GetTargetFlags( linkFlags += this->Makefile->GetSafeDefinition(sFlagVar); linkFlags += " "; } - if (target->GetPropertyAsBool("WIN32_EXECUTABLE")) { - linkFlags += - this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE"); - linkFlags += " "; - } else { - linkFlags += - this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE"); - linkFlags += " "; - } - if (target->IsExecutableWithExports()) { - std::string exportFlagVar = "CMAKE_EXE_EXPORTS_"; - exportFlagVar += linkLanguage; - exportFlagVar += "_FLAG"; - - linkFlags += this->Makefile->GetSafeDefinition(exportFlagVar); - linkFlags += " "; - } std::string cmp0065Flags = this->GetLinkLibsCMP0065(linkLanguage, *target); @@ -1282,6 +1294,7 @@ void cmLocalGenerator::GetTargetFlags( linkFlags += " "; } } + std::vector<std::string> opts; target->GetLinkOptions(opts, config, linkLanguage); // LINK_OPTIONS are escaped. |