cmGlobalMSYSMakefileGenerator.cxx 3.2 KB

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