[CMake] how to set environment variable when executing process

frederic heem frederic.heem at telsey.it
Fri Oct 6 09:55:05 EDT 2006


Hi,
In some FindXXX.cmake, pkgconfig is used to locate include directories 
libraries, definitions etc. I would like to set the environment variable 
PKG_CONFIG_PATH to $MYLIBDIR:$PKG_CONFIG_PATH,  hence pkg-config will look 
first for $MYLIBDIR/mylib.pc
EXECUTE_PROCESS and EXEC_PROGRAM allow to execute processes but they do not 
allow to change environment variable.
A non portable workaround for unix is to call export:
    EXECUTE_PROCESS(COMMAND sh -c "export PKG_CONFIG_PATH=${_pkgpath}"  
COMMAND ${PKGCONFIG_EXECUTABLE} --print-errors --exists${_package} 
RESULT_VARIABLE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull )





More information about the CMake mailing list