Re: [cmake-developers] How to set environment variable for custom command.

2013-07-20 Thread Nicolas Desprès
On Fri, Jul 19, 2013 at 8:29 PM, Alan W. Irwin ir...@beluga.phys.uvic.cawrote:

 On 2013-07-19 12:35-0400 Matthew Woehlke wrote:

  On 2013-07-19 10:36, Nicolas Desprès wrote:

 In Unix shell we can do that:
 $ VAR=foo cmd in out

 This way the environment variable is only set in the environment of the
 process of the command and not the in current shell like when using the
 export built-in.

 I would like to be able to do the same for a custom command in CMake.
 Ideally I was looking for something like that:

 add_custom_command(
OUTPUT out
COMMAND cmd in out
DEPENDS in
ENVIRONMENT VAR foo
)

 Any idea?


 Well, if you only care about UNIX you can always use /bin/env :-).


 Actually, using env is not that platform-limiting since it is
 available with MSYS.  For those not aware of the env capabilities a
 simple example (setting the PATH in various ways to run different
 cmake varsions) is

 COMMAND ${ENV_EXECUTABLE} PATH=whatever ${CMAKE_COMMAND} --version

 where ENV_EXECUTABLE is the result of find_program(ENV_EXECUTABLE
 env).  Also note that env can be used to set multiple environment
 variables for a particular command.

 I use env a lot for the custom commands in the build_projects project.
 I have found it works fine (with some care) for a number of different
 generators/platforms, e.g., Unix Makefiles on Linux, Ninja (both
 on Linux and for MinGW/MSYS/Windows), MSYS Makefiles, MinGW
 Makefiles, and NMake Makefiles Jom.


That's greate. I did not think about it. Actually, like many developpers I
guess, I use env only the she-bang line of my script or to print the
environment.

Thanks!

-- 
Nicolas Desprès
--

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://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Re: [cmake-developers] How to set environment variable for custom command.

2013-07-19 Thread Nicolas Desprès
Sorry wrong ML :(.


On Fri, Jul 19, 2013 at 4:36 PM, Nicolas Desprès
nicolas.desp...@gmail.comwrote:

 Hi,

 In Unix shell we can do that:
 $ VAR=foo cmd in out

 This way the environment variable is only set in the environment of the
 process of the command and not the in current shell like when using the
 export built-in.

 I would like to be able to do the same for a custom command in CMake.
 Ideally I was looking for something like that:

 add_custom_command(
   OUTPUT out
   COMMAND cmd in out
   DEPENDS in
   ENVIRONMENT VAR foo
   )

 Any idea?

 Cheers,

 --
 Nicolas Desprès




-- 
Nicolas Desprès
--

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://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

[cmake-developers] How to set environment variable for custom command.

2013-07-19 Thread Nicolas Desprès
Hi,

In Unix shell we can do that:
$ VAR=foo cmd in out

This way the environment variable is only set in the environment of the
process of the command and not the in current shell like when using the
export built-in.

I would like to be able to do the same for a custom command in CMake.
Ideally I was looking for something like that:

add_custom_command(
  OUTPUT out
  COMMAND cmd in out
  DEPENDS in
  ENVIRONMENT VAR foo
  )

Any idea?

Cheers,

-- 
Nicolas Desprès
--

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://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Re: [cmake-developers] How to set environment variable for custom command.

2013-07-19 Thread Brad King
On 07/19/2013 10:36 AM, Nicolas Desprès wrote:
 Hi,
 
 In Unix shell we can do that:
 $ VAR=foo cmd in out
 
 This way the environment variable is only set in the environment of the 
 process of the command and not the in current shell like when using the 
 export built-in.
 
 I would like to be able to do the same for a custom command in CMake. Ideally 
 I was looking for something like that:
 
 add_custom_command(
   OUTPUT out
   COMMAND cmd in out
   DEPENDS in
   ENVIRONMENT VAR foo
   )

There has been some progress here:

https://github.com/Kitware/CMake/pull/31

-Brad
--

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://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers


Re: [cmake-developers] How to set environment variable for custom command.

2013-07-19 Thread Matthew Woehlke

On 2013-07-19 10:36, Nicolas Desprès wrote:

In Unix shell we can do that:
$ VAR=foo cmd in out

This way the environment variable is only set in the environment of the
process of the command and not the in current shell like when using the
export built-in.

I would like to be able to do the same for a custom command in CMake.
Ideally I was looking for something like that:

add_custom_command(
   OUTPUT out
   COMMAND cmd in out
   DEPENDS in
   ENVIRONMENT VAR foo
   )

Any idea?


Well, if you only care about UNIX you can always use /bin/env :-).

I'm not sure if build tools on Windows are able to support setting 
environment variables. If you need to do it portably (and can't use the 
code Brad mentioned), you may need to use cmake's -P mode with a script 
that wraps your command (using execute_process) after first setting up 
the desired environment.


--
Matthew

--

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://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Re: [cmake-developers] How to set environment variable for custom command.

2013-07-19 Thread Alan W. Irwin

On 2013-07-19 12:35-0400 Matthew Woehlke wrote:


On 2013-07-19 10:36, Nicolas Desprès wrote:

In Unix shell we can do that:
$ VAR=foo cmd in out

This way the environment variable is only set in the environment of the
process of the command and not the in current shell like when using the
export built-in.

I would like to be able to do the same for a custom command in CMake.
Ideally I was looking for something like that:

add_custom_command(
   OUTPUT out
   COMMAND cmd in out
   DEPENDS in
   ENVIRONMENT VAR foo
   )

Any idea?


Well, if you only care about UNIX you can always use /bin/env :-).


Actually, using env is not that platform-limiting since it is
available with MSYS.  For those not aware of the env capabilities a
simple example (setting the PATH in various ways to run different
cmake varsions) is

COMMAND ${ENV_EXECUTABLE} PATH=whatever ${CMAKE_COMMAND} --version

where ENV_EXECUTABLE is the result of find_program(ENV_EXECUTABLE
env).  Also note that env can be used to set multiple environment
variables for a particular command.

I use env a lot for the custom commands in the build_projects project.
I have found it works fine (with some care) for a number of different
generators/platforms, e.g., Unix Makefiles on Linux, Ninja (both
on Linux and for MinGW/MSYS/Windows), MSYS Makefiles, MinGW
Makefiles, and NMake Makefiles Jom.

Alan
__
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__

Linux-powered Science
__
--

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://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers