小编tar*_*aki的帖子

有没有办法让CMake利用`swig -MM`生成的依赖?

SWIG使用接口(.i)文件以所需的目标语言(Python,Java,C#等)从C/C++生成包装器代码,该文件指定要包装的输入代码,如SWIG教程中所述.CMake可用于调用swig以便从.i接口生成目标代码,如SWIG文档中所述.

但是,使用此方法时,CMake只会为接口文件本身生成依赖关系,但不会为其包含的源文件生成依赖关系.可以手动添加依赖项,但SWIG可以使用-MM选项自动生成依赖项,我希望CMake可以使用这些依赖项.

有一个提交CMake使用了生成的依赖项,swig -MM但由于生成的源在swig调用时不存在的问题,后来又被恢复了.此时问题似乎仍未得到解决.

因此,我将问题提交给了出色的StackOverflow社区:当前的CMake是否有办法利用swig -MM当接口文件(a)不包含生成的代码(例如config.h)时生成的依赖关系,以及(b)包含生成的代码?

这是一个可以用于实验的小例子(在这里下载).

// swig_example.h
int foo(int n);
//*** comment this declaration after compiling once to witness dependency failure ***/
int another_function();
Run Code Online (Sandbox Code Playgroud)
// swig_example.cpp
#include "swig_example.h"
int another_function() {return -1;}
int foo(int n) 
{
    if (n <= 1) return 1;
    else return another_function();
}
Run Code Online (Sandbox Code Playgroud)
// swig_example: example.i
%module example
%{
#include "swig_example.h"
%}
%include "swig_example.h"
Run Code Online (Sandbox Code Playgroud)
# swig_example: …
Run Code Online (Sandbox Code Playgroud)

c++ python dependencies swig cmake

10
推荐指数
1
解决办法
1403
查看次数

标签 统计

c++ ×1

cmake ×1

dependencies ×1

python ×1

swig ×1