Search code examples
cmakescopedependenciesinclude

What is the default privacy/scope setting for include_directories?


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?


Solution

  • Is using include_directories() essentially the same as using target_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 current CMakeLists file. They are also added to the INCLUDE_DIRECTORIES target property for each target in the current CMakeLists 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 and PUBLIC items will populate the INCLUDE_DIRECTORIES property of <target>. PUBLIC and INTERFACE items will populate the INTERFACE_INCLUDE_DIRECTORIES property of <target>.