cmGlobalNMakeMakefileGenerator.cxx 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 "cmGlobalNMakeMakefileGenerator.h"
  4. #include "cmDocumentationEntry.h"
  5. #include "cmLocalUnixMakefileGenerator3.h"
  6. #include "cmMakefile.h"
  7. #include "cmState.h"
  8. #include "cmake.h"
  9. cmGlobalNMakeMakefileGenerator::cmGlobalNMakeMakefileGenerator(cmake* cm)
  10. : cmGlobalUnixMakefileGenerator3(cm)
  11. {
  12. this->FindMakeProgramFile = "CMakeNMakeFindMake.cmake";
  13. this->ForceUnixPaths = false;
  14. this->ToolSupportsColor = true;
  15. this->UseLinkScript = false;
  16. cm->GetState()->SetWindowsShell(true);
  17. cm->GetState()->SetNMake(true);
  18. this->DefineWindowsNULL = true;
  19. this->PassMakeflags = true;
  20. this->UnixCD = false;
  21. this->MakeSilentFlag = "/nologo";
  22. }
  23. void cmGlobalNMakeMakefileGenerator::EnableLanguage(
  24. std::vector<std::string> const& l, cmMakefile* mf, bool optional)
  25. {
  26. // pick a default
  27. mf->AddDefinition("CMAKE_GENERATOR_CC", "cl");
  28. mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl");
  29. this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
  30. }
  31. void cmGlobalNMakeMakefileGenerator::GetDocumentation(
  32. cmDocumentationEntry& entry)
  33. {
  34. entry.Name = cmGlobalNMakeMakefileGenerator::GetActualName();
  35. entry.Brief = "Generates NMake makefiles.";
  36. }
  37. void cmGlobalNMakeMakefileGenerator::PrintCompilerAdvice(
  38. std::ostream& os, std::string const& lang, const char* envVar) const
  39. {
  40. if (lang == "CXX" || lang == "C") {
  41. /* clang-format off */
  42. os <<
  43. "To use the NMake generator with Visual C++, cmake must be run from a "
  44. "shell that can use the compiler cl from the command line. This "
  45. "environment is unable to invoke the cl compiler. To fix this problem, "
  46. "run cmake from the Visual Studio Command Prompt (vcvarsall.bat).\n";
  47. /* clang-format on */
  48. }
  49. this->cmGlobalUnixMakefileGenerator3::PrintCompilerAdvice(os, lang, envVar);
  50. }
  51. std::vector<cmGlobalGenerator::GeneratedMakeCommand>
  52. cmGlobalNMakeMakefileGenerator::GenerateBuildCommand(
  53. const std::string& makeProgram, const std::string& projectName,
  54. const std::string& projectDir, std::vector<std::string> const& targetNames,
  55. const std::string& config, bool fast, int /*jobs*/, bool verbose,
  56. std::vector<std::string> const& makeOptions)
  57. {
  58. std::vector<std::string> nmakeMakeOptions;
  59. // Since we have full control over the invocation of nmake, let us
  60. // make it quiet.
  61. nmakeMakeOptions.push_back(this->MakeSilentFlag);
  62. cm::append(nmakeMakeOptions, makeOptions);
  63. return this->cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
  64. makeProgram, projectName, projectDir, targetNames, config, fast,
  65. cmake::NO_BUILD_PARALLEL_LEVEL, verbose, nmakeMakeOptions);
  66. }
  67. void cmGlobalNMakeMakefileGenerator::PrintBuildCommandAdvice(std::ostream& os,
  68. int jobs) const
  69. {
  70. if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
  71. // nmake does not support parallel build level
  72. // see https://msdn.microsoft.com/en-us/library/afyyse50.aspx
  73. /* clang-format off */
  74. os <<
  75. "Warning: NMake does not support parallel builds. "
  76. "Ignoring parallel build command line option.\n";
  77. /* clang-format on */
  78. }
  79. this->cmGlobalUnixMakefileGenerator3::PrintBuildCommandAdvice(
  80. os, cmake::NO_BUILD_PARALLEL_LEVEL);
  81. }