cmGlobalJOMMakefileGenerator.cxx 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 "cmGlobalJOMMakefileGenerator.h"
  4. #include <ostream>
  5. #include <cmext/algorithm>
  6. #include "cmDocumentationEntry.h"
  7. #include "cmGlobalGenerator.h"
  8. #include "cmMakefile.h"
  9. #include "cmState.h"
  10. #include "cmake.h"
  11. cmGlobalJOMMakefileGenerator::cmGlobalJOMMakefileGenerator(cmake* cm)
  12. : cmGlobalUnixMakefileGenerator3(cm)
  13. {
  14. this->FindMakeProgramFile = "CMakeJOMFindMake.cmake";
  15. this->ForceUnixPaths = false;
  16. this->ToolSupportsColor = true;
  17. this->UseLinkScript = false;
  18. cm->GetState()->SetWindowsShell(true);
  19. cm->GetState()->SetNMake(true);
  20. this->DefineWindowsNULL = true;
  21. this->PassMakeflags = true;
  22. this->UnixCD = false;
  23. this->MakeSilentFlag = "/nologo";
  24. }
  25. void cmGlobalJOMMakefileGenerator::EnableLanguage(
  26. std::vector<std::string> const& l, cmMakefile* mf, bool optional)
  27. {
  28. // pick a default
  29. mf->AddDefinition("CMAKE_GENERATOR_CC", "cl");
  30. mf->AddDefinition("CMAKE_GENERATOR_CXX", "cl");
  31. this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
  32. }
  33. void cmGlobalJOMMakefileGenerator::GetDocumentation(
  34. cmDocumentationEntry& entry)
  35. {
  36. entry.Name = cmGlobalJOMMakefileGenerator::GetActualName();
  37. entry.Brief = "Generates JOM makefiles.";
  38. }
  39. void cmGlobalJOMMakefileGenerator::PrintCompilerAdvice(std::ostream& os,
  40. std::string const& lang,
  41. cmValue envVar) const
  42. {
  43. if (lang == "CXX" || lang == "C") {
  44. /* clang-format off */
  45. os <<
  46. "To use the JOM generator with Visual C++, cmake must be run from a "
  47. "shell that can use the compiler cl from the command line. This "
  48. "environment is unable to invoke the cl compiler. To fix this problem, "
  49. "run cmake from the Visual Studio Command Prompt (vcvarsall.bat).\n";
  50. /* clang-format on */
  51. }
  52. this->cmGlobalUnixMakefileGenerator3::PrintCompilerAdvice(os, lang, envVar);
  53. }
  54. std::vector<cmGlobalGenerator::GeneratedMakeCommand>
  55. cmGlobalJOMMakefileGenerator::GenerateBuildCommand(
  56. const std::string& makeProgram, const std::string& projectName,
  57. const std::string& projectDir, std::vector<std::string> const& targetNames,
  58. const std::string& config, bool fast, int jobs, bool verbose,
  59. std::vector<std::string> const& makeOptions)
  60. {
  61. std::vector<std::string> jomMakeOptions;
  62. // Since we have full control over the invocation of JOM, let us
  63. // make it quiet.
  64. jomMakeOptions.push_back(this->MakeSilentFlag);
  65. cm::append(jomMakeOptions, makeOptions);
  66. // JOM does parallel builds by default, the -j is only needed if a specific
  67. // number is given
  68. // see https://github.com/qt-labs/jom/blob/v1.1.2/src/jomlib/options.cpp
  69. if (jobs == cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
  70. jobs = cmake::NO_BUILD_PARALLEL_LEVEL;
  71. }
  72. return cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
  73. makeProgram, projectName, projectDir, targetNames, config, fast, jobs,
  74. verbose, jomMakeOptions);
  75. }