如何设置CMakeLists.txt以在非默认路径中查找.PC文件(带有pkg_search_module的pkg-config)?

时间:2019-06-02 00:08:19

标签: cmake sdl sdl-2 pkg-config

我正在尝试使用SDL2和SDL2_image扩展名创建一个简单的项目。由于SDL2_image不提供对Find * .cmake模块的官方支持,因此我的替代方法是使用pkg-config查找那些库。

但是,我自己构建了SDL2和SDL2_image并将它们安装在自定义路径(〜/ Library / SDL2和〜/ Library / SDL2_image)中。

CMake似乎能够正确找到SDL2,但是即使我将.PC文件放在系统默认路径(/ usr / share / pkgconfig)中,它也找不到SDL2_image。

如何告诉CMake在非默认(系统)路径中查找.PC文件?我需要使用SDL2和SDL2_image构建一个简单的项目。

我试图将SDL2_image.pc文件放在.PC文件(/ usr / share / pkgconfig)的默认系统路径中,但是似乎没有任何改变。

find_package(PkgConfig)

# SDL2 can be found and included
pkg_search_module(SDL2 REQUIRED sdl2)

# SDL2_image cannot be found and thus the project doesn't configure/generate.
pkg_search_module(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)

运行“ cmake”时出现错误消息:

-- Checking for one of the modules 'SDL2_image>=2.0.0'
CMake Error at /usr/share/cmake-3.7/Modules/FindPkgConfig.cmake:637 (message):
  None of the required 'SDL2_image>=2.0.0' found
Call Stack (most recent call first):
  CMakeLists.txt:12 (pkg_search_module)

1 个答案:

答案 0 :(得分:0)

找到pkg-config *.pc文件,并导出路径:

export PKG_CONFIG_PATH="/path/lib/pkgconfig"