如何在不全局添加目录的情况下将包含目录添加到 swig cmake 目标?

How to add include directories to a swig cmake target without adding them globally?

如何在 cmake 中为 swig 目标指定 include_directories?我看到你要添加一个 swig 目标:

swig_add_library(swg_target
        TYPE STATIC
        LANGUAGE python
        SOURCES swg_src_files.i swg_src_files.h swg_src_files.cpp
)

但接下来是通常的

target_include_directories(swg_target PUBLIC ".../include")

不起作用(即似乎什么都不做),我需要把

include_directories(".../include")

调用 swig_add_library 之前。有没有一种方法可以将包含目录添加到 swig 目标,而无需为每个目标全局添加这些目录?

在幕后,swig_add_library 最终必须调用 add_library 并设置一些属性,但文档中有些奇怪的东西:

Target library properties can be set to apply same configuration to all SWIG input files.

SWIG_USE_TARGET_INCLUDE_DIRECTORIES
If set to TRUE, contents of target property INCLUDE_DIRECTORIES will be forwarded to SWIG compiler. If set to FALSE or not defined, target property INCLUDE_DIRECTORIES will be ignored. This behavior can be overridden by specifying source property USE_TARGET_INCLUDE_DIRECTORIES.

因此,为了使用target_include_directories,但您还必须在您的目标上设置上述属性。如果我正确阅读 Git 历史记录,它是在 CMake 3.13 中添加的。