MCPcopy Create free account
hub / github.com/Kitware/CMake / CheckVersionFile

Method CheckVersionFile

Source/cmFindPackageCommand.cxx:3163–3263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3161}
3162
3163bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file,
3164 std::string& result_version)
3165{
3166 // The version file will be loaded in an isolated scope.
3167 cmMakefile::ScopePushPop const varScope(this->Makefile);
3168 cmMakefile::PolicyPushPop const polScope(this->Makefile);
3169 static_cast<void>(varScope);
3170 static_cast<void>(polScope);
3171
3172 // Clear the output variables.
3173 this->Makefile->RemoveDefinition("PACKAGE_VERSION");
3174 this->Makefile->RemoveDefinition("PACKAGE_VERSION_UNSUITABLE");
3175 this->Makefile->RemoveDefinition("PACKAGE_VERSION_COMPATIBLE");
3176 this->Makefile->RemoveDefinition("PACKAGE_VERSION_EXACT");
3177
3178 // Set the input variables.
3179 this->Makefile->AddDefinition("PACKAGE_FIND_NAME", this->Name);
3180 this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_COMPLETE",
3181 this->VersionComplete);
3182
3183 auto addDefinition = [this](std::string const& variable,
3184 cm::string_view value) {
3185 this->Makefile->AddDefinition(variable, value);
3186 };
3187 this->SetVersionVariables(addDefinition, "PACKAGE_FIND_VERSION",
3188 this->Version, this->VersionCount,
3189 this->VersionMajor, this->VersionMinor,
3190 this->VersionPatch, this->VersionTweak);
3191 if (!this->VersionRange.empty()) {
3192 this->SetVersionVariables(addDefinition, "PACKAGE_FIND_VERSION_MIN",
3193 this->Version, this->VersionCount,
3194 this->VersionMajor, this->VersionMinor,
3195 this->VersionPatch, this->VersionTweak);
3196 this->SetVersionVariables(addDefinition, "PACKAGE_FIND_VERSION_MAX",
3197 this->VersionMax, this->VersionMaxCount,
3198 this->VersionMaxMajor, this->VersionMaxMinor,
3199 this->VersionMaxPatch, this->VersionMaxTweak);
3200
3201 this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_RANGE",
3202 this->VersionComplete);
3203 this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_RANGE_MIN",
3204 this->VersionRangeMin);
3205 this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_RANGE_MAX",
3206 this->VersionRangeMax);
3207 }
3208
3209 // Load the version check file.
3210 // Pass NoPolicyScope because we do our own policy push/pop.
3211 bool suitable = false;
3212 if (this->ReadListFile(version_file, NoPolicyScope)) {
3213 // Check the output variables.
3214 bool okay = this->Makefile->IsOn("PACKAGE_VERSION_EXACT");
3215 bool const unsuitable = this->Makefile->IsOn("PACKAGE_VERSION_UNSUITABLE");
3216 if (!okay && !this->VersionExact) {
3217 okay = this->Makefile->IsOn("PACKAGE_VERSION_COMPATIBLE");
3218 }
3219
3220 // The package is suitable if the version is okay and not

Callers 1

CheckVersionMethod · 0.95

Calls 7

SetVersionVariablesMethod · 0.95
ReadListFileMethod · 0.95
parseVersionFunction · 0.85
RemoveDefinitionMethod · 0.45
AddDefinitionMethod · 0.45
emptyMethod · 0.45
IsOnMethod · 0.45

Tested by

no test coverage detected