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