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.
Cheers, Nico On Fri, Jul 19, 2013 at 5:39 PM, Dan Kegel <d...@kegel.com> wrote: > On Fri, Jul 19, 2013 at 8:21 AM, Andreas Pakulat <ap...@gmx.de> wrote: > >> In Unix shell we can do that: > >> $ VAR=foo cmd in out > >> I would like to be able to do the same for a custom command in CMake. > > See http://public.kitware.com/Bug/view.php?id=5145 > for previous discussion. > > >> add_custom_command( > >> OUTPUT out > >> COMMAND cmd in out > >> DEPENDS in > >> ENVIRONMENT VAR foo > >> ) > > > > I can see two options to achieve this: ... > > 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. > > c) On Mac and Linux, you can do it inline something like this: > > add_custom_command( > OUTPUT out > COMMAND "FOO=${bar}" my_cmd.sh" > DEPENDS in > ) > > On Windows, you might be able to do it inline like this: > > add_custom_command( > OUTPUT out > COMMAND "set FOO=${bar}" & my_cmd.bat" > DEPENDS in > ) > > (although I haven't tried it, so in both cases you might need to > coax cmake into using a shell by prefixing the command with sh -c > or cmd /c or something.) > -- Nicolas Desprès
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake