[CMake] function and raise_scope commands

Miguel A. Figueroa-Villanueva miguelf at ieee.org
Sun Dec 23 11:30:11 EST 2007


On Dec 10, 2007 5:14 PM, Ken Martin wrote:
> Thanks for the information. Both these issues I suspect are fairly simple
> bugs and will be fixed.

Hello Ken,

I saw that some changes to the function command where applied to cmake
cvs, so I tested these and my report about the current state of things
is found below. Below is another bug (I think it is related). Let me
know if I should put this in the bug tracker.

> > 1. CMake crashes if I use the same variable name as the argument and
> > raise the scope later. That is, for the following function:
> >
> > function(track_find_variable cache_variable is_changed)
> >   raise_scope(${is_changed})
> > endfunction(track_find_variable)
> >
> > I can't call it like:
> >
> > track_find_variable(testvar is_changed) # I had to mangle is_changed
> > above, but that's ok
> >
> > I think it shouldn't crash. If its too much effort to have cmake
> > support this, then I don't think it is worth it... just having a note
> > that the argument can't be used as a variable name in the help and
> > maybe try to detect the case and signal an error...

This still doesn't work. I don't know if you have done anything for this.

> > 2. Given the new scope contexts, when I call the following function:
> >
> > function(tester)
> >   message(STATUS "${CMAKE_CURRENT_LIST_FILE}")
> > endfunction(tester)
> >
> > tester() prints what it should:
> > D:/builds/temp/testLatexModule/CMakeLists.txt
> >
> > However, if I put it in a cmake_utils.cmake file and call
> > include(cmake_utils):
> >
> > tester() prints garbage... somehow it gets corrupted. For example, in

This works now.

3. I'm having another issue. If you pass a variable to a function that
hasn't been defined previously and that isn't defined in the function
either, then it crashes when you do a raise_scope on it.

For instance, if you have the following function:

FUNCTION(LISTAPPEND _list _value)
  IF(_value)
    LIST(APPEND ${_list} ${_value})
  ENDIF(_value)

  RAISE_SCOPE(${_list})
ENDFUNCTION(LISTAPPEND)

Then this crashes:

LISTAPPEND(somelist FALSE)
MESSAGE(STATUS "${somelist}")
LISTAPPEND(somelist TRUE)
MESSAGE(STATUS "${somelist}")

But this works fine:

LISTAPPEND(somelist TRUE)
MESSAGE(STATUS "${somelist}")
LISTAPPEND(somelist FALSE)
MESSAGE(STATUS "${somelist}")

If you set the variable somelist, before calling the function it will
work fine. That is, the following works fine:

SET(somelist "")
LISTAPPEND(somelist FALSE)
MESSAGE(STATUS "${somelist}")
LISTAPPEND(somelist TRUE)
MESSAGE(STATUS "${somelist}")

If you need more help diagnosing the problem, let me know.

--Miguel


More information about the CMake mailing list