Merge topic 'ninja-gcc-windows'

20560e8d Ninja: Do not use newlines in response files with Windows GNU tools (#15439)
b3de0dfe Ninja: Use forward slashes for any GCC on Windows (#15439)
378c2a0e Ninja: Refactor detection of MinGW tools on Windows
957c2aac RC: Simplify selection of resource compiler based on C/C++ toolchain
This commit is contained in:
Brad King 2015-05-08 09:41:20 -04:00 committed by CMake Topic Stage
commit e38a2b5953
10 changed files with 64 additions and 57 deletions

View File

@ -53,5 +53,9 @@ macro(__cygwin_compiler_gnu lang)
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS} -Wl,--enable-auto-import") set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS} -Wl,--enable-auto-import")
set(CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS}") set(CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS}")
if(NOT CMAKE_RC_COMPILER_INIT)
set(CMAKE_RC_COMPILER_INIT windres)
endif()
enable_language(RC) enable_language(RC)
endmacro() endmacro()

View File

@ -138,6 +138,10 @@ macro(__windows_compiler_gnu lang)
endforeach() endforeach()
endif() endif()
if(NOT CMAKE_RC_COMPILER_INIT)
set(CMAKE_RC_COMPILER_INIT windres)
endif()
enable_language(RC) enable_language(RC)
endmacro() endmacro()

View File

@ -298,6 +298,9 @@ macro(__windows_compiler_msvc lang)
set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "/MD /O1 /Ob1 /D NDEBUG") set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "/MD /O1 /Ob1 /D NDEBUG")
set(CMAKE_${lang}_LINKER_SUPPORTS_PDB ON) set(CMAKE_${lang}_LINKER_SUPPORTS_PDB ON)
if(NOT CMAKE_RC_COMPILER_INIT)
set(CMAKE_RC_COMPILER_INIT rc)
endif()
if(NOT CMAKE_RC_FLAGS_INIT) if(NOT CMAKE_RC_FLAGS_INIT)
set(CMAKE_RC_FLAGS_INIT "${_PLATFORM_DEFINES} ${_PLATFORM_DEFINES_${lang}}") set(CMAKE_RC_FLAGS_INIT "${_PLATFORM_DEFINES} ${_PLATFORM_DEFINES_${lang}}")
endif() endif()

View File

@ -2420,38 +2420,6 @@ bool cmGlobalGenerator::UseFolderProperty()
return false; return false;
} }
//----------------------------------------------------------------------------
void cmGlobalGenerator::EnableMinGWLanguage(cmMakefile *mf)
{
this->FindMakeProgram(mf);
std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
std::vector<std::string> locations;
locations.push_back(cmSystemTools::GetProgramPath(makeProgram));
locations.push_back("/mingw/bin");
locations.push_back("c:/mingw/bin");
std::string tgcc = cmSystemTools::FindProgram("gcc", locations);
std::string gcc = "gcc.exe";
if(!tgcc.empty())
{
gcc = tgcc;
}
std::string tgxx = cmSystemTools::FindProgram("g++", locations);
std::string gxx = "g++.exe";
if(!tgxx.empty())
{
gxx = tgxx;
}
std::string trc = cmSystemTools::FindProgram("windres", locations);
std::string rc = "windres.exe";
if(!trc.empty())
{
rc = trc;
}
mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str());
mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str());
mf->AddDefinition("CMAKE_GENERATOR_RC", rc.c_str());
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmTarget cmGlobalGenerator::CreateGlobalTarget( cmTarget cmGlobalGenerator::CreateGlobalTarget(
const std::string& name, const char* message, const std::string& name, const char* message,

View File

@ -433,7 +433,6 @@ protected:
virtual const char* GetPredefinedTargetsFolder(); virtual const char* GetPredefinedTargetsFolder();
virtual bool UseFolderProperty(); virtual bool UseFolderProperty();
void EnableMinGWLanguage(cmMakefile *mf);
private: private:
cmMakefile* TryCompileOuterMakefile; cmMakefile* TryCompileOuterMakefile;

View File

@ -26,7 +26,33 @@ void cmGlobalMinGWMakefileGenerator
cmMakefile *mf, cmMakefile *mf,
bool optional) bool optional)
{ {
this->EnableMinGWLanguage(mf); this->FindMakeProgram(mf);
std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
std::vector<std::string> locations;
locations.push_back(cmSystemTools::GetProgramPath(makeProgram));
locations.push_back("/mingw/bin");
locations.push_back("c:/mingw/bin");
std::string tgcc = cmSystemTools::FindProgram("gcc", locations);
std::string gcc = "gcc.exe";
if(!tgcc.empty())
{
gcc = tgcc;
}
std::string tgxx = cmSystemTools::FindProgram("g++", locations);
std::string gxx = "g++.exe";
if(!tgxx.empty())
{
gxx = tgxx;
}
std::string trc = cmSystemTools::FindProgram("windres", locations);
std::string rc = "windres.exe";
if(!trc.empty())
{
rc = trc;
}
mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str());
mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str());
mf->AddDefinition("CMAKE_GENERATOR_RC", rc.c_str());
this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional); this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
} }

View File

@ -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->IsGCCOnWindows())
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()
, UsingGCCOnWindows(false)
, ComputingUnknownDependencies(false) , ComputingUnknownDependencies(false)
, PolicyCMP0058(cmPolicies::WARN) , PolicyCMP0058(cmPolicies::WARN)
{ {
@ -544,24 +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;
this->EnableMinGWLanguage(makefile);
}
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)
{ {
@ -569,12 +562,20 @@ void cmGlobalNinjaGenerator
{ {
continue; continue;
} }
this->ResolveLanguageCompiler(*l, makefile, optional); this->ResolveLanguageCompiler(*l, mf, optional);
} }
#ifdef _WIN32
if (mf->IsOn("CMAKE_COMPILER_IS_MINGW") ||
strcmp(mf->GetSafeDefinition("CMAKE_C_COMPILER_ID"), "GNU") == 0 ||
strcmp(mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID"), "GNU") == 0 ||
strcmp(mf->GetSafeDefinition("CMAKE_C_SIMULATE_ID"), "GNU") == 0 ||
strcmp(mf->GetSafeDefinition("CMAKE_CXX_SIMULATE_ID"), "GNU") == 0)
{
this->UsingGCCOnWindows = true;
}
#endif
} }
bool cmGlobalNinjaGenerator::UsingMinGW = false;
// Implemented by: // Implemented by:
// cmGlobalUnixMakefileGenerator3 // cmGlobalUnixMakefileGenerator3
// cmGlobalGhsMultiGenerator // cmGlobalGhsMultiGenerator

View File

@ -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 IsGCCOnWindows() const { return UsingGCCOnWindows; }
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 UsingGCCOnWindows;
/// 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

View File

@ -202,7 +202,12 @@ cmNinjaNormalTargetGenerator
responseFlag += rspfile; responseFlag += rspfile;
// build response file content // build response file content
rspcontent = "$in_newline $LINK_PATH $LINK_LIBRARIES"; if (this->GetGlobalGenerator()->IsGCCOnWindows()) {
rspcontent = "$in";
} else {
rspcontent = "$in_newline";
}
rspcontent += " $LINK_PATH $LINK_LIBRARIES";
vars.Objects = responseFlag.c_str(); vars.Objects = responseFlag.c_str();
vars.LinkLibraries = ""; vars.LinkLibraries = "";
} }

View File

@ -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()->IsGCCOnWindows())
cmSystemTools::ReplaceString(includeFlags, "\\", "/"); cmSystemTools::ReplaceString(includeFlags, "\\", "/");
this->LocalGenerator->AppendFlags(languageFlags, includeFlags); this->LocalGenerator->AppendFlags(languageFlags, includeFlags);