MantisBT - CMake
View Issue Details
0014118CMakeCMakepublic2013-04-27 20:572016-06-10 14:31
Kyle Heath 
Kitware Robot 
normalminoralways
closedmoved 
pcubuntu12.04
CMake 2.8.10.2 
 
0014118: CMAKE_CURRENT_LIST_LINE reports wrong line number
The behavior of CMAKE_CURRENT_LIST_LINE doesn't match the documentation. It should return the line of the CMakeList.txt at bottom of the call stack, but instead it returns the line number of the macro file where it appears.
Attached is a CMakeLists.txt that prints the value of CMAKE_CURRENT_LIST_LINE (Case A) and then calls a macro in my_macros.cmake that prints the value of CMAKE_CURRENT_LIST_LINE (Case B).

Case A gives the correct line number... line 3
Case B gives the incorrect line number... line 7 (of my_macros.cmake) but should be line 5 (of CMakeLists.txt)
  
No tags attached.
gz cmake_line_bug.tar.gz (628) 2013-04-27 20:57
https://public.kitware.com/Bug/file/4751/cmake_line_bug.tar.gz
Issue History
2013-04-27 20:57Kyle HeathNew Issue
2013-04-27 20:57Kyle HeathFile Added: cmake_line_bug.tar.gz
2013-04-28 04:18Rolf Eike BeerNote Added: 0032947
2013-04-28 15:08Kyle HeathNote Added: 0032951
2013-04-29 09:24Brad KingNote Added: 0032953
2013-11-02 09:19Stephen KellyNote Added: 0034316
2016-06-10 14:28Kitware RobotNote Added: 0042273
2016-06-10 14:28Kitware RobotStatusnew => resolved
2016-06-10 14:28Kitware RobotResolutionopen => moved
2016-06-10 14:28Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0032947)
Rolf Eike Beer   
2013-04-28 04:18   
Works as advertised: the current file processed is the macro file. When you want the line of the caller you must pass ${CMAKE_CURRENT_LIST_LINE} as argument to the debug macros so it knows what to print.
(0032951)
Kyle Heath   
2013-04-28 15:08   
The advertising is not clear... The naming scheme prefix "CMAKE_CURRENT_LIST" should indicate a consistent definition of what file is "current list". The documentation for CMAKE_CURRENT_LIST_DIR and CMAKE_CURRENT_LIST_FILE explain in detail... while the CMAKE_CURRENT_LIST_LINE is a one-liner. This could lead the user to believe it was the same definition as other variables from the same family.

The naming scheme would suggest that a macro writer could print a message indicating the call site of a macro to which invalid parameters were passed with this construct:

MESSAGE(FATAL_ERROR "Invalid use of MY_MACRO at ${CMAKE_CURRENT_LIST_FILE} at line ${CMAKE_CURRENT_LIST_LINE}")

Suggestion:

Define two different variables for handling line numbers:

CMAKE_CURRENT_LIST_LINE - where "current list" is consistent with the definitions used in CMAKE_CURRENT_LIST_FILE and CMAKE_CURRENT_LIST_DIR

CMAKE_CURRENT_SOURCE_LINE - "current source" is the file in which the variable is used

As it stands, it seems I can't tell the user of the macro (or potentially IDE error parsers) where the invalid use of the macro occurred because there is no way to report the line number of the call site.
(0032953)
Brad King   
2013-04-29 09:24   
Re 0014118:0032951:
> no way to report the line number of the call site

You can use

 message(AUTHOR_WARNING "Invalid arguments to this macro")

or

 message(FATAL_ERROR "Invalid arguments to this macro")

and the result will include the full call stack with file names and line numbers.

 http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:message [^]
(0034316)
Stephen Kelly   
2013-11-02 09:19   
Looks like this bug should be closed.
(0042273)
Kitware Robot   
2016-06-10 14:28   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.