<div class="gmail_quote">2011/4/28 Nicolas Desprès <span dir="ltr"><<a href="mailto:nicolas.despres@gmail.com">nicolas.despres@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
2011/4/27 Alexander Neundorf <<a href="mailto:neundorf@kde.org">neundorf@kde.org</a>>:<br>
<div><div></div><div class="h5">> On Wednesday 27 April 2011, Nicolas Desprès wrote:<br>
>> Hi,<br>
>><br>
>> I'm experimenting with the variables available in script mode in the<br>
>> current master (a3a581f8cd):<br>
>><br>
>> CMAKE_SCRIPT_MODE_FILE<br>
>> CMAKE_ARGC<br>
>> CMAKE_ARGVx<br>
>><br>
>> Apparently they are not available in 2.8.4 yet.<br>
>><br>
>> Using this test script:<br>
>><br>
>> ##################<br>
>> message("Begin")<br>
>> message("CMAKE_SCRIPT_MODE_FILE=${CMAKE_SCRIPT_MODE_FILE}")<br>
>> message("CMAKE_ARGC=${CMAKE_ARGC}")<br>
>> foreach(i RANGE 0 ${CMAKE_ARGC})<br>
>>   message("CMAKE_ARGV${i}=${CMAKE_ARGV${i}}")<br>
>> endforeach(i)<br>
>> message("CMAKE_ARGV=${CMAKE_ARGV}")<br>
>> message("CMAKE_ARGN=${CMAKE_ARGN}")<br>
>> message("End")<br>
>> #################<br>
>><br>
>> I have the following behavior:<br>
>><br>
>> $ ~/build/cmake/git/_build/bin/cmake -P /tmp/test.cmake a1 a2<br>
>> Begin<br>
>> CMAKE_SCRIPT_MODE_FILE=/tmp/test.cmake<br>
>> CMAKE_ARGC=5<br>
>> CMAKE_ARGV0=/home/despre_n/build/cmake/git/_build/bin/cmake<br>
>> CMAKE_ARGV1=-P<br>
>> CMAKE_ARGV2=/tmp/test.cmake<br>
>> CMAKE_ARGV3=a1<br>
>> CMAKE_ARGV4=a2<br>
>> CMAKE_ARGV5=<br>
>> CMAKE_ARGV=<br>
>> CMAKE_ARGN=<br>
>> End<br>
>><br>
>> I think the user does not care about having CMAKE_ARGV1=-P and<br>
>> CMAKE_ARGV2=/tmp/test.cmake<br>
>> I have attached a patch that do this behavior:<br>
>><br>
>> $ ~/build/cmake/git/_build/bin/cmake -P /tmp/test.cmake a1 a2<br>
>> Begin<br>
>> CMAKE_SCRIPT_MODE_FILE=/tmp/test.cmake<br>
>> CMAKE_ARGC=2<br>
>> CMAKE_ARGV0=a1<br>
>> CMAKE_ARGV1=a2<br>
>> CMAKE_ARGV2=<br>
>> CMAKE_ARGV=<br>
>> CMAKE_ARGN=<br>
>> End<br>
><br>
> I'm not sure I like this special handling.<br>
> See this example:<br>
> $ /opt/cmake-HEAD/bin/cmake -DFOO=TRUE -P test.cmake abc 123<br>
> Begin<br>
> CMAKE_SCRIPT_MODE_FILE=/home/alex/src/tests/cmakeargs/test.cmake<br>
> CMAKE_ARGC=6<br>
> CMAKE_ARGV0=/opt/cmake-HEAD/bin/cmake<br>
> CMAKE_ARGV1=-DFOO=TRUE<br>
> CMAKE_ARGV2=-P<br>
> CMAKE_ARGV3=test.cmake<br>
> CMAKE_ARGV4=abc<br>
> CMAKE_ARGV5=123<br>
> CMAKE_ARGV6=<br>
> CMAKE_ARGV=<br>
> CMAKE_ARGN=<br>
> End<br>
><br>
><br>
> I think it's ok to just hand all the arguments to the cmake script, so it can<br>
> look at everything and figure out what to do.<br>
><br>
<br>
</div></div>You score a point :-) But then command line arguments parsing starts<br>
to be tedious from the script point of view.<br>
Plus in your use case FOO will be set as a variable anyway so the<br>
script can picked it up from the cache. Actually, most of the cmake's<br>
options will have side effects of this type. Even the script name is<br>
made available as CMAKE_SCRIPT_MODE_FILE. The script will have to<br>
parse cmake's options that have already been parsed by cmake. I don't<br>
see any reason to pass these options to the script.<br>
<br>
Imagine something like that:<br>
$ cmake -DFOO=ON -Wdev --trace --debug-output --debug-trycompile<br>
--warn-uninitialized --warn-unused-vars -P test.cmake a1 a2<br>
<br>
I truely think the script writer don't want to hear about all the<br>
options before -P.<br>
<br>
--<br>
<font color="#888888">Nicolas Desprès<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
cmake-developers mailing list<br>
<a href="mailto:cmake-developers@cmake.org">cmake-developers@cmake.org</a><br>
<a href="http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers" target="_blank">http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers</a><br>
</div></div></blockquote></div><br><br>For these to be really useful, we should also introduce the notion of arguments that CMake will ignore. (i.e. : put a "--" at the end, and the stuff after that gets ignored by CMake, and only passed on to the script itself.) For example, in the above case, a1 and a2 may well trigger a command line error from CMake itself. Perhaps even after the script has run...<br>
<br>I agree with Alex. If we are going to keep these variables and make them useful, then they should contain the "argc" and "argv" from the C++ main of CMake itself, so that the script can analyze them if it wants to. If it doesn't... that's fine too, but at least they'll be there if somebody needs to validate something based on them.<br>
<br>I think this feature should be considered an experiment, and possibly even backed out of master and not put into the upcoming 2.8.5 release if there is disagreement about how it should behave. There are other command line nigglies that should probably be cleaned up anyhow before this is really ready.<br>
<br>For example, consider the following (unusual, but possible) case and its present behavior:<br><br>  cmake -DMyOption=ON -P script1.cmake -DMyOption=OFF -P script1.cmake -DMyOption=Custom -P script1.cmake<br><br>Anybody care to guess what the output is, when script1.cmake contains "message("MyOption='${MyOption}'")<br>
<br>:-)<br><br>