From 3a8f34b98cbbe8001f1645516701623a78504611 Mon Sep 17 00:00:00 2001 From: Nils Gladitz Date: Fri, 15 Nov 2013 21:41:11 +0100 Subject: [PATCH] Makefile: Remove "forbidden" flags only as a whole Fix CMAKE__CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS implementation to only remove whole flags. Without this n the Mac we were incorrectly removing -w from -Wno-write-strings. --- Source/cmMakefileTargetGenerator.cxx | 35 +++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 6770e106a..2fcad7974 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -27,6 +27,7 @@ #include "cmMakefileLibraryTargetGenerator.h" #include "cmMakefileUtilityTargetGenerator.h" +#include cmMakefileTargetGenerator::cmMakefileTargetGenerator(cmTarget* target) : OSXBundleGenerator(0) @@ -1694,10 +1695,42 @@ void cmMakefileTargetGenerator::RemoveForbiddenFlags(const char* flagVar, this->Makefile->GetSafeDefinition(removeFlags.c_str()); std::vector removeList; cmSystemTools::ExpandListArgument(removeflags, removeList); + for(std::vector::iterator i = removeList.begin(); i != removeList.end(); ++i) { - cmSystemTools::ReplaceString(linkFlags, i->c_str(), ""); + std::string tmp; + std::string::size_type lastPosition = 0; + + for(;;) + { + std::string::size_type position = linkFlags.find(*i, lastPosition); + + if(position == std::string::npos) + { + tmp += linkFlags.substr(lastPosition); + break; + } + else + { + std::string::size_type prefixLength = position - lastPosition; + tmp += linkFlags.substr(lastPosition, prefixLength); + lastPosition = position + i->length(); + + bool validFlagStart = position == 0 || + isspace(linkFlags[position - 1]); + + bool validFlagEnd = lastPosition == linkFlags.size() || + isspace(linkFlags[lastPosition]); + + if(!validFlagStart || !validFlagEnd) + { + tmp += *i; + } + } + } + + linkFlags = tmp; } }