mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-18 17:31:57 +08:00
cmExportFileGenerator: Add function to set required CMake version
This commit is contained in:
@@ -76,7 +76,7 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (generatedInterfaceRequired) {
|
if (generatedInterfaceRequired) {
|
||||||
this->GenerateRequiredCMakeVersion(os, "3.0.0");
|
this->SetRequiredCMakeVersion(3, 0, 0);
|
||||||
}
|
}
|
||||||
this->GenerateExpectedTargetsCode(os, expectedTargets);
|
this->GenerateExpectedTargetsCode(os, expectedTargets);
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
#include "cmTarget.h"
|
#include "cmTarget.h"
|
||||||
#include "cmValue.h"
|
#include "cmValue.h"
|
||||||
|
#include "cmVersion.h"
|
||||||
|
|
||||||
static std::string cmExportFileGeneratorEscape(std::string const& str)
|
static std::string cmExportFileGeneratorEscape(std::string const& str)
|
||||||
{
|
{
|
||||||
@@ -93,17 +94,22 @@ bool cmExportFileGenerator::GenerateImportFile()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::ostream& os = *foutPtr;
|
std::ostream& os = *foutPtr;
|
||||||
|
std::stringstream mainFileWithHeadersAndFootersBuffer;
|
||||||
|
|
||||||
// Start with the import file header.
|
// Start with the import file header.
|
||||||
this->GeneratePolicyHeaderCode(os);
|
this->GenerateImportHeaderCode(mainFileWithHeadersAndFootersBuffer);
|
||||||
this->GenerateImportHeaderCode(os);
|
|
||||||
|
|
||||||
// Create all the imported targets.
|
// Create all the imported targets.
|
||||||
bool result = this->GenerateMainFile(os);
|
bool result = this->GenerateMainFile(mainFileWithHeadersAndFootersBuffer);
|
||||||
|
|
||||||
// End with the import file footer.
|
// End with the import file footer.
|
||||||
this->GenerateImportFooterCode(os);
|
this->GenerateImportFooterCode(mainFileWithHeadersAndFootersBuffer);
|
||||||
this->GeneratePolicyFooterCode(os);
|
this->GeneratePolicyFooterCode(mainFileWithHeadersAndFootersBuffer);
|
||||||
|
|
||||||
|
// This has to be done last, after the minimum CMake version has been
|
||||||
|
// determined.
|
||||||
|
this->GeneratePolicyHeaderCode(os);
|
||||||
|
os << mainFileWithHeadersAndFootersBuffer.rdbuf();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -156,17 +162,6 @@ void cmExportFileGenerator::PopulateInterfaceProperty(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmExportFileGenerator::GenerateRequiredCMakeVersion(
|
|
||||||
std::ostream& os, const char* versionString)
|
|
||||||
{
|
|
||||||
/* clang-format off */
|
|
||||||
os << "if(CMAKE_VERSION VERSION_LESS " << versionString << ")\n"
|
|
||||||
" message(FATAL_ERROR \"This file relies on consumers using "
|
|
||||||
"CMake " << versionString << " or greater.\")\n"
|
|
||||||
"endif()\n\n";
|
|
||||||
/* clang-format on */
|
|
||||||
}
|
|
||||||
|
|
||||||
bool cmExportFileGenerator::PopulateInterfaceLinkLibrariesProperty(
|
bool cmExportFileGenerator::PopulateInterfaceLinkLibrariesProperty(
|
||||||
cmGeneratorTarget const* target,
|
cmGeneratorTarget const* target,
|
||||||
cmGeneratorExpression::PreprocessContext preprocessRule,
|
cmGeneratorExpression::PreprocessContext preprocessRule,
|
||||||
@@ -953,8 +948,14 @@ void cmExportFileGenerator::GeneratePolicyHeaderCode(std::ostream& os)
|
|||||||
os << "if(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.8)\n"
|
os << "if(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.8)\n"
|
||||||
<< " message(FATAL_ERROR \"CMake >= 2.8.0 required\")\n"
|
<< " message(FATAL_ERROR \"CMake >= 2.8.0 required\")\n"
|
||||||
<< "endif()\n"
|
<< "endif()\n"
|
||||||
<< "if(CMAKE_VERSION VERSION_LESS \"2.8.3\")\n"
|
<< "if(CMAKE_VERSION VERSION_LESS \""
|
||||||
<< " message(FATAL_ERROR \"CMake >= 2.8.3 required\")\n"
|
<< this->RequiredCMakeVersionMajor << '.'
|
||||||
|
<< this->RequiredCMakeVersionMinor << '.'
|
||||||
|
<< this->RequiredCMakeVersionPatch << "\")\n"
|
||||||
|
<< " message(FATAL_ERROR \"CMake >= "
|
||||||
|
<< this->RequiredCMakeVersionMajor << '.'
|
||||||
|
<< this->RequiredCMakeVersionMinor << '.'
|
||||||
|
<< this->RequiredCMakeVersionPatch << " required\")\n"
|
||||||
<< "endif()\n";
|
<< "endif()\n";
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
||||||
@@ -966,7 +967,10 @@ void cmExportFileGenerator::GeneratePolicyHeaderCode(std::ostream& os)
|
|||||||
// versions.
|
// versions.
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
os << "cmake_policy(PUSH)\n"
|
os << "cmake_policy(PUSH)\n"
|
||||||
<< "cmake_policy(VERSION 2.8.3...3.27)\n";
|
<< "cmake_policy(VERSION "
|
||||||
|
<< this->RequiredCMakeVersionMajor << '.'
|
||||||
|
<< this->RequiredCMakeVersionMinor << '.'
|
||||||
|
<< this->RequiredCMakeVersionPatch << "...3.27)\n";
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1485,3 +1489,17 @@ void cmExportFileGenerator::GenerateCxxModuleInformation(std::ostream& os)
|
|||||||
|
|
||||||
this->GenerateCxxModuleConfigInformation(ap);
|
this->GenerateCxxModuleConfigInformation(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmExportFileGenerator::SetRequiredCMakeVersion(unsigned int major,
|
||||||
|
unsigned int minor,
|
||||||
|
unsigned int patch)
|
||||||
|
{
|
||||||
|
if (CMake_VERSION_ENCODE(major, minor, patch) >
|
||||||
|
CMake_VERSION_ENCODE(this->RequiredCMakeVersionMajor,
|
||||||
|
this->RequiredCMakeVersionMinor,
|
||||||
|
this->RequiredCMakeVersionPatch)) {
|
||||||
|
this->RequiredCMakeVersionMajor = major;
|
||||||
|
this->RequiredCMakeVersionMinor = minor;
|
||||||
|
this->RequiredCMakeVersionPatch = patch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -173,9 +173,6 @@ protected:
|
|||||||
std::string& input, cmGeneratorTarget const* target,
|
std::string& input, cmGeneratorTarget const* target,
|
||||||
FreeTargetsReplace replace = NoReplaceFreeTargets);
|
FreeTargetsReplace replace = NoReplaceFreeTargets);
|
||||||
|
|
||||||
virtual void GenerateRequiredCMakeVersion(std::ostream& os,
|
|
||||||
const char* versionString);
|
|
||||||
|
|
||||||
bool PopulateCxxModuleExportProperties(
|
bool PopulateCxxModuleExportProperties(
|
||||||
cmGeneratorTarget const* gte, ImportPropertyMap& properties,
|
cmGeneratorTarget const* gte, ImportPropertyMap& properties,
|
||||||
cmGeneratorExpression::PreprocessContext ctx,
|
cmGeneratorExpression::PreprocessContext ctx,
|
||||||
@@ -196,6 +193,9 @@ protected:
|
|||||||
cmFileSet* fileSet,
|
cmFileSet* fileSet,
|
||||||
cmTargetExport* te) = 0;
|
cmTargetExport* te) = 0;
|
||||||
|
|
||||||
|
void SetRequiredCMakeVersion(unsigned int major, unsigned int minor,
|
||||||
|
unsigned int patch);
|
||||||
|
|
||||||
// The namespace in which the exports are placed in the generated file.
|
// The namespace in which the exports are placed in the generated file.
|
||||||
std::string Namespace;
|
std::string Namespace;
|
||||||
|
|
||||||
@@ -216,6 +216,10 @@ protected:
|
|||||||
|
|
||||||
std::vector<std::string> MissingTargets;
|
std::vector<std::string> MissingTargets;
|
||||||
|
|
||||||
|
unsigned int RequiredCMakeVersionMajor = 2;
|
||||||
|
unsigned int RequiredCMakeVersionMinor = 8;
|
||||||
|
unsigned int RequiredCMakeVersionPatch = 3;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void PopulateInterfaceProperty(const std::string&, const std::string&,
|
void PopulateInterfaceProperty(const std::string&, const std::string&,
|
||||||
cmGeneratorTarget const* target,
|
cmGeneratorTarget const* target,
|
||||||
|
@@ -110,11 +110,6 @@ void cmExportInstallAndroidMKGenerator::GenerateImportPrefix(std::ostream&)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmExportInstallAndroidMKGenerator::GenerateRequiredCMakeVersion(
|
|
||||||
std::ostream&, const char*)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void cmExportInstallAndroidMKGenerator::CleanupTemporaryVariables(
|
void cmExportInstallAndroidMKGenerator::CleanupTemporaryVariables(
|
||||||
std::ostream&)
|
std::ostream&)
|
||||||
{
|
{
|
||||||
|
@@ -54,8 +54,6 @@ protected:
|
|||||||
const ImportPropertyMap& properties) override;
|
const ImportPropertyMap& properties) override;
|
||||||
void GenerateImportPrefix(std::ostream& os) override;
|
void GenerateImportPrefix(std::ostream& os) override;
|
||||||
void LoadConfigFiles(std::ostream&) override;
|
void LoadConfigFiles(std::ostream&) override;
|
||||||
void GenerateRequiredCMakeVersion(std::ostream& os,
|
|
||||||
const char* versionString) override;
|
|
||||||
void CleanupTemporaryVariables(std::ostream&) override;
|
void CleanupTemporaryVariables(std::ostream&) override;
|
||||||
void GenerateImportedFileCheckLoop(std::ostream& os) override;
|
void GenerateImportedFileCheckLoop(std::ostream& os) override;
|
||||||
void GenerateImportedFileChecksCode(
|
void GenerateImportedFileChecksCode(
|
||||||
|
@@ -76,9 +76,6 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
|
|||||||
// Compute the relative import prefix for the file
|
// Compute the relative import prefix for the file
|
||||||
this->GenerateImportPrefix(os);
|
this->GenerateImportPrefix(os);
|
||||||
|
|
||||||
bool require2_8_12 = false;
|
|
||||||
bool require3_0_0 = false;
|
|
||||||
bool require3_1_0 = false;
|
|
||||||
bool requiresConfigFiles = false;
|
bool requiresConfigFiles = false;
|
||||||
// Create all the imported targets.
|
// Create all the imported targets.
|
||||||
for (cmTargetExport* te : allTargets) {
|
for (cmTargetExport* te : allTargets) {
|
||||||
@@ -147,16 +144,16 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
|
|||||||
if (this->PopulateInterfaceLinkLibrariesProperty(
|
if (this->PopulateInterfaceLinkLibrariesProperty(
|
||||||
gt, cmGeneratorExpression::InstallInterface, properties) &&
|
gt, cmGeneratorExpression::InstallInterface, properties) &&
|
||||||
!this->ExportOld) {
|
!this->ExportOld) {
|
||||||
require2_8_12 = true;
|
this->SetRequiredCMakeVersion(2, 8, 12);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (targetType == cmStateEnums::INTERFACE_LIBRARY) {
|
if (targetType == cmStateEnums::INTERFACE_LIBRARY) {
|
||||||
require3_0_0 = true;
|
this->SetRequiredCMakeVersion(3, 0, 0);
|
||||||
}
|
}
|
||||||
if (gt->GetProperty("INTERFACE_SOURCES")) {
|
if (gt->GetProperty("INTERFACE_SOURCES")) {
|
||||||
// We can only generate INTERFACE_SOURCES in CMake 3.3, but CMake 3.1
|
// We can only generate INTERFACE_SOURCES in CMake 3.3, but CMake 3.1
|
||||||
// can consume them.
|
// can consume them.
|
||||||
require3_1_0 = true;
|
this->SetRequiredCMakeVersion(3, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE", gt,
|
this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE", gt,
|
||||||
@@ -169,14 +166,6 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
|
|||||||
this->GenerateTargetFileSets(gt, os, te);
|
this->GenerateTargetFileSets(gt, os, te);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (require3_1_0) {
|
|
||||||
this->GenerateRequiredCMakeVersion(os, "3.1.0");
|
|
||||||
} else if (require3_0_0) {
|
|
||||||
this->GenerateRequiredCMakeVersion(os, "3.0.0");
|
|
||||||
} else if (require2_8_12) {
|
|
||||||
this->GenerateRequiredCMakeVersion(os, "2.8.12");
|
|
||||||
}
|
|
||||||
|
|
||||||
this->LoadConfigFiles(os);
|
this->LoadConfigFiles(os);
|
||||||
|
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
Reference in New Issue
Block a user