| 1080 | } |
| 1081 | |
| 1082 | bool cmFindPackageCommand::FindPackage( |
| 1083 | std::vector<std::string> const& argsForProvider) |
| 1084 | { |
| 1085 | std::string const makePackageRequiredVar = |
| 1086 | cmStrCat("CMAKE_REQUIRE_FIND_PACKAGE_", this->Name); |
| 1087 | bool const makePackageRequiredSet = |
| 1088 | this->Makefile->IsOn(makePackageRequiredVar); |
| 1089 | if (makePackageRequiredSet) { |
| 1090 | if (this->IsRequired()) { |
| 1091 | this->Makefile->IssueMessage( |
| 1092 | MessageType::WARNING, |
| 1093 | cmStrCat("for module ", this->Name, |
| 1094 | " already called with REQUIRED, thus ", |
| 1095 | makePackageRequiredVar, " has no effect.")); |
| 1096 | } else { |
| 1097 | this->Required = RequiredStatus::RequiredFromPackageVar; |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | std::string const disableFindPackageVar = |
| 1102 | cmStrCat("CMAKE_DISABLE_FIND_PACKAGE_", this->Name); |
| 1103 | if (this->Makefile->IsOn(disableFindPackageVar)) { |
| 1104 | if (this->IsRequired()) { |
| 1105 | this->SetError( |
| 1106 | cmStrCat("for module ", this->Name, |
| 1107 | (makePackageRequiredSet |
| 1108 | ? " was made REQUIRED with " + makePackageRequiredVar |
| 1109 | : " called with REQUIRED, "), |
| 1110 | " but ", disableFindPackageVar, |
| 1111 | " is enabled. A REQUIRED package cannot be disabled.")); |
| 1112 | return false; |
| 1113 | } |
| 1114 | return true; |
| 1115 | } |
| 1116 | |
| 1117 | // Restore PACKAGE_PREFIX_DIR to its pre-call value when we return. If our |
| 1118 | // caller is a file generated by configure_package_config_file(), and if |
| 1119 | // the package we are about to load also has a config file created by that |
| 1120 | // command, it will overwrite PACKAGE_PREFIX_DIR. We need to restore it in |
| 1121 | // case something still refers to it in our caller's scope after we return. |
| 1122 | class RestoreVariableOnLeavingScope |
| 1123 | { |
| 1124 | cmMakefile* makefile_; |
| 1125 | cm::optional<std::string> value_; |
| 1126 | |
| 1127 | public: |
| 1128 | RestoreVariableOnLeavingScope(cmMakefile* makefile) |
| 1129 | : makefile_(makefile) |
| 1130 | { |
| 1131 | cmValue v = makefile->GetDefinition("PACKAGE_PREFIX_DIR"); |
| 1132 | if (v) { |
| 1133 | value_ = *v; |
| 1134 | } |
| 1135 | } |
| 1136 | ~RestoreVariableOnLeavingScope() |
| 1137 | { |
| 1138 | if (this->value_) { |
| 1139 | makefile_->AddDefinition("PACKAGE_PREFIX_DIR", *value_); |
no test coverage detected