[CMake] Cmake absolute paths with gcc, __FILE__ , and logging

Willy Lambert lambert.willy at gmail.com
Fri Jan 4 11:47:32 EST 2013


2013/1/4 Willy Lambert <lambert.willy at gmail.com>:
> Hi all,
>
> Short Story :
>
> 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".
>
>
>
>
> Long Story :
>
>
>
> So I have for instance a source /home/me/src/main.cpp, compiled with
> relative paths "gcc -o main.cpp".
> So the logger say  "Error : line XXX in main.cpp".
>
> Going further, if I have a file "dummy.hpp" included from main.cpp
> that have for any reason an inlined function that log something, it
> will say "Error : line YYYin dummy.hpp" from main.cpp. This is due to
> the fact that gcc plays with __FILE__ behind the scene.
>
> What defines the __FILE__ value is the path given to the preprocessor
> (so the one given to gcc, so the one given by the makefile generated
> by CMake). So now I have something like :
> "Error : line XXX in /home/me/src/main.cpp"
> which is very anoying because :
> 1/ it reduces lisibility
> 2/ it show a wrong path when the project is on another machine.
>
>
> I tried to use the suggested trigger "set_source_files_properties" to
> define my own __FILE__ but it doesn't works with included files (it
> shows main.cpp instead oh dummy.hpp)
> http://www.cmake.org/pipermail/cmake/2011-December/048281.html
>
> So this way is a dead end because the compilator (and the one that
> creates its command line)  is the only one to be aware of this
> information.
>
> Beside that, as I would really like to simplify the "VERBOSE=2 make"
> output to be able to debug what CMake generates I currently have
> plenty of path with 20 or more folder level including many "../..", I
> am looking on making CMake giving relatives paths to gcc.
>
> I have seen some thread about the use of CMAKE_USE_RELATIVE_PATHS, but
> it seems that it is not working, and maybe with no will to support
> this (is that true ?)
> http://cmake.3232098.n2.nabble.com/CMAKE-USE-RELATIVE-PATHS-td4042914.html
>

for completeness :
http://public.kitware.com/Bug/view.php?id=12563

I'm under linux, is this just a problem under MSVC ?




> Does anyone have succeeded with relatives path in CMake ?


More information about the CMake mailing list