|
|
@@ -2,10 +2,15 @@
|
|
|
file LICENSE.rst or https://cmake.org/licensing for details. */
|
|
|
#include "cmPackageInfoArguments.h"
|
|
|
|
|
|
+#include <utility>
|
|
|
+
|
|
|
#include "cmExecutionStatus.h"
|
|
|
#include "cmGeneratorExpression.h"
|
|
|
+#include "cmMakefile.h"
|
|
|
+#include "cmStateSnapshot.h"
|
|
|
#include "cmStringAlgorithms.h"
|
|
|
#include "cmSystemTools.h"
|
|
|
+#include "cmValue.h"
|
|
|
|
|
|
template void cmPackageInfoArguments::Bind<void>(cmArgumentParser<void>&,
|
|
|
cmPackageInfoArguments*);
|
|
|
@@ -35,6 +40,14 @@ bool cmPackageInfoArguments::Check(cmExecutionStatus& status,
|
|
|
status.SetError("DEFAULT_CONFIGURATIONS requires PACKAGE_INFO.");
|
|
|
return false;
|
|
|
}
|
|
|
+ if (!this->ProjectName.empty()) {
|
|
|
+ status.SetError("PROJECT requires PACKAGE_INFO.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (this->NoProjectDefaults) {
|
|
|
+ status.SetError("NO_PROJECT_METADATA requires PACKAGE_INFO.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Check for incompatible options.
|
|
|
@@ -53,6 +66,17 @@ bool cmPackageInfoArguments::Check(cmExecutionStatus& status,
|
|
|
"are mutually exclusive.");
|
|
|
return false;
|
|
|
}
|
|
|
+ if (!this->ProjectName.empty()) {
|
|
|
+ status.SetError("APPENDIX and PROJECT are mutually exclusive.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (this->NoProjectDefaults) {
|
|
|
+ if (!this->ProjectName.empty()) {
|
|
|
+ status.SetError("PROJECT and NO_PROJECT_METADATA "
|
|
|
+ "are mutually exclusive.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Check for options that require other options.
|
|
|
@@ -81,6 +105,66 @@ bool cmPackageInfoArguments::Check(cmExecutionStatus& status,
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+bool cmPackageInfoArguments::SetMetadataFromProject(cmExecutionStatus& status)
|
|
|
+{
|
|
|
+ // Determine what project to use for inherited metadata.
|
|
|
+ if (!this->SetEffectiveProject(status)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this->ProjectName.empty()) {
|
|
|
+ // We are not inheriting from a project.
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ cmMakefile& mf = status.GetMakefile();
|
|
|
+ if (this->Version.empty()) {
|
|
|
+ cmValue const& version =
|
|
|
+ mf.GetDefinition(cmStrCat(this->ProjectName, "_VERSION"_s));
|
|
|
+ if (version) {
|
|
|
+ this->Version = version;
|
|
|
+ cmValue const& compatVersion =
|
|
|
+ mf.GetDefinition(cmStrCat(this->ProjectName, "_COMPAT_VERSION"_s));
|
|
|
+ if (compatVersion) {
|
|
|
+ this->VersionCompat = compatVersion;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool cmPackageInfoArguments::SetEffectiveProject(cmExecutionStatus& status)
|
|
|
+{
|
|
|
+ if (!this->Appendix.empty()) {
|
|
|
+ // Appendices are not allowed to specify package metadata.
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this->NoProjectDefaults) {
|
|
|
+ // User requested that metadata not be inherited.
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ cmMakefile& mf = status.GetMakefile();
|
|
|
+ if (!this->ProjectName.empty()) {
|
|
|
+ // User specified a project; make sure it exists.
|
|
|
+ if (!mf.GetStateSnapshot().CheckProjectName(this->ProjectName)) {
|
|
|
+ status.SetError(cmStrCat(R"(PROJECT given invalid project name ")"_s,
|
|
|
+ this->ProjectName, R"(".)"_s));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // No project was specified; check if the package name is also a project.
|
|
|
+ std::string project = mf.GetStateSnapshot().GetProjectName();
|
|
|
+ if (this->PackageName == project) {
|
|
|
+ this->ProjectName = std::move(project);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
std::string cmPackageInfoArguments::GetNamespace() const
|
|
|
{
|
|
|
return cmStrCat(this->PackageName, "::"_s);
|