<div dir="ltr">Hi,<div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jul 19, 2013 at 4:37 PM, Nicolas Desprès <span dir="ltr">&lt;<a href="mailto:nicolas.despres@gmail.com" target="_blank">nicolas.despres@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div><div>In Unix shell we can do that:</div><div>$ VAR=foo cmd in out</div><div>
<br></div><div>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 &quot;export&quot; built-in.</div>

<div><br></div><div>I would like to be able to do the same for a custom command in CMake. Ideally I was looking for something like that:</div><div><br></div><div>add_custom_command(</div><div>  OUTPUT out</div><div>  COMMAND cmd in out</div>


<div>  DEPENDS in</div><div>  ENVIRONMENT VAR foo</div><div>  )</div><div></div></div></blockquote></div></div><div class="gmail_extra"><br></div><div class="gmail_extra" style>I can see two options to achieve this:</div>
<div class="gmail_extra" style><br></div><div class="gmail_extra" style>a) set the environment variable when calling make in the same way as above. Custom commands are actually executed by make and get the envvars from the make environment</div>
<div class="gmail_extra" style><br></div><div class="gmail_extra" style>b) let cmake generate a shell script (using configure_file) and set the envvar in there, it would also contain the command executable and pass on any arguments using $@. Then use the script as custom command instead of the real command.</div>
<div class="gmail_extra" style><br></div><div class="gmail_extra" style>Andreas</div></div>