[CMake] Cmake absolute paths with gcc, __FILE__ , and logging
Gregor Jasny
gjasny at googlemail.com
Fri Jan 4 17:09:44 EST 2013
Hello Willy,
On 1/4/13 4:58 PM, Willy Lambert wrote:
> I am trying to convert an existing project from Manual Makefiles to
> Cmake for building it.
> We have a logger that rely on the __FILE__ define to say which file is
> "writing" into the log but this is broken by the CMake default
> behavior using absolute paths.
> So I wonder if there is any way to have the file name in the code to
> be able to log "Error : line XXX in file.cpp".
This is somewhat hackish and should be surrounded by a check for the
Makefile generator:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst
${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
Thanks,
Gregor
More information about the CMake
mailing list