| 2949 | } |
| 2950 | |
| 2951 | bool cmFindPackageCommand::CheckVersion(std::string const& config_file) |
| 2952 | { |
| 2953 | bool result = false; // by default, assume the version is not ok. |
| 2954 | bool haveResult = false; |
| 2955 | std::string version = "unknown"; |
| 2956 | std::string message; |
| 2957 | SearchResult reason = SearchResult::InsufficientVersion; |
| 2958 | |
| 2959 | // Get the file extension. |
| 2960 | std::string::size_type pos = config_file.rfind('.'); |
| 2961 | std::string ext = cmSystemTools::LowerCase(config_file.substr(pos)); |
| 2962 | |
| 2963 | if (ext == ".cps"_s) { |
| 2964 | cmMakefile::CallRAII cs{ this->Makefile, config_file, this->Status }; |
| 2965 | |
| 2966 | std::unique_ptr<cmPackageInfoReader> reader = |
| 2967 | cmPackageInfoReader::Read(this->Makefile, config_file); |
| 2968 | |
| 2969 | if (reader && reader->GetName() == this->Name) { |
| 2970 | // Read version information. |
| 2971 | cm::optional<std::string> cpsVersion = reader->GetVersion(); |
| 2972 | cm::optional<ParsedVersion> const& parsedVersion = |
| 2973 | reader->ParseVersion(cpsVersion); |
| 2974 | bool const hasVersion = cpsVersion.has_value(); |
| 2975 | |
| 2976 | // Test for version compatibility. |
| 2977 | result = this->Version.empty(); |
| 2978 | if (hasVersion) { |
| 2979 | version = std::move(*cpsVersion); |
| 2980 | |
| 2981 | if (!this->Version.empty()) { |
| 2982 | if (!parsedVersion) { |
| 2983 | // If we don't understand the version, compare the exact versions |
| 2984 | // using full string comparison. This is the correct behavior for |
| 2985 | // the "custom" schema, and the best we can do otherwise. |
| 2986 | result = (this->Version == version); |
| 2987 | } else if (this->VersionExact) { |
| 2988 | // If EXACT is specified, the version must be exactly the requested |
| 2989 | // version. |
| 2990 | result = |
| 2991 | cmSystemTools::VersionCompareEqual(this->Version, version); |
| 2992 | } else { |
| 2993 | // Do we have a compat_version? |
| 2994 | cm::optional<std::string> const& compatVersion = |
| 2995 | reader->GetCompatVersion(); |
| 2996 | if (reader->ParseVersion(compatVersion)) { |
| 2997 | // If yes, the initial result is whether the requested version is |
| 2998 | // between the actual version and the compat version, inclusive. |
| 2999 | result = cmSystemTools::VersionCompareGreaterEq(version, |
| 3000 | this->Version) && |
| 3001 | cmSystemTools::VersionCompareGreaterEq(this->Version, |
| 3002 | *compatVersion); |
| 3003 | |
| 3004 | if (result && !this->VersionMax.empty()) { |
| 3005 | // We must also check that the version is less than the version |
| 3006 | // limit. |
| 3007 | if (this->VersionRangeMax == VERSION_ENDPOINT_EXCLUDED) { |
| 3008 | result = cmSystemTools::VersionCompareGreater( |
no test coverage detected