Swig -includeall 除了...
Swig -includeall except...
我有一个大型项目,其中使用 Swig -includeall 标志似乎很有意义。但是,有些文件我不想扩展,主要是 STL 库(例如矢量和列表)。是否可以使用 -includeall 标志,但将某些文件列入黑名单以防止扩展(如向量和列表)?
我不是 SWIG 方面的专家,但同时查看了 documentation for latest version 和源代码(特别是 Source/Modules/main.cxx
文件,其中读取了命令行参数),是否清楚这样的选项不存在(甚至不是隐藏的)。
另一方面,如果您觉得可以很容易地修改源代码。
您可以在 main.cxx
文件中添加一个新的命令行选项来添加要排除的文件名,然后比较这些名称以找到匹配项。您可以在 Source/Preprocessor/preprocessor.h
文件中添加全局函数,该文件已包含在 main.cxx
.
中
-includeall
选项的代码在 Source/Preprocessor/cpp.c
中。在该文件中还有一个名为 include_all
的全局变量,当在命令行中设置模拟参数时,它被设置为 1
(它会引导您找到执行此类选项的位置)。
现在,在 Preprocessor_parse(...)
函数中,您可以找到解析 header 文件的位置(从 3.0.12 版本的第 1715 行开始):
s1 = cpp_include(fn, sysfile);
if (s1) {
/* ....... */
}
您会对 String *Swig_last_file(void)
函数感兴趣,它将 return 刚刚解析的 header 行的文件名。
s1 = cpp_include(fn, sysfile);
if (s1) {
int found = 0;
String* filename = Swig_last_file();
/* Here find for a match in the exclusion list */
if (!found) { /* keep working as usual */
/* ....... */
} /* if found, just ignore the include directive for that file */
Delete(s1);
}
我知道这不是一个完整的解决方案,但希望可以指导您获得所需的行为。
来自Docs about the SWIG Preprocessor:
SWIG fully supports the use of #if, #ifdef, #ifndef, #else, #endif to conditionally include parts of an interface. The following symbols are predefined by SWIG when it is parsing the interface:
SWIG - Always defined when SWIG is processing a file
所以你可以这样写:
#ifndef SWIG
#include <string>
#include <vector>
#endif // !SWIG
并且 SWIG 将在 -includeall 传递期间忽略它。
我有一个大型项目,其中使用 Swig -includeall 标志似乎很有意义。但是,有些文件我不想扩展,主要是 STL 库(例如矢量和列表)。是否可以使用 -includeall 标志,但将某些文件列入黑名单以防止扩展(如向量和列表)?
我不是 SWIG 方面的专家,但同时查看了 documentation for latest version 和源代码(特别是 Source/Modules/main.cxx
文件,其中读取了命令行参数),是否清楚这样的选项不存在(甚至不是隐藏的)。
另一方面,如果您觉得可以很容易地修改源代码。
您可以在 main.cxx
文件中添加一个新的命令行选项来添加要排除的文件名,然后比较这些名称以找到匹配项。您可以在 Source/Preprocessor/preprocessor.h
文件中添加全局函数,该文件已包含在 main.cxx
.
-includeall
选项的代码在 Source/Preprocessor/cpp.c
中。在该文件中还有一个名为 include_all
的全局变量,当在命令行中设置模拟参数时,它被设置为 1
(它会引导您找到执行此类选项的位置)。
现在,在 Preprocessor_parse(...)
函数中,您可以找到解析 header 文件的位置(从 3.0.12 版本的第 1715 行开始):
s1 = cpp_include(fn, sysfile);
if (s1) {
/* ....... */
}
您会对 String *Swig_last_file(void)
函数感兴趣,它将 return 刚刚解析的 header 行的文件名。
s1 = cpp_include(fn, sysfile);
if (s1) {
int found = 0;
String* filename = Swig_last_file();
/* Here find for a match in the exclusion list */
if (!found) { /* keep working as usual */
/* ....... */
} /* if found, just ignore the include directive for that file */
Delete(s1);
}
我知道这不是一个完整的解决方案,但希望可以指导您获得所需的行为。
来自Docs about the SWIG Preprocessor:
SWIG fully supports the use of #if, #ifdef, #ifndef, #else, #endif to conditionally include parts of an interface. The following symbols are predefined by SWIG when it is parsing the interface:
SWIG - Always defined when SWIG is processing a file
所以你可以这样写:
#ifndef SWIG
#include <string>
#include <vector>
#endif // !SWIG
并且 SWIG 将在 -includeall 传递期间忽略它。