cmGlobalMSYSMakefileGenerator.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. cmGlobalMSYSMakefileGenerator::cmGlobalMSYSMakefileGenerator()
  15. {
  16. this->FindMakeProgramFile = "CMakeMSYSFindMake.cmake";
  17. this->ForceUnixPaths = true;
  18. this->ToolSupportsColor = true;
  19. this->UseLinkScript = false;
  20. }
  21. std::string
  22. cmGlobalMSYSMakefileGenerator::FindMinGW(std::string const& makeloc)
  23. {
  24. std::string fstab = makeloc;
  25. fstab += "/../etc/fstab";
  26. std::ifstream fin(fstab.c_str());
  27. std::string path;
  28. std::string mount;
  29. std::string mingwBin;
  30. while(fin)
  31. {
  32. fin >> path;
  33. fin >> mount;
  34. if(mount == "/mingw")
  35. {
  36. mingwBin = path;
  37. mingwBin += "/bin";
  38. }
  39. }
  40. return mingwBin;
  41. }
  42. void cmGlobalMSYSMakefileGenerator
  43. ::EnableLanguage(std::vector<std::string>const& l,
  44. cmMakefile *mf,
  45. bool optional)
  46. {
  47. this->FindMakeProgram(mf);
  48. std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  49. std::vector<std::string> locations;
  50. std::string makeloc = cmSystemTools::GetProgramPath(makeProgram.c_str());
  51. locations.push_back(this->FindMinGW(makeloc));
  52. locations.push_back(makeloc);
  53. locations.push_back("/mingw/bin");
  54. locations.push_back("c:/mingw/bin");
  55. std::string tgcc = cmSystemTools::FindProgram("gcc", locations);
  56. std::string gcc = "gcc.exe";
  57. if(tgcc.size())
  58. {
  59. gcc = tgcc;
  60. }
  61. std::string tgxx = cmSystemTools::FindProgram("g++", locations);
  62. std::string gxx = "g++.exe";
  63. if(tgxx.size())
  64. {
  65. gxx = tgxx;
  66. }
  67. mf->AddDefinition("MSYS", "1");
  68. mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str());
  69. mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str());
  70. this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
  71. if(!mf->IsSet("CMAKE_AR") &&
  72. !this->CMakeInstance->GetIsInTryCompile() &&
  73. !(1==l.size() && l[0]=="NONE"))
  74. {
  75. cmSystemTools::Error
  76. ("CMAKE_AR was not found, please set to archive program. ",
  77. mf->GetDefinition("CMAKE_AR"));
  78. }
  79. }
  80. ///! Create a local generator appropriate to this Global Generator
  81. cmLocalGenerator *cmGlobalMSYSMakefileGenerator::CreateLocalGenerator()
  82. {
  83. cmLocalUnixMakefileGenerator3* lg = new cmLocalUnixMakefileGenerator3;
  84. lg->SetWindowsShell(false);
  85. lg->SetMSYSShell(true);
  86. lg->SetGlobalGenerator(this);
  87. lg->SetIgnoreLibPrefix(true);
  88. lg->SetPassMakeflags(false);
  89. lg->SetUnixCD(true);
  90. return lg;
  91. }
  92. //----------------------------------------------------------------------------
  93. void cmGlobalMSYSMakefileGenerator
  94. ::GetDocumentation(cmDocumentationEntry& entry) const
  95. {
  96. entry.Name = this->GetName();
  97. entry.Brief = "Generates MSYS makefiles.";
  98. entry.Full = "The makefiles use /bin/sh as the shell. "
  99. "They require msys to be installed on the machine.";
  100. }