I understand that target_include_directories()
can be used in conjunction with PUBLIC
, INTERFACE
, or PRIVATE
to specify the scope or privacy of the directories. But a lot of antiquated code still uses include_directories()
, and I'm not sure how these directories are treated by the targets that use them.
Is using include_directories()
essentially the same as using target_include_directories(MyTarget PRIVATE ...)
? I have seen this similar question, but is there no default scoping behavior with include_directories()
either?
Is using
include_directories()
essentially the same as usingtarget_include_directories(MyTarget PRIVATE ...)
?
Yes, for every target, affected by include_directories
(that is, in the current CMakeLists.txt
and below), it has the same effect as PRIVATE
keyword in target-specific version of the command.
Documentation for include_directories
says, that the command assigns INCLUDE_DIRECTORIES
property of the targets and directories:
The include directories are added to the
INCLUDE_DIRECTORIES
directory property for the currentCMakeLists
file. They are also added to theINCLUDE_DIRECTORIES
target property for each target in the currentCMakeLists
file.
and the directory property affects on further target's ones:
This property is used to populate the
INCLUDE_DIRECTORIES
target property.
Exactly INCLUDE_DIRECTORIES
target property is affected by the PRIVATE
keyword of target_include_directories
command:
PRIVATE
andPUBLIC
items will populate theINCLUDE_DIRECTORIES
property of<target>
.PUBLIC
andINTERFACE
items will populate theINTERFACE_INCLUDE_DIRECTORIES
property of<target>
.