cmGlobalMSYSMakefileGenerator.cxx 2.7 KB

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