如何仅在cmake中匹配主要版本

How to match major version only in cmake

我正在尝试构建一个需要 LLVM 11 作为依赖项的项目。他们捆绑了一份 LLVM 11.0.1。我想针对系统版本构建它,即 LLVM 11.1.0。在 cmake 构建文件中,它们具有:

find_package(LLVM 11.0 CONFIG)

如果您尝试使用系统 LLVM,您会收到以下错误:

CMake Warning at 3rdparty/llvm.cmake:42 (find_package):
  Could not find a configuration file for package "LLVM" that is compatible
  with requested version "11.0".

  The following configuration files were considered but not accepted:

    /usr/lib/llvm/11/lib64/cmake/llvm/LLVMConfig.cmake, version: 11.1.0
    /usr/lib/llvm/11/lib/cmake/llvm/LLVMConfig.cmake, version: 11.1.0

Call Stack (most recent call first):
  3rdparty/CMakeLists.txt:436 (include)

我认为将此行更改为这样可以解决问题:

find_package(LLVM 11 CONFIG)

但它没有,我得到了完全相同的错误:

CMake Warning at 3rdparty/llvm.cmake:42 (find_package):
  Could not find a configuration file for package "LLVM" that is compatible
  with requested version "11".

  The following configuration files were considered but not accepted:

    /usr/lib/llvm/11/lib64/cmake/llvm/LLVMConfig.cmake, version: 11.1.0
    /usr/lib/llvm/11/lib/cmake/llvm/LLVMConfig.cmake, version: 11.1.0

Call Stack (most recent call first):
  3rdparty/CMakeLists.txt:436 (include)

我错过了什么?这是代码的完整 link:https://github.com/RPCS3/rpcs3/blob/master/3rdparty/llvm.cmake

一个版本是否被认为与所请求的版本兼容由您要查找的包指定。我没有查看 LLVM 配置,但我怀疑它指定只有确切的版本兼容,而不是具有相同主要版本的所有版本。

如果您是 运行 CMake 3.19 或更高版本,您可以将版本范围传递给 find_package,这样您就可以尝试 find_package(LLVM 11...<12 CONFIG)