Part of that is the Ninja generator normalizing many paths. The other is that CMake deduplicates include paths by textual equivalence (possibly with a trailing / being ignored). Anything else would generally result in a lot more work being done at generate time.
I don’t recommend using . and .. in your include directories; the working directory of the compiler is different for different generators, so they don’t mean the same thing. I think using absolute paths here would generally make things more readable and be closer to what you want.
It shouldn’t matter. The target_include_directories() command internally converts relative paths to absolute before storing them in the INCLUDE_DIRECTORIES target property. It treats relative paths as being relative to the current source directory.
The . and … was only used to show the problem.
IMHO: converting too realpath while generating would be better and not to expensive.
It whould reduce the build time too.
Interesting is the result if the build dir is not part of source dir.
I wonder. REALPATH has other effects that may be undesirable. For instance, it also resolves symlinks, so if there are two include paths and one is symlinked to the other, that one will be eliminated. Which is probably fine… except when it isn’t.
Ultimately, is it CMake’s job to be pruning directories out of the include list at generate time, when those directories are meant to be consumed at build time? There could be situations where paths that are listed in target_include_directories() will end up looking different during the build process than they do when generating. CMake trying to be too smart could cause problems for some users.
I mean, ultimately, what you point to as a “problem” is only a problem because you actually specified the same directory multiple times, in different forms. CMake merely passed along the parameters you gave it to the build system. Perhaps the right answer is simply, “Don’t do that.”?
I want that cmake generators normalize include directories with i.e. unix realpath:
NAME
realpath - print the resolved path
SYNOPSIS
realpath [OPTION]... FILE...
DESCRIPTION
Print the resolved absolute file name; all but the last component must exist
-e, --canonicalize-existing
all components of the path must exist
-m, --canonicalize-missing
no path components need exist or be a directory
-L, --logical
resolve '..' components before symlinks
-P, --physical
resolve symlinks as encountered (default)
-q, --quiet
suppress most error messages
--relative-to=DIR
print the resolved path relative to DIR
--relative-base=DIR
print absolute paths unless paths below DIR
-s, --strip, --no-symlinks
don't expand symlinks
-z, --zero
end each output line with NUL, not newline
--help display this help and exit
--version
output version information and exit