[cmake-developers] What about #line like feature in cmake language?

Brad King brad.king at kitware.com
Thu May 22 09:16:17 EDT 2014


On 05/21/2014 04:05 PM, Nicolas Desprès wrote:
> at the time the AST node is created the file location is frozen.
> Locations are controlled by the lexer so do comments.

Correct.  This has to be done by the lexer.  We already have
documentation blocks that are "indistinguishable from comments":

 #.rst:
 # ...reStructuredText docs...

 #[=====[.rst:
 ...reStructuredText docs...
 #]=====]

I see no reason this can't be used for #line too:

 #.cmake-source-line: 1234 "/path/to/real/file"

In all of the above cases there is no semantic meaning to the
comments as far as the CMake language processor is concerned.
The last case only changes the file names and line numbers in
backtraces.

One remaining challenge is CMAKE_CURRENT_LIST_FILE and
CMAKE_CURRENT_LIST_LINE.  Since the "current file" is not
handled by the lexer these may not be consistent unless some
kind of refactoring is done in the language implementation.
However, it is not clear whether CMAKE_CURRENT_LIST_FILE can
safely refer back to some transformed location because sometimes
code uses it to look next to the file being processed to locate
other files.  If some source location mapping is in place then
that may not be well-defined.

-Brad




More information about the cmake-developers mailing list