MantisBT - CMake
View Issue Details
0012603CMakeCMakepublic2011-11-30 22:362011-11-30 23:09
Andreas Schuh 
Clinton Stimpson 
normalminoralways
closedduplicate 
Apple MacOS X10.4.10
CMake 2.8.5 
 
0012603: When passing ARGV or ARGN on to subfunction, empty elements are stripped off
When attempting to pass on the optional or all arguments given to one function on to another function using ARGN or ARGV, the empty elements in those lists are stripped off.

Saving the attached example code in a file and executing it with "cmake -P <script>" outputs

foo(s;h;t)
bar(s;h;t)

though the expected output would have been

foo(s;h;;;t)
bar(s;h;;;t)

This bug is related to bug 0012303, but yet seems to differ.
cmake_minimum_required (VERSION 2.6)

function (foo)
  message ("foo(${ARGV})")
endfunction ()

function (bar)
  message ("bar(${ARGV})")
endfunction ()

function (foobar)
  foo (${ARGV})
  bar (${ARGN})
endfunction ()

foobar (s h "" "" "t")
No tags attached.
Issue History
2011-11-30 22:36Andreas SchuhNew Issue
2011-11-30 22:50Andreas SchuhNote Added: 0027876
2011-11-30 23:09Clinton StimpsonNote Added: 0027877
2011-11-30 23:09Clinton StimpsonStatusnew => closed
2011-11-30 23:09Clinton StimpsonAssigned To => Clinton Stimpson
2011-11-30 23:09Clinton StimpsonResolutionopen => duplicate

Notes
(0027876)
Andreas Schuh   
2011-11-30 22:50   
A workaround for this problem in my case was to use a macro instead of a function and in order to still take advantage of the function scopes call this macro inside a function.

Example:

function (set_target_properties)
  my_set_target_properties_impl(${ARGV}) # the macro still sees the empty elements
endfunction ()

function (my_set_target_properties)
  my_set_target_properties_impl(${ARGV}) # the macro still sees the empty elements
endfunction ()

macro (my_set_target_properties_impl)
  # do the actual work here
endmacro ()

Instead of

function (set_target_properties)
  my_set_target_properties(${ARGV}) # the function will not get the empty elements
endfunction ()



Or, the previously example modified:

cmake_minimum_required (VERSION 2.6)

function (foo)
  message ("foo(${ARGV})")
  foreach (ARG IN LISTS ARGV)
    if (ARG MATCHES "^$")
      message ("EMPTY ELEMENT IN LIST")
    endif ()
  endforeach ()
endfunction ()

macro (bar)
  message ("bar(${ARGV})")
  foreach (ARG IN LISTS ARGV)
    if (ARG MATCHES "^$")
      message ("EMPTY ELEMENT IN LIST")
    endif ()
  endforeach ()
endmacro ()

function (foobar)
  foo (${ARGV})
  bar (${ARGV})
endfunction ()


foobar (s h "" "" "t")
(0027877)
Clinton Stimpson   
2011-11-30 23:09   
Duplicate of 12303