Should I use
INCLUDE_DIRECTORIES(
.
)
or
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
)
What is the difference, if any? I've seen mostly "." in existing code, but searching for a dot on the Internet is kind of difficult ...
Should I use
INCLUDE_DIRECTORIES(
.
)
or
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
)
What is the difference, if any? I've seen mostly "." in existing code, but searching for a dot on the Internet is kind of difficult ...
In your case you could think about globally setting CMAKE_INCLUDE_CURRENT_DIR to
ON
.Regarding your question, the answer depends mainly on your own preferences. I prefer the relative paths variant for the readability of your
CMakeLists.txt
files.If you look into CMake's source code at cmTargetIncludeDirectoriesCommand ::Join() and SystemTools::FileIsFullPath() you find the following conditions checked by CMake - after expanding the variables - if it will append
CMAKE_CURRENT_SOURCE_DIR
to the include paths:\
or/
and the second character is not a:
/
or~
In consequence the following CMake code
will show
This automatic and absolute path prefixing behaviour of CMake makes sense because it's possible - and often recommended - to do out-of-source tree builds in CMake (see also CMake policy CMP0021).
You can think about setting CMAKE_USE_RELATIVE_PATHS to
ON
which will convert the include paths back during generation of the build environment to paths relative to yourCMAKE_BINARY_DIR
directory (but it works only with the Makefile generators).Some additional references:
Both uses generate nearly the same output, since CMake tracks the current directory and replaces the occurrence of "." with "${CMAKE_CURRENT_SOURCE_DIR}/.". The only difference is that the "." variant has the extra path component "/." appended.
Whichever you choose is a matter of taste here.