cmake and include dirs

Brad King brad.king at kitware.com
Thu Feb 16 16:03:56 CET 2006


David Faure wrote:
> When having file in subdirs, we (will soon) have to write something like:
> 
> include_directories(
>   ${CMAKE_CURRENT_SOURCE_DIR}/misc
[snip]
> )
> include_directories(
>   ${CMAKE_CURRENT_BINARY_DIR}/misc
[snip]
> )
> 
> Could this be factorized, to have a way to specify both srcdir and builddir in one go?
> Ideally I would just write 
> include_directories(misc dom xml html rendering ecma imload imload/decoders)
> and for relative paths, cmake would interpret that as "in current source dir -and- in current
> build dir".

The convention we have been using in CMake for relative paths given in 
commands is to always treat them as relative to 
${CMAKE_CURRENT_SOURCE_DIR}.  This feature can be added to the 
include_directories command but I'd rather not also include the binary 
tree automatically.  Many projects do not have generated headers in 
every subdirectory and it will just make their include paths longer than 
necessary.

I suggest you create a macro that loops over its arguments and adds the 
paths relative to ${CMAKE_CURRENT_BINARY_DIR} and then 
${CMAKE_CURRENT_SOURCE_DIR}:

macro(kde4_add_subdirectory_includes)
   foreach(d ${ARGV})
     include_directories(${CMAKE_CURRENT_BINARY_DIR}/${d})
     include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${d})
   endforeach(d)
endmacro(kde4_add_subdirectory_includes)

Then

kde4_add_subdirectory_includes(
   misc dom xml html rendering ecma imload imload/decoders)

-Brad


More information about the Kde-buildsystem mailing list