diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index fb897b2d33..c05394346b 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -85,6 +85,7 @@ public: virtual bool IsMultiConfig(); virtual bool SetGeneratorToolset(std::string const& ts); + void AppendFlag(std::string& flags, std::string const& flag); private: cmXCodeObject* CreateOrGetPBXGroup(cmTarget& cmtarget, cmSourceGroup* sg); @@ -198,7 +199,6 @@ private: void AppendDefines(BuildObjectListOrString& defs, std::vector const& defines, bool dflag = false); - void AppendFlag(std::string& flags, std::string const& flag); protected: virtual const char* GetInstallTargetName() const { return "install"; } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 684c3c4cdc..ccbccb219c 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1354,7 +1354,7 @@ void cmLocalGenerator::GetCompileOptions(std::string& flags, for(std::vector::const_iterator li = opts.begin(); li != opts.end(); ++li) { - this->AppendFlags(flags, li->c_str()); + this->AppendFlagEscape(flags, li->c_str()); } } @@ -2216,7 +2216,7 @@ void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags, for(std::vector::const_iterator oi = options.begin(); oi != options.end(); ++oi) { - this->AppendFlags(flags, this->EscapeForShell(oi->c_str()).c_str()); + this->AppendFlagEscape(flags, oi->c_str()); } } } @@ -2253,6 +2253,13 @@ void cmLocalGenerator::AppendFlags(std::string& flags, } } +//---------------------------------------------------------------------------- +void cmLocalGenerator::AppendFlagEscape(std::string& flags, + const char* rawFlag) +{ + this->AppendFlags(flags, this->EscapeForShell(rawFlag).c_str()); +} + //---------------------------------------------------------------------------- void cmLocalGenerator::AppendDefines(std::set& defines, const char* defines_list) @@ -2359,7 +2366,7 @@ void cmLocalGenerator::AppendFeatureOptions( for(std::vector::const_iterator oi = options.begin(); oi != options.end(); ++oi) { - this->AppendFlags(flags, this->EscapeForShell(oi->c_str()).c_str()); + this->AppendFlagEscape(flags, oi->c_str()); } } } diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 9a71b9b0b7..1a01a8d33b 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -149,6 +149,7 @@ public: const char* config); ///! Append flags to a string. virtual void AppendFlags(std::string& flags, const char* newFlags); + virtual void AppendFlagEscape(std::string& flags, const char* rawFlag); ///! Get the include flags for the current makefile and language std::string GetIncludeFlags(const std::vector &includes, const char* lang, bool forResponseFile = false, diff --git a/Source/cmLocalXCodeGenerator.cxx b/Source/cmLocalXCodeGenerator.cxx index 551ebd30a1..7c5f69df5f 100644 --- a/Source/cmLocalXCodeGenerator.cxx +++ b/Source/cmLocalXCodeGenerator.cxx @@ -33,3 +33,12 @@ cmLocalXCodeGenerator::GetTargetDirectory(cmTarget const&) const // No per-target directory for this generator (yet). return ""; } + +//---------------------------------------------------------------------------- +void cmLocalXCodeGenerator::AppendFlagEscape(std::string& flags, + const char* rawFlag) +{ + cmGlobalXCodeGenerator* gg = + static_cast(this->GlobalGenerator); + gg->AppendFlag(flags, rawFlag); +} diff --git a/Source/cmLocalXCodeGenerator.h b/Source/cmLocalXCodeGenerator.h index eab228f6be..d97a41cea6 100644 --- a/Source/cmLocalXCodeGenerator.h +++ b/Source/cmLocalXCodeGenerator.h @@ -28,6 +28,7 @@ public: virtual ~cmLocalXCodeGenerator(); virtual std::string GetTargetDirectory(cmTarget const& target) const; + virtual void AppendFlagEscape(std::string& flags, const char* rawFlag); private: }; diff --git a/Tests/CompileOptions/CMakeLists.txt b/Tests/CompileOptions/CMakeLists.txt index 6d8a96a668..52c3759f6a 100644 --- a/Tests/CompileOptions/CMakeLists.txt +++ b/Tests/CompileOptions/CMakeLists.txt @@ -5,7 +5,11 @@ project(CompileOptions) add_library(testlib other.cpp) add_executable(CompileOptions main.cpp) -set_property(TARGET CompileOptions PROPERTY COMPILE_OPTIONS "$<$:-DTEST_DEFINE>") +set_property(TARGET CompileOptions PROPERTY COMPILE_OPTIONS + "-DTEST_DEFINE" + "-DNEEDS_ESCAPE=\"E$CAPE\"" + "$<$:-DTEST_DEFINE_GNU>" + ) target_link_libraries(CompileOptions testlib) if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") diff --git a/Tests/CompileOptions/main.cpp b/Tests/CompileOptions/main.cpp index 0d390503f8..90740f1431 100644 --- a/Tests/CompileOptions/main.cpp +++ b/Tests/CompileOptions/main.cpp @@ -1,11 +1,20 @@ - -#ifdef DO_GNU_TESTS -# ifndef TEST_DEFINE -# error Expected TEST_DEFINE -# endif +#ifndef TEST_DEFINE +# error Expected definition TEST_DEFINE #endif -int main(int argc, char **argv) +#ifndef NEEDS_ESCAPE +# error Expected definition NEEDS_ESCAPE +#endif + +#ifdef DO_GNU_TESTS +# ifndef TEST_DEFINE_GNU +# error Expected definition TEST_DEFINE_GNU +# endif +#endif + +#include + +int main() { - return 0; + return strcmp(NEEDS_ESCAPE, "E$CAPE") == 0 ? 0 : 1; }