From 3c8e899102dc58efa5301240f5bf5bf2225c2b65 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Mon, 3 Apr 2006 12:57:51 -0400 Subject: [PATCH] ENH: add support for per config target LINK_FLAGS --- Source/cmLocalGenerator.cxx | 18 ++++++++++++- Source/cmLocalVisualStudio6Generator.cxx | 25 ++++++++++++++++--- Source/cmLocalVisualStudio7Generator.cxx | 10 +++++++- .../cmMakefileExecutableTargetGenerator.cxx | 5 +++- Source/cmMakefileLibraryTargetGenerator.cxx | 9 +++++++ Source/cmSetTargetPropertiesCommand.h | 3 ++- 6 files changed, 63 insertions(+), 7 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index af82c45e3..748bfe59b 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1045,6 +1045,14 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs, { linkFlags += targetLinkFlags; linkFlags += " "; + std::string configLinkFlags = targetLinkFlags; + configLinkFlags += buildType; + targetLinkFlags = target.GetProperty(configLinkFlags.c_str()); + if(targetLinkFlags) + { + linkFlags += targetLinkFlags; + linkFlags += " "; + } } cmOStringStream linklibsStr; this->OutputLinkLibraries(linklibsStr, target, false); @@ -1103,7 +1111,15 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs, if(targetLinkFlags) { linkFlags += targetLinkFlags; - linkFlags += " "; + linkFlags += " "; + std::string configLinkFlags = targetLinkFlags; + configLinkFlags += buildType; + targetLinkFlags = target.GetProperty(configLinkFlags.c_str()); + if(targetLinkFlags) + { + linkFlags += targetLinkFlags; + linkFlags += " "; + } } } break; diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx index 6c36bea51..ec5d7ea3d 100644 --- a/Source/cmLocalVisualStudio6Generator.cxx +++ b/Source/cmLocalVisualStudio6Generator.cxx @@ -1062,7 +1062,6 @@ void cmLocalVisualStudio6Generator libMultiLineOptionsForDebug += targetLinkFlags; libMultiLineOptionsForDebug += " \n"; } - // are there any custom rules on the target itself // only if the target is a lib or exe @@ -1185,18 +1184,38 @@ void cmLocalVisualStudio6Generator std::string flagVar = baseFlagVar + "_RELEASE"; flagsRelease = this->Makefile->GetRequiredDefinition(flagVar.c_str()); flagsRelease += " -DCMAKE_INTDIR=\\\"Release\\\" "; - + if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_RELEASE")) + { + flagsRelease += targetLinkFlags; + flagsRelease += " "; + } flagVar = baseFlagVar + "_MINSIZEREL"; flagsMinSize = this->Makefile->GetRequiredDefinition(flagVar.c_str()); flagsMinSize += " -DCMAKE_INTDIR=\\\"MinSizeRel\\\" "; + if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_MINSIZEREL")) + { + flagsMinSize += targetLinkFlags; + flagsMinSize += " "; + } flagVar = baseFlagVar + "_DEBUG"; flagsDebug = this->Makefile->GetRequiredDefinition(flagVar.c_str()); flagsDebug += " -DCMAKE_INTDIR=\\\"Debug\\\" "; - + if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_DEBUG")) + { + flagsDebug += targetLinkFlags; + flagsDebug += " "; + } + flagVar = baseFlagVar + "_RELWITHDEBINFO"; flagsDebugRel = this->Makefile->GetRequiredDefinition(flagVar.c_str()); flagsDebugRel += " -DCMAKE_INTDIR=\\\"RelWithDebInfo\\\" "; + if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_RELWITHDEBINFO")) + { + flagsDebugRel += targetLinkFlags; + flagsDebugRel += " "; + } + } // if unicode is not found, then add -D_MBCS diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 38b97009c..55b80efea 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -626,7 +626,15 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, extraLinkOptions += " "; extraLinkOptions += targetLinkFlags; } - + std::string configTypeUpper = cmSystemTools::UpperCase(configName); + std::string linkFlagsConfig = "LINK_FLAGS_"; + linkFlagsConfig += configTypeUpper; + targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str()); + if(targetLinkFlags) + { + extraLinkOptions += " "; + extraLinkOptions += targetLinkFlags; + } std::map flagMap; this-> FillFlagMapFromCommandFlags(flagMap, diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index 738886206..37c664c5a 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -232,7 +232,10 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) // Add target-specific linker flags. this->LocalGenerator->AppendFlags(linkFlags, this->Target->GetProperty("LINK_FLAGS")); - + std::string linkFlagsConfig = "LINK_FLAGS_"; + linkFlagsConfig += cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName.c_str()); + this->LocalGenerator->AppendFlags(linkFlags, + this->Target->GetProperty(linkFlagsConfig.c_str())); // Construct a list of files associated with this executable that // may need to be cleaned. std::vector exeCleanFiles; diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 6cf5be90c..bf5d55cb2 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -109,6 +109,11 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink) std::string extraFlags; this->LocalGenerator->AppendFlags(extraFlags, this->Target->GetProperty("LINK_FLAGS")); + std::string linkFlagsConfig = "LINK_FLAGS_"; + linkFlagsConfig += cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName.c_str()); + this->LocalGenerator->AppendFlags(extraFlags, + this->Target->GetProperty(linkFlagsConfig.c_str())); + this->LocalGenerator->AddConfigVariableFlags(extraFlags, "CMAKE_SHARED_LINKER_FLAGS", this->LocalGenerator->ConfigurationName.c_str()); if(this->Makefile->IsOn("WIN32") && !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW"))) @@ -143,6 +148,10 @@ void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink) std::string extraFlags; this->LocalGenerator->AppendFlags(extraFlags, this->Target->GetProperty("LINK_FLAGS")); + std::string linkFlagsConfig = "LINK_FLAGS_"; + linkFlagsConfig += cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName.c_str()); + this->LocalGenerator->AppendFlags(extraFlags, + this->Target->GetProperty(linkFlagsConfig.c_str())); this->LocalGenerator->AddConfigVariableFlags(extraFlags, "CMAKE_MODULE_LINKER_FLAGS", this->LocalGenerator->ConfigurationName.c_str()); // TODO: .def files should be supported here also. diff --git a/Source/cmSetTargetPropertiesCommand.h b/Source/cmSetTargetPropertiesCommand.h index fdf41b15b..21a7b5046 100644 --- a/Source/cmSetTargetPropertiesCommand.h +++ b/Source/cmSetTargetPropertiesCommand.h @@ -79,7 +79,8 @@ public: "variable for executables)." "\n" "The LINK_FLAGS property can be used to add extra flags to the " - "link step of a target. " + "link step of a target. LINK_FLAGS_ will add to the configuration " + ", for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO. " "DEFINE_SYMBOL sets the name of the preprocessor symbol defined when " "compiling sources in a shared library. " "If not set here then it is set to target_EXPORTS by default "