C++ 检查包是否已通过 Swift 包管理器安装并包含一个文件

C++ Check if the package has been installed via Swift Package Manager and include a file

我有一组使用 Swift 包管理器和另一个包管理器(我们称之为 PMX)解析的 C++ 包。

PMX 无法解析其中一个依赖项,但我必须 运行 CI 解决它。是否有可能以某种方式检查包是否正在使用 SPM 系统编译并包含适当的导入,如果它不使用 SPM,则不包含那些 headers?

示例:

#if defined(_WIN32) || defined(_WIN64) || defined(__APPLE__)
#include <MyFile.h>
#endif

我想要类似这样的东西:

#if defined(_WIN32) || defined(_WIN64) || (defined(__APPLE__) && defined(SWIFT_PACKAGE_MANAGER))
#include <MyFile.h>
#endif

这样的事情可能吗?

找到解决方案,这个标志存在,它被称为SWIFT_PACKAGE

这个解决方案非常适合我:

#if defined(_WIN32) || defined(_WIN64) || (defined(__APPLE__) && defined(SWIFT_PACKAGE))
#include <MyFile.h>
#endif

Blog post mentioning the issue