Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add temporarily path to pkg-config within CMake script?

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.

like image 725
usr1234567 Avatar asked Dec 07 '13 23:12

usr1234567


People also ask

Does CMake use pkg-config?

CMake can generate pkg-config . pc files for packages. The . pc file can be used by many build systems.

What is Pkg_config_path?

PKG_CONFIG_PATH is a environment variable that specifies additional paths in which pkg-config will search for its . pc files. This variable is used to augment pkg-config's default search path. On a typical Unix system, it will search in the directories /usr/lib/pkgconfig and /usr/share/pkgconfig .

What is Pkgconfig in Linux?

pkg-config is a helper tool used when compiling applications and libraries. It helps you insert the correct compiler options on the command line so an application can use gcc -o test test. c `pkg-config --libs --cflags glib-2.0` for instance, rather than hard-coding values on where to find glib (or other libraries).


2 Answers

Maybe the following will do the job

set( ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${MYLIB_ROOT}/lib/pkgconfig" )
like image 182
lgnom Avatar answered Sep 28 '22 01:09

lgnom


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.

like image 42
usr1234567 Avatar answered Sep 28 '22 03:09

usr1234567