<div dir="ltr">Thank you all for your suggestion. I will go with the script shell wrapper trick even if I am not a big fan of it. I don't like the burden of generating a wrapper just to set environment variable. Luckily CMake will provides such a feature in the future.<div>
<br></div><div>Cheers,</div><div>Nico<div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 19, 2013 at 5:39 PM, Dan Kegel <span dir="ltr"><<a href="mailto:dank@kegel.com" target="_blank">dank@kegel.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Fri, Jul 19, 2013 at 8:21 AM, Andreas Pakulat <<a href="mailto:apaku@gmx.de">apaku@gmx.de</a>> wrote:<br>
>> In Unix shell we can do that:<br>
>> $ VAR=foo cmd in out<br>
</div><div class="im">>> I would like to be able to do the same for a custom command in CMake.<br>
<br>
</div>See <a href="http://public.kitware.com/Bug/view.php?id=5145" target="_blank">http://public.kitware.com/Bug/view.php?id=5145</a><br>
for previous discussion.<br>
<div class="im"><br>
>> add_custom_command(<br>
>> OUTPUT out<br>
>> COMMAND cmd in out<br>
>> DEPENDS in<br>
>> ENVIRONMENT VAR foo<br>
>> )<br>
><br>
</div>> I can see two options to achieve this: ...<br>
<div class="im">> b) let cmake generate a shell script (using configure_file) and set the<br>
> envvar in there, it would also contain the command executable and pass on<br>
> any arguments using $@. Then use the script as custom command instead of the<br>
> real command.<br>
<br>
</div>c) On Mac and Linux, you can do it inline something like this:<br>
<br>
add_custom_command(<br>
OUTPUT out<br>
COMMAND "FOO=${bar}" my_cmd.sh"<br>
DEPENDS in<br>
)<br>
<br>
On Windows, you might be able to do it inline like this:<br>
<br>
add_custom_command(<br>
OUTPUT out<br>
COMMAND "set FOO=${bar}" & my_cmd.bat"<br>
DEPENDS in<br>
)<br>
<br>
(although I haven't tried it, so in both cases you might need to<br>
coax cmake into using a shell by prefixing the command with sh -c<br>
or cmd /c or something.)<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Nicolas Desprès<br>
</div></div></div>