In your case, you might think of globally setting CMAKE_INCLUDE_CURRENT_DIR to ON .
Regarding your question, the answer depends mainly on your own preferences. I prefer the option of relative paths for the readability of your CMakeLists.txt files.
If you look at the CMake source code at cmTargetIncludeDirectoriesCommand :: Join () and SystemTools :: FileIsFullPath (), you will find the following conditions noted by CMake - after expanding the variables - if it adds CMAKE_CURRENT_SOURCE_DIR to the include paths:
- As a rule, it should not contain generator expressions
- On Windows, everything that doesn't start with
\ or / , and the second character is not : - On Unix, anything that doesn't start with
/ or ~
As a result, the following CMake code
include_directories(.) get_directory_property(_inc_dirs INCLUDE_DIRECTORIES) message("_inc_dirs: ${_inc_dirs}")
will show
_inc_dirs: [...your CMakeLists.txt path ...]/.
This automatic and absolute behavior of the CMake path path prefix makes sense because it is possible - and often recommended - to build the tree outside the source code in CMake (see also CMake policy CMP0021 ).
You might consider setting CMAKE_USE_RELATIVE_PATHS to ON , which will convert include paths when generating the build environment in a path relative to your CMAKE_BINARY_DIR directory (but it only works with Makefile generators).
Some sitelinks include:
source share