cmInstallSubdirectoryGenerator.cxx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 "cmInstallSubdirectoryGenerator.h"
  4. #include <memory>
  5. #include <sstream>
  6. #include <utility>
  7. #include <vector>
  8. #include "cmListFileCache.h"
  9. #include "cmLocalGenerator.h"
  10. #include "cmMakefile.h"
  11. #include "cmPolicies.h"
  12. #include "cmScriptGenerator.h"
  13. #include "cmSystemTools.h"
  14. cmInstallSubdirectoryGenerator::cmInstallSubdirectoryGenerator(
  15. cmMakefile* makefile, std::string binaryDirectory,
  16. cmListFileBacktrace backtrace)
  17. : cmInstallGenerator("", std::vector<std::string>(), "", MessageDefault,
  18. false, false, std::move(backtrace))
  19. , Makefile(makefile)
  20. , BinaryDirectory(std::move(binaryDirectory))
  21. {
  22. }
  23. cmInstallSubdirectoryGenerator::~cmInstallSubdirectoryGenerator() = default;
  24. bool cmInstallSubdirectoryGenerator::HaveInstall()
  25. {
  26. for (const auto& generator : this->Makefile->GetInstallGenerators()) {
  27. if (generator->HaveInstall()) {
  28. return true;
  29. }
  30. }
  31. return false;
  32. }
  33. void cmInstallSubdirectoryGenerator::CheckCMP0082(
  34. bool& haveSubdirectoryInstall, bool& /*unused*/)
  35. {
  36. if (this->HaveInstall()) {
  37. haveSubdirectoryInstall = true;
  38. }
  39. }
  40. bool cmInstallSubdirectoryGenerator::Compute(cmLocalGenerator* lg)
  41. {
  42. this->LocalGenerator = lg;
  43. return true;
  44. }
  45. void cmInstallSubdirectoryGenerator::GenerateScript(std::ostream& os)
  46. {
  47. if (!this->Makefile->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
  48. cmPolicies::PolicyStatus status =
  49. this->LocalGenerator->GetPolicyStatus(cmPolicies::CMP0082);
  50. switch (status) {
  51. case cmPolicies::WARN:
  52. CM_FALLTHROUGH;
  53. case cmPolicies::OLD:
  54. // OLD behavior is handled in cmLocalGenerator::GenerateInstallRules()
  55. break;
  56. case cmPolicies::NEW: {
  57. Indent indent;
  58. std::string odir = this->BinaryDirectory;
  59. cmSystemTools::ConvertToUnixSlashes(odir);
  60. os << indent << "if(NOT CMAKE_INSTALL_LOCAL_ONLY)\n"
  61. << indent.Next()
  62. << "# Include the install script for the subdirectory.\n"
  63. << indent.Next() << "include(\"" << odir
  64. << "/cmake_install.cmake\")\n"
  65. << indent << "endif()\n\n";
  66. } break;
  67. }
  68. }
  69. }