Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add_subdirectory: Run subdirectory install rules in correct order
Before this change, install rules created by add_subdirectory() would be executed after all of the top-level install rules, even if they were declared before the top-level rules. This change adds a new policy, CMP0082, which interleaves the add_subdirectory() install rules with the other install rules so they are run in the correct order.
- Loading branch information
1 parent
514f0b5
commit fc8955e
Showing
14 changed files
with
235 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
CMP0082 | ||
------- | ||
|
||
Install rules from :command:`add_subdirectory` calls are interleaved with | ||
those in caller. | ||
|
||
CMake 3.13 and lower ran the install rules from :command:`add_subdirectory` | ||
after all other install rules, even if :command:`add_subdirectory` was called | ||
before the other install rules. CMake 3.14 and later interleaves these | ||
:command:`add_subdirectory` install rules with the others so that they are | ||
run in the order they are declared. | ||
|
||
The ``OLD`` behavior for this policy is to run the install rules from | ||
:command:`add_subdirectory` after the other install rules. The ``NEW`` | ||
behavior for this policy is to run all install rules in the order they are | ||
declared. | ||
|
||
This policy was introduced in CMake version 3.14. Unlike most policies, | ||
CMake version |release| does *not* warn by default when this policy | ||
is not set and simply uses OLD behavior. See documentation of the | ||
:variable:`CMAKE_POLICY_WARNING_CMP0082 <CMAKE_POLICY_WARNING_CMP<NNNN>>` | ||
variable to control the warning. | ||
|
||
.. include:: DEPRECATED.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
install-subdirectory-order | ||
-------------------------- | ||
|
||
* Install rules under :command:`add_subdirectory` now interleave with those in | ||
the calling directory. See policy :policy:`CMP0082` for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying | ||
file Copyright.txt or https://cmake.org/licensing for details. */ | ||
#include "cmInstallSubdirectoryGenerator.h" | ||
|
||
#include "cmLocalGenerator.h" | ||
#include "cmMakefile.h" | ||
#include "cmPolicies.h" | ||
#include "cmScriptGenerator.h" | ||
#include "cmSystemTools.h" | ||
|
||
#include <sstream> | ||
#include <vector> | ||
|
||
cmInstallSubdirectoryGenerator::cmInstallSubdirectoryGenerator( | ||
cmMakefile* makefile, const char* binaryDirectory, bool excludeFromAll) | ||
: cmInstallGenerator(nullptr, std::vector<std::string>(), nullptr, | ||
MessageDefault, excludeFromAll) | ||
, Makefile(makefile) | ||
, BinaryDirectory(binaryDirectory) | ||
{ | ||
} | ||
|
||
cmInstallSubdirectoryGenerator::~cmInstallSubdirectoryGenerator() | ||
{ | ||
} | ||
|
||
bool cmInstallSubdirectoryGenerator::HaveInstall() | ||
{ | ||
for (auto generator : this->Makefile->GetInstallGenerators()) { | ||
if (generator->HaveInstall()) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
void cmInstallSubdirectoryGenerator::CheckCMP0082( | ||
bool& haveSubdirectoryInstall, bool& /*unused*/) | ||
{ | ||
if (this->HaveInstall()) { | ||
haveSubdirectoryInstall = true; | ||
} | ||
} | ||
|
||
void cmInstallSubdirectoryGenerator::Compute(cmLocalGenerator* lg) | ||
{ | ||
this->LocalGenerator = lg; | ||
} | ||
|
||
void cmInstallSubdirectoryGenerator::GenerateScript(std::ostream& os) | ||
{ | ||
if (!this->ExcludeFromAll) { | ||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying | ||
file Copyright.txt or https://cmake.org/licensing for details. */ | ||
#ifndef cmInstallSubdirectoryGenerator_h | ||
#define cmInstallSubdirectoryGenerator_h | ||
|
||
#include "cmConfigure.h" // IWYU pragma: keep | ||
|
||
#include "cmInstallGenerator.h" | ||
|
||
#include <iosfwd> | ||
#include <string> | ||
|
||
class cmLocalGenerator; | ||
class cmMakefile; | ||
|
||
/** \class cmInstallSubdirectoryGenerator | ||
* \brief Generate target installation rules. | ||
*/ | ||
class cmInstallSubdirectoryGenerator : public cmInstallGenerator | ||
{ | ||
public: | ||
cmInstallSubdirectoryGenerator(cmMakefile* makefile, | ||
const char* binaryDirectory, | ||
bool excludeFromAll); | ||
~cmInstallSubdirectoryGenerator() override; | ||
|
||
bool HaveInstall() override; | ||
void CheckCMP0082(bool& haveSubdirectoryInstall, | ||
bool& haveInstallAfterSubdirectory) override; | ||
|
||
void Compute(cmLocalGenerator* lg) override; | ||
|
||
protected: | ||
void GenerateScript(std::ostream& os) override; | ||
|
||
cmMakefile* Makefile; | ||
std::string BinaryDirectory; | ||
cmLocalGenerator* LocalGenerator; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters