Search code examples
c++includec-preprocessorswift-package-managerswift-package

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


I have a set of C++ packages resolved with the Swift Package Manager and another Package Manager (let's call it PMX).

PMX cannot resolve one of the dependencies, but I have to run CI on it. Is it possible to somehow check that the package is being compiled with the SPM system and include the appropriate imports and if it's not using SPM, then just not include those headers?

Example:

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

I'd like to have something similar to this:

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

Is something like this possible?


Solution

  • Found a solution, this flag exists and it's called SWIFT_PACKAGE

    This solution has worked perfectly for me:

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

    Blog post mentioning the issue