[CMake] How to configure CMake to add current path to include directive.

Steve Lorimer steve.lorimer at gmail.com
Sun Oct 16 18:46:26 EDT 2016


In makefile parlance, I'm trying to add -I. (ie: the current directory) to
my include paths

I tried the following:

include_directories(".")


This doesn't work unfortunately, as relative paths are interpreted as
relative to the current source directory
<https://cmake.org/cmake/help/v3.0/command/include_directories.html>

That is, if this statement is in my top level CMakeLists.txt, located in
~/src/project, the include directive added will be "-I ~/src/project/.",
whereas I'm trying to add "-I ."

The reason for my wanting this is that we have sources for a single library
in several subdirs.

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

add_library(
foo
STATIC
foo.cpp
bar/bar.cpp
)

In bar/bar.cpp, I have a relative include

#include "../foo.h"

With the above setup, this will fail to compile as only ~/src/project/foo
will be added to the include paths.

I'm aware that if I explicitly added the path it would work

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/bar)

However, if there is a way to get -I. added to my include path, that's what
I'm after.

TIA
Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20161016/4f0c1f4e/attachment.html>


More information about the CMake mailing list