2011/4/27 Alexander Neundorf <[email protected]>: > On Wednesday 27 April 2011, Nicolas Desprès wrote: >> Hi, >> >> I'm experimenting with the variables available in script mode in the >> current master (a3a581f8cd): >> >> CMAKE_SCRIPT_MODE_FILE >> CMAKE_ARGC >> CMAKE_ARGVx >> >> Apparently they are not available in 2.8.4 yet. >> >> Using this test script: >> >> ################## >> message("Begin") >> message("CMAKE_SCRIPT_MODE_FILE=${CMAKE_SCRIPT_MODE_FILE}") >> message("CMAKE_ARGC=${CMAKE_ARGC}") >> foreach(i RANGE 0 ${CMAKE_ARGC}) >> message("CMAKE_ARGV${i}=${CMAKE_ARGV${i}}") >> endforeach(i) >> message("CMAKE_ARGV=${CMAKE_ARGV}") >> message("CMAKE_ARGN=${CMAKE_ARGN}") >> message("End") >> ################# >> >> I have the following behavior: >> >> $ ~/build/cmake/git/_build/bin/cmake -P /tmp/test.cmake a1 a2 >> Begin >> CMAKE_SCRIPT_MODE_FILE=/tmp/test.cmake >> CMAKE_ARGC=5 >> CMAKE_ARGV0=/home/despre_n/build/cmake/git/_build/bin/cmake >> CMAKE_ARGV1=-P >> CMAKE_ARGV2=/tmp/test.cmake >> CMAKE_ARGV3=a1 >> CMAKE_ARGV4=a2 >> CMAKE_ARGV5= >> CMAKE_ARGV= >> CMAKE_ARGN= >> End >> >> I think the user does not care about having CMAKE_ARGV1=-P and >> CMAKE_ARGV2=/tmp/test.cmake >> I have attached a patch that do this behavior: >> >> $ ~/build/cmake/git/_build/bin/cmake -P /tmp/test.cmake a1 a2 >> Begin >> CMAKE_SCRIPT_MODE_FILE=/tmp/test.cmake >> CMAKE_ARGC=2 >> CMAKE_ARGV0=a1 >> CMAKE_ARGV1=a2 >> CMAKE_ARGV2= >> CMAKE_ARGV= >> CMAKE_ARGN= >> End > > I'm not sure I like this special handling. > See this example: > $ /opt/cmake-HEAD/bin/cmake -DFOO=TRUE -P test.cmake abc 123 > Begin > CMAKE_SCRIPT_MODE_FILE=/home/alex/src/tests/cmakeargs/test.cmake > CMAKE_ARGC=6 > CMAKE_ARGV0=/opt/cmake-HEAD/bin/cmake > CMAKE_ARGV1=-DFOO=TRUE > CMAKE_ARGV2=-P > CMAKE_ARGV3=test.cmake > CMAKE_ARGV4=abc > CMAKE_ARGV5=123 > CMAKE_ARGV6= > CMAKE_ARGV= > CMAKE_ARGN= > End > > > I think it's ok to just hand all the arguments to the cmake script, so it can > look at everything and figure out what to do. >
You score a point :-) But then command line arguments parsing starts to be tedious from the script point of view. Plus in your use case FOO will be set as a variable anyway so the script can picked it up from the cache. Actually, most of the cmake's options will have side effects of this type. Even the script name is made available as CMAKE_SCRIPT_MODE_FILE. The script will have to parse cmake's options that have already been parsed by cmake. I don't see any reason to pass these options to the script. Imagine something like that: $ cmake -DFOO=ON -Wdev --trace --debug-output --debug-trycompile --warn-uninitialized --warn-unused-vars -P test.cmake a1 a2 I truely think the script writer don't want to hear about all the options before -P. -- Nicolas Desprès _______________________________________________ cmake-developers mailing list [email protected] http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers
