[CMake] Environment variables and ExternalProject

2011-10-17 Thread Milutin Jovanović
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?

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
)

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
CONFIGURE_COMMAND PKG_CONFIG_PATH=${CMAKE_INSTALL_PREFIX}/lib/pkgconfig
 export PKG_CONFIG_PATH  set  ./configure
--prefix=${CMAKE_INSTALL_PREFIX} --with-ogg=${CMAKE_INSTALL_PREFIX}
BUILD_COMMAND make
# 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

Re: [CMake] Environment variables and ExternalProject

2011-10-17 Thread Luigi Calori

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

set(ENV{PATH} ${my_install_dir}/bin:$ENV{PATH})
string(REPLACE @@ ; my_configure ${my_configure} )

set(ENV{PKG_CONFIG_PATH} ${my_install_dir}/lib/pkgconfig)
set(ENV{LD_LIBRARY_PATH} 

Re: [CMake] Environment variables and ExternalProject

2011-10-17 Thread Milutin Jovanović
Thanks Luigi. I feared a workaround was necessary. I will go over your
suggestion and try to apply it.

I'll second your suggestion for providing environment variables for
ExternalProjects.

Miki.
--

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

Re: [CMake] Environment variables and ExternalProject

2011-10-17 Thread David Cole
For now, a wrapper script is definitely the way to do this.

We need the ability to specify environment values generically in the
add_custom_command command. Once we have that, adding support to
ExternalProject will be trivial. Until we have that, a wrapper script
work-around is valid now and will still be valid after we add that
feature.

There are no concrete plans that I am aware of to do this work in the
near future. But when it is done (eventually), you'll probably hear
about it first here on this mailing list...


Thanks,
David C.


2011/10/17 Milutin Jovanović jovanovic.milu...@gmail.com:

 Thanks Luigi. I feared a workaround was necessary. I will go over your
 suggestion and try to apply it.

 I'll second your suggestion for providing environment variables for
 ExternalProjects.

 Miki.


 --

 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

--

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