Coverage Report

Created: 2026-06-15 07:03

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