View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014118CMakeCMakepublic2013-04-27 20:572016-06-10 14:31
ReporterKyle Heath 
Assigned ToKitware Robot 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionmoved 
PlatformpcOSubuntuOS Version12.04
Product VersionCMake 2.8.10.2 
Target VersionFixed in Version 
Summary0014118: CMAKE_CURRENT_LIST_LINE reports wrong line number
DescriptionThe 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.
Steps To ReproduceAttached 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)
  
TagsNo tags attached.
Attached Filesgz file icon cmake_line_bug.tar.gz [^] (628 bytes) 2013-04-27 20:57

 Relationships

  Notes
(0032947)
Rolf Eike Beer (developer)
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 (reporter)
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 (manager)
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 (developer)
2013-11-02 09:19

Looks like this bug should be closed.
(0042273)
Kitware Robot (administrator)
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.

 Issue History
Date Modified Username Field Change
2013-04-27 20:57 Kyle Heath New Issue
2013-04-27 20:57 Kyle Heath File Added: cmake_line_bug.tar.gz
2013-04-28 04:18 Rolf Eike Beer Note Added: 0032947
2013-04-28 15:08 Kyle Heath Note Added: 0032951
2013-04-29 09:24 Brad King Note Added: 0032953
2013-11-02 09:19 Stephen Kelly Note Added: 0034316
2016-06-10 14:28 Kitware Robot Note Added: 0042273
2016-06-10 14:28 Kitware Robot Status new => resolved
2016-06-10 14:28 Kitware Robot Resolution open => moved
2016-06-10 14:28 Kitware Robot Assigned To => Kitware Robot
2016-06-10 14:31 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team