首页 > 解决方案 > 如何仅在 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)

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

标签: cmakellvm

解决方案


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

如果您正在运行 CMake 3.19 或更高版本,则可以将版本范围传递给find_package,因此您可以尝试find_package(LLVM 11...<12 CONFIG)


推荐阅读