[CMake] Environment variables and ExternalProject

Luigi Calori l.calori at cineca.it
Mon Oct 17 13:15:33 EDT 2011


On 17/10/2011 18.27, Milutin Jovanovic' wrote:
>
> Hi all,
>
> Hi all. First time posting. Before I start I'd like to thank all the 
> Kitware guys for a very nice and useful tool. I did a fair bit of 
> searching to try to avoid asking duplicate questions, but did not find 
> answer to my problem.
>
> I am trying to make a private build of some dependencies, ogg and 
> vorbis in this case. The initial problem is that second library make 
> is not finding first, due to pkg-config not finding output files from 
> the first library. OK, I said, and did PKG_CONFIG_PATH=... and export 
> PKG_CONFIG_PATH before executing cmake build. And this fixed the problem.
>
> However then I tried to ease the job of whoever might be using this, 
> and tried setting the PKG_CONFIG_PATH inside the cmake script. But 
> this does not work. I did some tests, and indeed, configure executed 
> as part of ExternalProject does not see environmental variables set by 
> cmake.
>
> So, the question is, am I doing something wrong or is this cmake 
> limitation?
I' m not really sure, but I think it is a CMake limitation that has been 
discussed before:
When you do

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

I think that you are setting the environment for the current cmake 
process and all it' s child processes.

The problem is that when you use ExternalProject_Add() you are building 
a Makefile that will be processed at "build" time whwn you invoke make 
(or a XCode ide processing)

That process is NOT a child of your cmake, so the env is lost

As far as I know, there is (unfortunately) no ENV clause in 
ExternalProcess,  so the only (ugly) workaround that I have found is to 
define a wrapper of the two configure and make processes that pass the 
env you need like:

1) using the included pkgconfig_env.cmake
2) calling the wrapper script as I' ve tried to show subsequently by 
modifying your second call

There could be a simpler way in your case, but I' ve included this as is 
what I' m using for packaging external libraries.

I would really like to have an ENV clause in ExternalProcess to force 
all the called steps to have a defined environment

HTH
               Luigi










>
> Miki.
>
> P.S. I am doing this on a Mac OSX Lion, but I expect it to work on 
> Linux without modifications.
>
> === CMakeLists.txt ===
>
> cmake_minimum_required(VERSION 2.8)
>
> set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR} CACHE PATH "Path where to 
> install.")
>
> project(dependecies)
>
> include(ExternalProject)
>
> set(ENV{PKG_CONFIG_PATH} 
> "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig/:$ENV{PKG_CONFIG_PATH}")
> message(STATUS "PKG_CONFIG_PATH=$ENV{PKG_CONFIG_PATH}")
>
> ExternalProject_Add(
>     libogg
>     PREFIX libogg
>     URL http://downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.gz
>     URL_MD5 0a7eb40b86ac050db3a789ab65fe21c2
>     UPDATE_COMMAND set
>     CONFIGURE_COMMAND ./configure --prefix=${CMAKE_INSTALL_PREFIX}
>            BUILD_COMMAND make
>     # INSTALL_COMMAND make install
>            BUILD_IN_SOURCE 1
>     )
>
set(_mymoduledir <---- where you put the included file 
pkgconfig_env.cmake ------>
set(conf_command_body ./configure --prefix=${CMAKE_INSTALL_PREFIX}  
--with-ogg=${CMAKE_INSTALL_PREFIX}
string(REPLACE ";" "@@" managed_conf_command_body "${conf_command_body}" )
  set(conf_command CONFIGURE_COMMAND ${CMAKE_COMMAND} 
-Dmy_binary_dir:PATH=<BINARY_DIR> -Dmy_source_dir:PATH=<SOURCE_DIR> 
-Dmy_install_dir:PATH=${CMAKE_INSTALL_PREFIX} 
-Dmy_configure:STRING=${managed_conf_command_body} -P 
${_mymoduledir}/pkgconfig_env.cmake)

set(make_command_body make --jobs 4)
string(REPLACE ";" "@@" managed_make_command_body "${make_command_body}" )
set(make_command BUILD_COMMAND ${CMAKE_COMMAND} 
-Dmy_binary_dir:PATH=<BINARY_DIR> -Dmy_source_dir:PATH=<SOURCE_DIR> 
-Dmy_install_dir:PATH=${CMAKE_INSTALL_PREFIX} 
-Dmy_configure:STRING=${managed_make_command_body} -P 
${_mymoduledir}/pkgconfig_env.cmake)
  set(list_separator "LIST_SEPARATOR @@")

> ExternalProject_Add(
>     libvorbis
>     DEPENDS libogg
>     PREFIX libvorbis
>     URL http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.2.tar.bz2
>     URL_MD5 798a4211221073c1409f26eac4567e8b
>     UPDATE_COMMAND set
         ${conf_command}
         ${make_command}
         ${list_separator}
>
>     # INSTALL_COMMAND make install
>            BUILD_IN_SOURCE 1
>     )
>
>
>
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake


-- 
Luigi Calori
SuperComputing Applications and Innovation Department
CINECA - via Magnanelli, 6/3, 40033 Casalecchio di Reno (Bologna) - ITALY
Tel: +39 051 6171509  Fax: +39 051 6132198
hpc.cineca.it

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20111017/1f3c60d8/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pkgconfig_env.cmake
Type: text/x-cmake
Size: 894 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20111017/1f3c60d8/attachment-0001.bin>


More information about the CMake mailing list