What is the difference between include_directories and target_include_directories in CMake?

前端 未结 3 597
陌清茗
陌清茗 2020-12-07 08:48

I have a directory structure for my C++ code which goes like this :

|
|->include
|->src

I am writing a CMakeLists.txt file for my co

3条回答
  •  难免孤独
    2020-12-07 09:08

    Beside what Angew's answer correctly says, another very important difference between include_directories and target_include_directories is that, when used with PUBLIC or INTERFACE, the latter populate the INTERFACE_INCLUDE_DIRECTORIES property of the target. This property is useful when another target uses target_link_libraries to link to the original target, as the linking target will have automatically those include directories added. See example.

    This important feature is pretty well hidden in the documentation: target_include_directories mention populating INTERFACE_INCLUDE_DIRECTORIES, whose documentation says:

    When target dependencies are specified using target_link_libraries(), CMake will read this property from all target dependencies to determine the build properties of the consumer.

提交回复
热议问题