[CMake] how to set environment variable when executing process

Brad King brad.king at kitware.com
Fri Oct 6 09:59:36 EDT 2006


frederic heem wrote:
> 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 )

SET(ENV{PKG_CONFIG_PATH} "/my/path:$ENV{PKG_CONFIG_PATH}")
EXECUTE_PROCESS(...)

-Brad



More information about the CMake mailing list