[CMake] ARGVx "inherited" by sub-functions?

Paul Smith paul at mad-scientist.net
Mon Aug 3 17:25:31 EDT 2015


Is this a known thing, or a bug (I'm using cmake 3.1.0):

I create this CMakeLists.txt:

  cmake_minimum_required(VERSION 3.1.0)
  project(ArgTest)

  function(FOO one two)
    message(STATUS "extra args are ${ARGN}")
    message(STATUS "third arg is ${ARGV2}")
  endfunction()

  function(BAR one)
    FOO(${one} TWO)
    message(STATUS "do something with ${ARGN}")
  endfunction()

  BAR(ONE N1 N2 N3 N4)

Note how I invoke BAR() with 5 arguments, but BAR invokes FOO with only
two arguments.  I would expect that the third argument ${ARGV3} would be
empty in function FOO.

However, when I run cmake on this file it shows:

  -- extra args are
  -- third arg is N2
  -- do something with N1;N2;N3;N4

So the ARGN for function FOO is correct (nothing there) but FOO has
"inherited" the extra ARGVx arguments beyond the first two, that I
passed to function BAR!

That's rather unexpected.  Bug or feature?



More information about the CMake mailing list