cmake/Source/cmInstallSubdirectoryGenerator.cxx

80 lines
2.3 KiB
C++
Raw Normal View History

2019-11-11 23:01:05 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmInstallSubdirectoryGenerator.h"
2020-08-30 11:54:41 +02:00
#include <memory>
2020-02-01 23:06:01 +01:00
#include <sstream>
2020-08-30 11:54:41 +02:00
#include <utility>
2020-02-01 23:06:01 +01:00
#include <vector>
2019-11-11 23:01:05 +01:00
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmPolicies.h"
#include "cmScriptGenerator.h"
#include "cmSystemTools.h"
cmInstallSubdirectoryGenerator::cmInstallSubdirectoryGenerator(
2021-09-14 00:13:48 +02:00
cmMakefile* makefile, std::string binaryDirectory,
cmListFileBacktrace backtrace)
2020-08-30 11:54:41 +02:00
: cmInstallGenerator("", std::vector<std::string>(), "", MessageDefault,
2021-09-14 00:13:48 +02:00
false, false, std::move(backtrace))
2019-11-11 23:01:05 +01:00
, Makefile(makefile)
2020-08-30 11:54:41 +02:00
, BinaryDirectory(std::move(binaryDirectory))
2019-11-11 23:01:05 +01:00
{
}
cmInstallSubdirectoryGenerator::~cmInstallSubdirectoryGenerator() = default;
bool cmInstallSubdirectoryGenerator::HaveInstall()
{
2020-08-30 11:54:41 +02:00
for (const auto& generator : this->Makefile->GetInstallGenerators()) {
2019-11-11 23:01:05 +01:00
if (generator->HaveInstall()) {
return true;
}
}
return false;
}
void cmInstallSubdirectoryGenerator::CheckCMP0082(
bool& haveSubdirectoryInstall, bool& /*unused*/)
{
if (this->HaveInstall()) {
haveSubdirectoryInstall = true;
}
}
bool cmInstallSubdirectoryGenerator::Compute(cmLocalGenerator* lg)
{
this->LocalGenerator = lg;
return true;
}
void cmInstallSubdirectoryGenerator::GenerateScript(std::ostream& os)
{
2021-09-14 00:13:48 +02:00
if (!this->Makefile->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
2019-11-11 23:01:05 +01:00
cmPolicies::PolicyStatus status =
this->LocalGenerator->GetPolicyStatus(cmPolicies::CMP0082);
switch (status) {
case cmPolicies::WARN:
case cmPolicies::OLD:
// OLD behavior is handled in cmLocalGenerator::GenerateInstallRules()
break;
case cmPolicies::NEW:
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS: {
Indent indent;
std::string odir = this->BinaryDirectory;
cmSystemTools::ConvertToUnixSlashes(odir);
os << indent << "if(NOT CMAKE_INSTALL_LOCAL_ONLY)\n"
<< indent.Next()
<< "# Include the install script for the subdirectory.\n"
<< indent.Next() << "include(\"" << odir
<< "/cmake_install.cmake\")\n"
<< indent << "endif()\n\n";
} break;
}
}
}