cmGlobalMSYSMakefileGenerator.cxx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmGlobalMSYSMakefileGenerator.h"
  4. #include "cmsys/FStream.hxx"
  5. #include "cmDocumentationEntry.h"
  6. #include "cmLocalUnixMakefileGenerator3.h"
  7. #include "cmMakefile.h"
  8. #include "cmState.h"
  9. #include "cmake.h"
  10. cmGlobalMSYSMakefileGenerator::cmGlobalMSYSMakefileGenerator(cmake* cm)
  11. : cmGlobalUnixMakefileGenerator3(cm)
  12. {
  13. this->FindMakeProgramFile = "CMakeMSYSFindMake.cmake";
  14. this->ForceUnixPaths = true;
  15. this->ToolSupportsColor = true;
  16. this->UseLinkScript = false;
  17. cm->GetState()->SetMSYSShell(true);
  18. }
  19. std::string cmGlobalMSYSMakefileGenerator::FindMinGW(
  20. std::string const& makeloc)
  21. {
  22. std::string fstab = makeloc;
  23. fstab += "/../etc/fstab";
  24. cmsys::ifstream fin(fstab.c_str());
  25. std::string path;
  26. std::string mount;
  27. std::string mingwBin;
  28. while (fin) {
  29. fin >> path;
  30. fin >> mount;
  31. if (mount == "/mingw") {
  32. mingwBin = path;
  33. mingwBin += "/bin";
  34. }
  35. }
  36. return mingwBin;
  37. }
  38. void cmGlobalMSYSMakefileGenerator::EnableLanguage(
  39. std::vector<std::string> const& l, cmMakefile* mf, bool optional)
  40. {
  41. this->FindMakeProgram(mf);
  42. std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  43. std::vector<std::string> locations;
  44. std::string makeloc = cmSystemTools::GetProgramPath(makeProgram.c_str());
  45. locations.push_back(this->FindMinGW(makeloc));
  46. locations.push_back(makeloc);
  47. locations.push_back("/mingw/bin");
  48. locations.push_back("c:/mingw/bin");
  49. std::string tgcc = cmSystemTools::FindProgram("gcc", locations);
  50. std::string gcc = "gcc.exe";
  51. if (!tgcc.empty()) {
  52. gcc = tgcc;
  53. }
  54. std::string tgxx = cmSystemTools::FindProgram("g++", locations);
  55. std::string gxx = "g++.exe";
  56. if (!tgxx.empty()) {
  57. gxx = tgxx;
  58. }
  59. std::string trc = cmSystemTools::FindProgram("windres", locations);
  60. std::string rc = "windres.exe";
  61. if (!trc.empty()) {
  62. rc = trc;
  63. }
  64. mf->AddDefinition("MSYS", "1");
  65. mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str());
  66. mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str());
  67. mf->AddDefinition("CMAKE_GENERATOR_RC", rc.c_str());
  68. this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
  69. if (!mf->IsSet("CMAKE_AR") && !this->CMakeInstance->GetIsInTryCompile() &&
  70. !(1 == l.size() && l[0] == "NONE")) {
  71. cmSystemTools::Error(
  72. "CMAKE_AR was not found, please set to archive program. ",
  73. mf->GetDefinition("CMAKE_AR"));
  74. }
  75. }
  76. void cmGlobalMSYSMakefileGenerator::GetDocumentation(
  77. cmDocumentationEntry& entry)
  78. {
  79. entry.Name = cmGlobalMSYSMakefileGenerator::GetActualName();
  80. entry.Brief = "Generates MSYS makefiles.";
  81. }