用 scons 检查宏定义?

Checking macro definition with scons?

我正在使用 Conftest.CheckHeader 检查是否存在 VTK。 具体来说,我检查是否找到了 <vtkVersion.h>。现在我想看看 VTK 的实际版本是什么,这可以通过检查 VTK_MAJOR_VERSIONVTK_MINOR_VERSION 来完成。在 SCons 中有没有一种干净的方法可以做到这一点,例如以某种方式 returning 预处理源,它只包含 VTK_MAJOR_VERSION VTK_MINOR_VERSION 和 return 6 0?

你可以试试(来自scons manpage

CheckContext.TryRun(self, text, extension)

Checks, if a file with the specified extension (e.g. '.c') containing text can be compiled using the environment's Program builder. On success, the program is run. If the program executes successfully (that is, its return status is 0), a tuple (1, outputStr) is returned, where outputStr is the standard output of the program. If the program fails execution (its return status is non-zero), then (0, '') is returned.