cmGlobalMSYSMakefileGenerator.cxx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. this->MSYSShell = true;
  22. }
  23. std::string
  24. cmGlobalMSYSMakefileGenerator::FindMinGW(std::string const& makeloc)
  25. {
  26. std::string fstab = makeloc;
  27. fstab += "/../etc/fstab";
  28. cmsys::ifstream fin(fstab.c_str());
  29. std::string path;
  30. std::string mount;
  31. std::string mingwBin;
  32. while(fin)
  33. {
  34. fin >> path;
  35. fin >> mount;
  36. if(mount == "/mingw")
  37. {
  38. mingwBin = path;
  39. mingwBin += "/bin";
  40. }
  41. }
  42. return mingwBin;
  43. }
  44. void cmGlobalMSYSMakefileGenerator
  45. ::EnableLanguage(std::vector<std::string>const& l,
  46. cmMakefile *mf,
  47. bool optional)
  48. {
  49. this->FindMakeProgram(mf);
  50. std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
  51. std::vector<std::string> locations;
  52. std::string makeloc = cmSystemTools::GetProgramPath(makeProgram.c_str());
  53. locations.push_back(this->FindMinGW(makeloc));
  54. locations.push_back(makeloc);
  55. locations.push_back("/mingw/bin");
  56. locations.push_back("c:/mingw/bin");
  57. std::string tgcc = cmSystemTools::FindProgram("gcc", locations);
  58. std::string gcc = "gcc.exe";
  59. if(tgcc.size())
  60. {
  61. gcc = tgcc;
  62. }
  63. std::string tgxx = cmSystemTools::FindProgram("g++", locations);
  64. std::string gxx = "g++.exe";
  65. if(tgxx.size())
  66. {
  67. gxx = tgxx;
  68. }
  69. std::string trc = cmSystemTools::FindProgram("windres", locations);
  70. std::string rc = "windres.exe";
  71. if(trc.size())
  72. {
  73. rc = trc;
  74. }
  75. mf->AddDefinition("MSYS", "1");
  76. mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str());
  77. mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str());
  78. mf->AddDefinition("CMAKE_GENERATOR_RC", rc.c_str());
  79. this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
  80. if(!mf->IsSet("CMAKE_AR") &&
  81. !this->CMakeInstance->GetIsInTryCompile() &&
  82. !(1==l.size() && l[0]=="NONE"))
  83. {
  84. cmSystemTools::Error
  85. ("CMAKE_AR was not found, please set to archive program. ",
  86. mf->GetDefinition("CMAKE_AR"));
  87. }
  88. }
  89. //----------------------------------------------------------------------------
  90. void cmGlobalMSYSMakefileGenerator
  91. ::GetDocumentation(cmDocumentationEntry& entry)
  92. {
  93. entry.Name = cmGlobalMSYSMakefileGenerator::GetActualName();
  94. entry.Brief = "Generates MSYS makefiles.";
  95. }