On 01/22/2015 04:46 AM, Michael Enßlin wrote:
> (1.2) Using compile-time string manipulations to sanitize the filename.
>       Due to limitations of C++, this requires template metaprogramming,
>       leading to unreasonable complexity and compile times.

See below.

> Over the last several decades, at least on the POSIX platform, it has
> become common practice to invoke compilers with relative file paths

This is only true for in-source builds.  CMake recommends out-of-source,
and then full paths are much more reliable.  Even if one used relative
paths then your messages would still have a bunch of "../" in them for
an out-of-source build.  Therefore I'll assume you're using in-source
builds.

Side note: To make relative paths behave right with __FILE__ you would
also need all include paths (-I) to be relative.  Otherwise headers will
still get full paths.  This would require much more work than just
trying to get compile lines to refer to source files with a relative
path.

So, assuming you have an in-source build then all sources and headers
must sit under a single prefix (the top of the source tree).  With that
you can do something like:

 string(LENGTH "${CMAKE_SOURCE_DIR}/" SRC_DIR_LEN)
 add_definitions(-DSRC_DIR_LEN=${SRC_DIR_LEN})

and then in the source code do:

 #define MY__FILE__ (__FILE__+SRC_DIR_LEN)

That will give you a compile-time constant __FILE__ with a relative path
and no runtime overhead.  Use MY__FILE__ in your log macros.

-Brad

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to