/src/CMake/Source/cmPackageInfoArguments.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 "cmPackageInfoArguments.h" |
4 | | |
5 | | #include <cm/string_view> |
6 | | |
7 | | #include "cmExecutionStatus.h" |
8 | | #include "cmStringAlgorithms.h" |
9 | | #include "cmSystemTools.h" |
10 | | |
11 | | template void cmPackageInfoArguments::Bind<void>(cmArgumentParser<void>&, |
12 | | cmPackageInfoArguments*); |
13 | | |
14 | | cm::string_view cmPackageInfoArguments::CommandName() const |
15 | 0 | { |
16 | 0 | return "PACKAGE_INFO"_s; |
17 | 0 | } |
18 | | |
19 | | #define ENFORCE_REQUIRES(req, value, arg) \ |
20 | 0 | do { \ |
21 | 0 | if (ArgWasSpecified(value)) { \ |
22 | 0 | status.SetError(arg " requires " req "."); \ |
23 | 0 | return false; \ |
24 | 0 | } \ |
25 | 0 | } while (false) |
26 | | |
27 | | #define ENFORCE_EXCLUSIVE(arg1, value, arg2) \ |
28 | 0 | do { \ |
29 | 0 | if (ArgWasSpecified(value)) { \ |
30 | 0 | status.SetError(arg1 " and " arg2 " are mutually exclusive."); \ |
31 | 0 | return false; \ |
32 | 0 | } \ |
33 | 0 | } while (false) |
34 | | |
35 | | bool cmPackageInfoArguments::Check(cmExecutionStatus& status) const |
36 | 0 | { |
37 | | // Check for incompatible options. |
38 | 0 | if (!this->Appendix.empty()) { |
39 | 0 | ENFORCE_EXCLUSIVE("APPENDIX", this->Version, "VERSION"); |
40 | 0 | ENFORCE_EXCLUSIVE("APPENDIX", this->License, "LICENSE"); |
41 | 0 | ENFORCE_EXCLUSIVE("APPENDIX", this->Description, "DESCRIPTION"); |
42 | 0 | ENFORCE_EXCLUSIVE("APPENDIX", this->Website, "HOMEPAGE_URL"); |
43 | 0 | ENFORCE_EXCLUSIVE("APPENDIX", this->DefaultTargets, "DEFAULT_TARGETS"); |
44 | 0 | ENFORCE_EXCLUSIVE("APPENDIX", this->DefaultConfigs, |
45 | 0 | "DEFAULT_CONFIGURATIONS"); |
46 | 0 | ENFORCE_EXCLUSIVE("APPENDIX", this->ProjectName, "PROJECT"); |
47 | 0 | } |
48 | | |
49 | | // Check for options that require other options. |
50 | 0 | if (this->Version.empty()) { |
51 | 0 | ENFORCE_REQUIRES("VERSION", this->VersionCompat, "COMPAT_VERSION"); |
52 | 0 | ENFORCE_REQUIRES("VERSION", this->VersionSchema, "VERSION_SCHEMA"); |
53 | 0 | } |
54 | | |
55 | 0 | return cmProjectInfoArguments::Check(status); |
56 | 0 | } |
57 | | |
58 | | #undef ENFORCE_REQUIRES |
59 | | #undef ENFORCE_EXCLUSIVE |
60 | | |
61 | | bool cmPackageInfoArguments::SetEffectiveProject(cmExecutionStatus& status) |
62 | 0 | { |
63 | 0 | if (!this->Appendix.empty()) { |
64 | | // Appendices are not allowed to specify package metadata. |
65 | 0 | return true; |
66 | 0 | } |
67 | | |
68 | 0 | return cmProjectInfoArguments::SetEffectiveProject(status); |
69 | 0 | } |
70 | | |
71 | | std::string cmPackageInfoArguments::GetNamespace() const |
72 | 0 | { |
73 | 0 | return cmStrCat(this->PackageName, "::"_s); |
74 | 0 | } |
75 | | |
76 | | std::string cmPackageInfoArguments::GetPackageDirName() const |
77 | 0 | { |
78 | 0 | if (this->LowerCase) { |
79 | 0 | return cmSystemTools::LowerCase(this->PackageName); |
80 | 0 | } |
81 | 0 | return this->PackageName; |
82 | 0 | } |
83 | | |
84 | | std::string cmPackageInfoArguments::GetPackageFileName() const |
85 | 0 | { |
86 | 0 | std::string const pkgNameOnDisk = this->GetPackageDirName(); |
87 | 0 | if (!this->Appendix.empty()) { |
88 | 0 | return cmStrCat(pkgNameOnDisk, '-', this->Appendix, ".cps"_s); |
89 | 0 | } |
90 | 0 | return cmStrCat(pkgNameOnDisk, ".cps"_s); |
91 | 0 | } |