[CMake] Setting environment variables prebuild

Kito Berg-Taylor kito.berg-taylor at dlr.de
Tue Mar 10 05:45:06 EDT 2009


Upon further consideration, I think fixing the codeblocks project file
is probably too specific of a fix. After all, the only way to come
across this issue is if you are cross-compiling, in which case you need
to write a toolchain file anyway. The problem here, IMHO, is that there
are insufficient capabilities for setting up the build environment when
cross-compiling. It should be possible to setup all the necessary
environment conditions in the toolchain.cmake file, so that I can have
different environment variables depending on what I'm cross-compiling
for.

The following patch to the underlying Makefile solves the problem for
all IDEs that build using UNIX makefiles:


        --- Makefile 2009-03-10 10:02:10.250079759 +0100
        +++ Makefile_QNX 2009-03-10 10:31:20.359078662 +0100
        @@ -29,6 +29,12 @@
        #=============================================================================
        # Set environment variables for the build.
        
        +# QNX Environment Variables
        +QNX_HOST := /home/kito/work/qnx640/host/linux/x86
        +QNX_TARGET := /home/kito/work/qnx640/target/qnx6
        +QNX_CONFIGURATION := /etc/qnx
        +Path := ${Path};/home/kito/work/qnx640/host/linux/x86/usr/bin
        +
        # The shell in which to execute make rules.
        SHELL = /bin/sh

I'm sure there are similar solutions that would apply for the other
build systems. Being able to set a series of environment variables and
their values in the toolchain file would be a much more general solution
that adjusting the individual project files. For example, on the
machines I have here, not all of them even have QCC as a compiler option
in Codeblocks. Some of them have QCC, but also require changes to the
Path environment variable before they will compile cmake projects for
qnx. However, the above patch works on all of the machines I've tested,
in both Codeblocks and Eclipse. (Of course those paths need to be
correct for each machine, but since my toolchain file knows the value of
these variables, that shouldn't be a big problem).

-kito

On Tue, 2009-03-10 at 03:11 -0400, cmake-request at cmake.org wrote:

> Date: Tue, 10 Mar 2009 01:00:22 +0100
> From: Alexander Neundorf <a.neundorf-work at gmx.net>
> Subject: Re: [CMake] Setting environment variables prebuild
> To: cmake at cmake.org
> Cc: Kito Berg-Taylor <kito.berg-taylor at dlr.de>
> Message-ID: <200903100100.22277.a.neundorf-work at gmx.net>
> Content-Type: text/plain;  charset="iso-8859-1"
> 
> On Tuesday 03 March 2009, Kito Berg-Taylor wrote:
> > Hello all,
> >
> > I'm very new to cmake, so excuse me if I'm missing some obvious
> > functionality that cmake already has.
> >
> > I am building a project using a QNX cross-compile toolchain that I
> > setup. For those not familiar with the QNX toolchain, the QNX compiler
> > qcc is a wrapper around gcc that's mostly the same but has a few
> > peculiarities. Of particular relevance, it requires QNX_HOST and
> > QNX_TARGET (and QNX_CONFIGURATION on win32) to be set as environment
> > variables. I have setup my toolchain_qnx640.cmake file to automatically
> > locate the $QNX_HOST (...etc) path and then set it as follows:
> >
> > SET( ENV{QNX_HOST} ${PATH_TO_QNX_HOST} )
> >
> > This allows the configure/generate steps to work correctly, however when
> > I go to build the project unless these variables are set separately in
> > the environment, the build will fail. In other words, CMake is not
> > setting this variable as part of the build (although it did set them
> > when it went to test the compiler, because qcc passed the compiler
> > test).
> >
> > When building from UNIX Makefiles I can set the variable at the console
> > and then "make" and it will work. When using Codeblocks projects if (and
> > only if) I change the project compiler to QCC Compiler it will also
> > build, since Codeblocks knows how to setup the environment for QCC. I
> > can't find a way to make QCC the default compiler when generating the
> > project (otherwise this will get overridden every time the project is
> > re-generated). 
> 
> You mean the generated project file for CodeBlocks should say that the 
> compiler is qcc, but it doesn't ?
> Can you please send my a codeblocks project file for a hello-world style 
> application using qcc, so I can have a look what it should contain ?
> 
> > Eclipse CDT projects similarly won't build, unless I mess
> > around with the project settings (new to eclipse, haven't found the
> > right settings yet).
> 
> Same here.
> 
> Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090310/7b17061c/attachment-0001.htm>


More information about the CMake mailing list