cmGlobalMSYSMakefileGenerator.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmGlobalMSYSMakefileGenerator.h"
  11. #include "cmLocalUnixMakefileGenerator3.h"
  12. #include "cmMakefile.h"
  13. #include "cmake.h"
  14. #include <cmsys/FStream.hxx>
  15. cmGlobalMSYSMakefileGenerator::cmGlobalMSYSMakefileGenerator()
  16. {
  17. this->FindMakeProgramFile = "CMakeMSYSFindMake.cmake";
  18. this->ForceUnixPaths = true;
  19. this->ToolSupportsColor = true;
  20. this->UseLinkScript = false;
  21. }
  22. std::string
  23. cmGlobalMSYSMakefileGenerator::FindMinGW(std::string const& makeloc)
  24. {
  25. std::string fstab = makeloc;
  26. fstab += "/../etc/fstab";
  27. cmsys::ifstream fin(fstab.c_str());
  28. std::string path;
  29. std::string mount;
  30. std::string mingwBin;
  31. while(fin)
  32. {
  33. fin >> path;
  34. fin >> mount;
  35. if(mount == "/mingw")
  36. {
  37. mingwBin = path;
  38. mingwBin += "/bin";
  39. }
  40. }
  41. return mingwBin;
  42. }
  43. void cmGlobalMSYSMakefileGenerator
  44. ::EnableLanguage(std::vector<std::string>const& l,
  45. cmMakefile *mf,
  46. bool optional)
  47. {
  48. this->FindMakeProgram(mf);
  49. std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  50. std::vector<std::string> locations;
  51. std::string makeloc = cmSystemTools::GetProgramPath(makeProgram.c_str());
  52. locations.push_back(this->FindMinGW(makeloc));
  53. locations.push_back(makeloc);
  54. locations.push_back("/mingw/bin");
  55. locations.push_back("c:/mingw/bin");
  56. std::string tgcc = cmSystemTools::FindProgram("gcc", locations);
  57. std::string gcc = "gcc.exe";
  58. if(tgcc.size())
  59. {
  60. gcc = tgcc;
  61. }
  62. std::string tgxx = cmSystemTools::FindProgram("g++", locations);
  63. std::string gxx = "g++.exe";
  64. if(tgxx.size())
  65. {
  66. gxx = tgxx;
  67. }
  68. std::string trc = cmSystemTools::FindProgram("windres", locations);
  69. std::string rc = "windres.exe";
  70. if(trc.size())
  71. {
  72. rc = trc;
  73. }
  74. mf->AddDefinition("MSYS", "1");
  75. mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str());
  76. mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str());
  77. mf->AddDefinition("CMAKE_GENERATOR_RC", rc.c_str());
  78. this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
  79. if(!mf->IsSet("CMAKE_AR") &&
  80. !this->CMakeInstance->GetIsInTryCompile() &&
  81. !(1==l.size() && l[0]=="NONE"))
  82. {
  83. cmSystemTools::Error
  84. ("CMAKE_AR was not found, please set to archive program. ",
  85. mf->GetDefinition("CMAKE_AR"));
  86. }
  87. }
  88. ///! Create a local generator appropriate to this Global Generator
  89. cmLocalGenerator *cmGlobalMSYSMakefileGenerator::CreateLocalGenerator()
  90. {
  91. cmLocalUnixMakefileGenerator3* lg = new cmLocalUnixMakefileGenerator3;
  92. lg->SetWindowsShell(false);
  93. lg->SetMSYSShell(true);
  94. lg->SetGlobalGenerator(this);
  95. lg->SetIgnoreLibPrefix(true);
  96. lg->SetPassMakeflags(false);
  97. lg->SetUnixCD(true);
  98. return lg;
  99. }
  100. //----------------------------------------------------------------------------
  101. void cmGlobalMSYSMakefileGenerator
  102. ::GetDocumentation(cmDocumentationEntry& entry)
  103. {
  104. entry.Name = cmGlobalMSYSMakefileGenerator::GetActualName();
  105. entry.Brief = "Generates MSYS makefiles.";
  106. }