cmake/Source/cmGlobalMSYSMakefileGenerator.cxx

91 lines
2.7 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGlobalMSYSMakefileGenerator.h"
2016-07-09 11:21:54 +02:00
2017-07-20 19:35:53 +02:00
#include "cmsys/FStream.hxx"
2017-04-14 19:02:05 +02:00
#include "cmDocumentationEntry.h"
#include "cmLocalUnixMakefileGenerator3.h"
#include "cmMakefile.h"
2019-11-11 23:01:05 +01:00
#include "cmMessageType.h"
2017-04-14 19:02:05 +02:00
#include "cmState.h"
#include "cmake.h"
2015-08-17 11:37:30 +02:00
cmGlobalMSYSMakefileGenerator::cmGlobalMSYSMakefileGenerator(cmake* cm)
: cmGlobalUnixMakefileGenerator3(cm)
{
this->FindMakeProgramFile = "CMakeMSYSFindMake.cmake";
this->ForceUnixPaths = true;
this->ToolSupportsColor = true;
this->UseLinkScript = false;
2015-08-17 11:37:30 +02:00
cm->GetState()->SetMSYSShell(true);
}
2016-07-09 11:21:54 +02:00
std::string cmGlobalMSYSMakefileGenerator::FindMinGW(
std::string const& makeloc)
{
std::string fstab = makeloc;
fstab += "/../etc/fstab";
2014-08-03 19:52:23 +02:00
cmsys::ifstream fin(fstab.c_str());
std::string path;
std::string mount;
std::string mingwBin;
2016-07-09 11:21:54 +02:00
while (fin) {
fin >> path;
fin >> mount;
2016-07-09 11:21:54 +02:00
if (mount == "/mingw") {
mingwBin = path;
mingwBin += "/bin";
}
2016-07-09 11:21:54 +02:00
}
return mingwBin;
}
2016-07-09 11:21:54 +02:00
void cmGlobalMSYSMakefileGenerator::EnableLanguage(
std::vector<std::string> const& l, cmMakefile* mf, bool optional)
{
this->FindMakeProgram(mf);
2019-11-11 23:01:05 +01:00
const std::string& makeProgram =
mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
std::vector<std::string> locations;
2019-11-11 23:01:05 +01:00
std::string makeloc = cmSystemTools::GetProgramPath(makeProgram);
locations.push_back(this->FindMinGW(makeloc));
locations.push_back(makeloc);
locations.push_back("/mingw/bin");
locations.push_back("c:/mingw/bin");
std::string tgcc = cmSystemTools::FindProgram("gcc", locations);
std::string gcc = "gcc.exe";
2016-07-09 11:21:54 +02:00
if (!tgcc.empty()) {
gcc = tgcc;
2016-07-09 11:21:54 +02:00
}
std::string tgxx = cmSystemTools::FindProgram("g++", locations);
std::string gxx = "g++.exe";
2016-07-09 11:21:54 +02:00
if (!tgxx.empty()) {
gxx = tgxx;
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
std::string trc = cmSystemTools::FindProgram("windres", locations);
std::string rc = "windres.exe";
2016-07-09 11:21:54 +02:00
if (!trc.empty()) {
2011-01-16 11:35:12 +01:00
rc = trc;
2016-07-09 11:21:54 +02:00
}
mf->AddDefinition("MSYS", "1");
mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str());
mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str());
2011-01-16 11:35:12 +01:00
mf->AddDefinition("CMAKE_GENERATOR_RC", rc.c_str());
this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
2016-07-09 11:21:54 +02:00
if (!mf->IsSet("CMAKE_AR") && !this->CMakeInstance->GetIsInTryCompile() &&
!(1 == l.size() && l[0] == "NONE")) {
cmSystemTools::Error(
2019-11-11 23:01:05 +01:00
"CMAKE_AR was not found, please set to archive program. " +
mf->GetSafeDefinition("CMAKE_AR"));
2016-07-09 11:21:54 +02:00
}
}
2016-07-09 11:21:54 +02:00
void cmGlobalMSYSMakefileGenerator::GetDocumentation(
cmDocumentationEntry& entry)
{
2013-03-16 19:13:01 +02:00
entry.Name = cmGlobalMSYSMakefileGenerator::GetActualName();
entry.Brief = "Generates MSYS makefiles.";
}