cmGlobalJOMMakefileGenerator.cxx 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #include "cmGlobalJOMMakefileGenerator.h"
  4. #include <ostream>
  5. #include <cmext/algorithm>
  6. #include <cmext/string_view>
  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. cmDocumentationEntry cmGlobalJOMMakefileGenerator::GetDocumentation()
  34. {
  35. return { cmGlobalJOMMakefileGenerator::GetActualName(),
  36. "Generates JOM makefiles." };
  37. }
  38. void cmGlobalJOMMakefileGenerator::PrintCompilerAdvice(std::ostream& os,
  39. std::string const& lang,
  40. cmValue envVar) const
  41. {
  42. if (lang == "CXX"_s || lang == "C"_s) {
  43. /* clang-format off */
  44. os <<
  45. "To use the JOM generator with Visual C++, cmake must be run from a "
  46. "shell that can use the compiler cl from the command line. This "
  47. "environment is unable to invoke the cl compiler. To fix this problem, "
  48. "run cmake from the Visual Studio Command Prompt (vcvarsall.bat).\n";
  49. /* clang-format on */
  50. }
  51. this->cmGlobalUnixMakefileGenerator3::PrintCompilerAdvice(os, lang, envVar);
  52. }
  53. std::vector<cmGlobalGenerator::GeneratedMakeCommand>
  54. cmGlobalJOMMakefileGenerator::GenerateBuildCommand(
  55. std::string const& makeProgram, std::string const& projectName,
  56. std::string const& projectDir, std::vector<std::string> const& targetNames,
  57. std::string const& config, int jobs, bool verbose,
  58. cmBuildOptions buildOptions, std::vector<std::string> const& makeOptions)
  59. {
  60. std::vector<std::string> jomMakeOptions;
  61. // Since we have full control over the invocation of JOM, let us
  62. // make it quiet.
  63. jomMakeOptions.push_back(this->MakeSilentFlag);
  64. cm::append(jomMakeOptions, makeOptions);
  65. // JOM does parallel builds by default, the -j is only needed if a specific
  66. // number is given
  67. // see https://github.com/qt-labs/jom/blob/v1.1.2/src/jomlib/options.cpp
  68. if (jobs == cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
  69. jobs = cmake::NO_BUILD_PARALLEL_LEVEL;
  70. }
  71. return cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
  72. makeProgram, projectName, projectDir, targetNames, config, jobs, verbose,
  73. buildOptions, jomMakeOptions);
  74. }