cmGlobalMSYSMakefileGenerator.cxx 2.6 KB

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