Ninja: Refactor detection of MinGW tools on Windows
Check for CMAKE_COMPILER_IS_MINGW only after enabling a language when it might actually be set. Previously this worked by accident because the check for working compiler or a second language enabled would cause the code path to be taken. Store UsingMinGW as an instance member of cmGlobalNinjaGenerator so that it is reset on each reconfigure. Otherwise cmake-gui cannot switch between build trees for MinGW or non-MinGW tools.
This commit is contained in:
parent
957c2aac7f
commit
378c2a0e86
|
@ -96,7 +96,7 @@ std::string cmGlobalNinjaGenerator::EncodePath(const std::string &path)
|
||||||
{
|
{
|
||||||
std::string result = path;
|
std::string result = path;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if(UsingMinGW)
|
if (this->IsMinGW())
|
||||||
cmSystemTools::ReplaceString(result, "\\", "/");
|
cmSystemTools::ReplaceString(result, "\\", "/");
|
||||||
else
|
else
|
||||||
cmSystemTools::ReplaceString(result, "/", "\\");
|
cmSystemTools::ReplaceString(result, "/", "\\");
|
||||||
|
@ -484,6 +484,7 @@ cmGlobalNinjaGenerator::cmGlobalNinjaGenerator()
|
||||||
, CompileCommandsStream(0)
|
, CompileCommandsStream(0)
|
||||||
, Rules()
|
, Rules()
|
||||||
, AllDependencies()
|
, AllDependencies()
|
||||||
|
, UsingMinGW(false)
|
||||||
, ComputingUnknownDependencies(false)
|
, ComputingUnknownDependencies(false)
|
||||||
, PolicyCMP0058(cmPolicies::WARN)
|
, PolicyCMP0058(cmPolicies::WARN)
|
||||||
{
|
{
|
||||||
|
@ -544,23 +545,16 @@ void cmGlobalNinjaGenerator::Generate()
|
||||||
this->CloseBuildFileStream();
|
this->CloseBuildFileStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implemented in all cmGlobaleGenerator sub-classes.
|
|
||||||
// Used in:
|
|
||||||
// Source/cmMakefile.cxx:
|
|
||||||
void cmGlobalNinjaGenerator
|
void cmGlobalNinjaGenerator
|
||||||
::EnableLanguage(std::vector<std::string>const& langs,
|
::EnableLanguage(std::vector<std::string>const& langs,
|
||||||
cmMakefile* makefile,
|
cmMakefile* mf,
|
||||||
bool optional)
|
bool optional)
|
||||||
{
|
{
|
||||||
if (makefile->IsOn("CMAKE_COMPILER_IS_MINGW"))
|
|
||||||
{
|
|
||||||
UsingMinGW = true;
|
|
||||||
}
|
|
||||||
if (std::find(langs.begin(), langs.end(), "Fortran") != langs.end())
|
if (std::find(langs.begin(), langs.end(), "Fortran") != langs.end())
|
||||||
{
|
{
|
||||||
cmSystemTools::Error("The Ninja generator does not support Fortran yet.");
|
cmSystemTools::Error("The Ninja generator does not support Fortran yet.");
|
||||||
}
|
}
|
||||||
this->cmGlobalGenerator::EnableLanguage(langs, makefile, optional);
|
this->cmGlobalGenerator::EnableLanguage(langs, mf, optional);
|
||||||
for(std::vector<std::string>::const_iterator l = langs.begin();
|
for(std::vector<std::string>::const_iterator l = langs.begin();
|
||||||
l != langs.end(); ++l)
|
l != langs.end(); ++l)
|
||||||
{
|
{
|
||||||
|
@ -568,11 +562,15 @@ void cmGlobalNinjaGenerator
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this->ResolveLanguageCompiler(*l, makefile, optional);
|
this->ResolveLanguageCompiler(*l, mf, optional);
|
||||||
}
|
}
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (mf->IsOn("CMAKE_COMPILER_IS_MINGW"))
|
||||||
|
{
|
||||||
|
this->UsingMinGW = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmGlobalNinjaGenerator::UsingMinGW = false;
|
|
||||||
|
|
||||||
// Implemented by:
|
// Implemented by:
|
||||||
// cmGlobalUnixMakefileGenerator3
|
// cmGlobalUnixMakefileGenerator3
|
||||||
|
|
|
@ -63,7 +63,7 @@ public:
|
||||||
|
|
||||||
static std::string EncodeIdent(const std::string &ident, std::ostream &vars);
|
static std::string EncodeIdent(const std::string &ident, std::ostream &vars);
|
||||||
static std::string EncodeLiteral(const std::string &lit);
|
static std::string EncodeLiteral(const std::string &lit);
|
||||||
static std::string EncodePath(const std::string &path);
|
std::string EncodePath(const std::string &path);
|
||||||
static std::string EncodeDepfileSpace(const std::string &path);
|
static std::string EncodeDepfileSpace(const std::string &path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -155,9 +155,7 @@ public:
|
||||||
const cmNinjaDeps& targets,
|
const cmNinjaDeps& targets,
|
||||||
const std::string& comment = "");
|
const std::string& comment = "");
|
||||||
|
|
||||||
|
bool IsMinGW() const { return this->UsingMinGW; }
|
||||||
static bool IsMinGW() { return UsingMinGW; }
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Default constructor.
|
/// Default constructor.
|
||||||
|
@ -362,6 +360,8 @@ private:
|
||||||
/// The set of dependencies to add to the "all" target.
|
/// The set of dependencies to add to the "all" target.
|
||||||
cmNinjaDeps AllDependencies;
|
cmNinjaDeps AllDependencies;
|
||||||
|
|
||||||
|
bool UsingMinGW;
|
||||||
|
|
||||||
/// The set of custom commands we have seen.
|
/// The set of custom commands we have seen.
|
||||||
std::set<cmCustomCommand const*> CustomCommands;
|
std::set<cmCustomCommand const*> CustomCommands;
|
||||||
|
|
||||||
|
@ -385,9 +385,6 @@ private:
|
||||||
|
|
||||||
typedef std::map<std::string, cmTarget*> TargetAliasMap;
|
typedef std::map<std::string, cmTarget*> TargetAliasMap;
|
||||||
TargetAliasMap TargetAliases;
|
TargetAliasMap TargetAliases;
|
||||||
|
|
||||||
static bool UsingMinGW;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ! cmGlobalNinjaGenerator_h
|
#endif // ! cmGlobalNinjaGenerator_h
|
||||||
|
|
|
@ -175,7 +175,7 @@ cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile const* source,
|
||||||
// needed by cmcldeps
|
// needed by cmcldeps
|
||||||
false,
|
false,
|
||||||
this->GetConfigName());
|
this->GetConfigName());
|
||||||
if(cmGlobalNinjaGenerator::IsMinGW())
|
if (this->GetGlobalGenerator()->IsMinGW())
|
||||||
cmSystemTools::ReplaceString(includeFlags, "\\", "/");
|
cmSystemTools::ReplaceString(includeFlags, "\\", "/");
|
||||||
|
|
||||||
this->LocalGenerator->AppendFlags(languageFlags, includeFlags);
|
this->LocalGenerator->AppendFlags(languageFlags, includeFlags);
|
||||||
|
|
Loading…
Reference in New Issue