Add temporarily path to pkg-config within CMake script?

南楼画角 提交于 2019-12-04 16:44:40

问题


For external libraries the user can specify a non-standard location by adding the path to the CMAKE_FLAGS or by adding -DMYLIB_ROOT. Within the CMake script I want to find the library's pkg-config pc file. Because the pc file is not in the standard folder, it is not found by pkg-config with FindPkgConfig's pkg_search_module.

I tried to add the user-given path to the PKG_CONFIG_PATH but it seemed to be ignored:

include(FindPkgConfig)
set(PKG_CONFIG_PATH "${PKG_CONFIG_PATH}:${MYLIB_ROOT}/lib/pkgconfig")
pkg_search_module(PKG_MYLIB mylib)

if(${PKG_MYLIB_FOUND})
...

When I call pkg-config from the terminal with the modified PKG_CONFIG_PATH set, it find the pc file. What am I doing wrong? How can I get pkg_search_module working? I'd like to avoid calling pkg-config directly from CMake.


回答1:


Maybe the following will do the job

set( ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${MYLIB_ROOT}/lib/pkgconfig" )



回答2:


This is a known issue and a ticket exists in CMake's bugtracker, but it is backlocked due to lack of developer interest. I guess one has to provide a patch first...

Edit: According to the bugtracker the feature has been implemented and is part of CMake 3.1.



来源:https://stackoverflow.com/questions/20447821/add-temporarily-path-to-pkg-config-within-cmake-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!