gotchacppCritical
What is the difference between include_directories and target_include_directories in CMake?
Viewed 0 times
cmaketarget_include_directoriesandinclude_directoriesbetweenthedifferencewhat
Problem
I have a directory structure for my C++ code which goes like this :
I am writing a CMakeLists.txt file for my code. I want to understand the difference between
What is the difference between their usage and in order to add my include file path which one should I be using?
|
|->include
|->srcI am writing a CMakeLists.txt file for my code. I want to understand the difference between
include_directories and target_include_directories in CMake.What is the difference between their usage and in order to add my include file path which one should I be using?
Solution
include_directories(x/y) affects directory scope. All targets in this CMakeList, as well as those in all subdirectories added after the point of its call, will have the path x/y added to their include path.target_include_directories(t x/y) has target scope—it adds x/y to the include path for target t.You want the former one if all of your targets use the include directories in question. You want the latter one if the path is specific to a target, or if you want finer control of the path's visibility. The latter comes from the fact that
target_include_directories() supports the PRIVATE, PUBLIC, and INTERFACE qualifiers.Context
Stack Overflow Q#31969547, score: 281
Revisions (0)
No revisions yet.