Escape target flags taken from COMPILE_OPTIONS
Factor appending of individual flags out into an AppendFlagEscape method in cmLocalGenerator and teach it to use EscapeForShell. Update all COMPILE_OPTIONS handling to use AppendFlagEscape. Override the method in the Xcode generator to use its custom escape implementation. Teach the CompileOptions test to add an option that requires escaping everywhere instead of just with the GNU tools.
This commit is contained in:
parent
0c9cc9a077
commit
b6385cabec
|
@ -85,6 +85,7 @@ public:
|
||||||
virtual bool IsMultiConfig();
|
virtual bool IsMultiConfig();
|
||||||
|
|
||||||
virtual bool SetGeneratorToolset(std::string const& ts);
|
virtual bool SetGeneratorToolset(std::string const& ts);
|
||||||
|
void AppendFlag(std::string& flags, std::string const& flag);
|
||||||
private:
|
private:
|
||||||
cmXCodeObject* CreateOrGetPBXGroup(cmTarget& cmtarget,
|
cmXCodeObject* CreateOrGetPBXGroup(cmTarget& cmtarget,
|
||||||
cmSourceGroup* sg);
|
cmSourceGroup* sg);
|
||||||
|
@ -198,7 +199,6 @@ private:
|
||||||
void AppendDefines(BuildObjectListOrString& defs,
|
void AppendDefines(BuildObjectListOrString& defs,
|
||||||
std::vector<std::string> const& defines,
|
std::vector<std::string> const& defines,
|
||||||
bool dflag = false);
|
bool dflag = false);
|
||||||
void AppendFlag(std::string& flags, std::string const& flag);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual const char* GetInstallTargetName() const { return "install"; }
|
virtual const char* GetInstallTargetName() const { return "install"; }
|
||||||
|
|
|
@ -1354,7 +1354,7 @@ void cmLocalGenerator::GetCompileOptions(std::string& flags,
|
||||||
for(std::vector<std::string>::const_iterator li = opts.begin();
|
for(std::vector<std::string>::const_iterator li = opts.begin();
|
||||||
li != opts.end(); ++li)
|
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<std::string>::const_iterator oi = options.begin();
|
for(std::vector<std::string>::const_iterator oi = options.begin();
|
||||||
oi != options.end(); ++oi)
|
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<std::string>& defines,
|
void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
|
||||||
const char* defines_list)
|
const char* defines_list)
|
||||||
|
@ -2359,7 +2366,7 @@ void cmLocalGenerator::AppendFeatureOptions(
|
||||||
for(std::vector<std::string>::const_iterator oi = options.begin();
|
for(std::vector<std::string>::const_iterator oi = options.begin();
|
||||||
oi != options.end(); ++oi)
|
oi != options.end(); ++oi)
|
||||||
{
|
{
|
||||||
this->AppendFlags(flags, this->EscapeForShell(oi->c_str()).c_str());
|
this->AppendFlagEscape(flags, oi->c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,6 +149,7 @@ public:
|
||||||
const char* config);
|
const char* config);
|
||||||
///! Append flags to a string.
|
///! Append flags to a string.
|
||||||
virtual void AppendFlags(std::string& flags, const char* newFlags);
|
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
|
///! Get the include flags for the current makefile and language
|
||||||
std::string GetIncludeFlags(const std::vector<std::string> &includes,
|
std::string GetIncludeFlags(const std::vector<std::string> &includes,
|
||||||
const char* lang, bool forResponseFile = false,
|
const char* lang, bool forResponseFile = false,
|
||||||
|
|
|
@ -33,3 +33,12 @@ cmLocalXCodeGenerator::GetTargetDirectory(cmTarget const&) const
|
||||||
// No per-target directory for this generator (yet).
|
// No per-target directory for this generator (yet).
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void cmLocalXCodeGenerator::AppendFlagEscape(std::string& flags,
|
||||||
|
const char* rawFlag)
|
||||||
|
{
|
||||||
|
cmGlobalXCodeGenerator* gg =
|
||||||
|
static_cast<cmGlobalXCodeGenerator*>(this->GlobalGenerator);
|
||||||
|
gg->AppendFlag(flags, rawFlag);
|
||||||
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ public:
|
||||||
|
|
||||||
virtual ~cmLocalXCodeGenerator();
|
virtual ~cmLocalXCodeGenerator();
|
||||||
virtual std::string GetTargetDirectory(cmTarget const& target) const;
|
virtual std::string GetTargetDirectory(cmTarget const& target) const;
|
||||||
|
virtual void AppendFlagEscape(std::string& flags, const char* rawFlag);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,7 +5,11 @@ project(CompileOptions)
|
||||||
add_library(testlib other.cpp)
|
add_library(testlib other.cpp)
|
||||||
|
|
||||||
add_executable(CompileOptions main.cpp)
|
add_executable(CompileOptions main.cpp)
|
||||||
set_property(TARGET CompileOptions PROPERTY COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:GNU>:-DTEST_DEFINE>")
|
set_property(TARGET CompileOptions PROPERTY COMPILE_OPTIONS
|
||||||
|
"-DTEST_DEFINE"
|
||||||
|
"-DNEEDS_ESCAPE=\"E$CAPE\""
|
||||||
|
"$<$<CXX_COMPILER_ID:GNU>:-DTEST_DEFINE_GNU>"
|
||||||
|
)
|
||||||
target_link_libraries(CompileOptions testlib)
|
target_link_libraries(CompileOptions testlib)
|
||||||
|
|
||||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||||
|
|
|
@ -1,11 +1,20 @@
|
||||||
|
#ifndef TEST_DEFINE
|
||||||
|
# error Expected definition TEST_DEFINE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NEEDS_ESCAPE
|
||||||
|
# error Expected definition NEEDS_ESCAPE
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DO_GNU_TESTS
|
#ifdef DO_GNU_TESTS
|
||||||
# ifndef TEST_DEFINE
|
# ifndef TEST_DEFINE_GNU
|
||||||
# error Expected TEST_DEFINE
|
# error Expected definition TEST_DEFINE_GNU
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
#include <string.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
{
|
{
|
||||||
return 0;
|
return strcmp(NEEDS_ESCAPE, "E$CAPE") == 0 ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue