sip: Conditionally wrapping a virtual method?
Phil Thompson
phil at riverbankcomputing.com
Thu Apr 2 16:43:39 BST 2026
On 02/04/2026 16:21, Scott Talbert wrote:
> Hi,
>
> I'm trying to wrap a C++ class in wxPython that has a virtual method
> that is conditionally defined. Very simplified, it looks like this:
>
> class wxWindow
> {
> public:
> ...other methods...
> #if wxUSE_ACCESSIBILITY
> virtual wxAccessible* CreateAccessible() { return nullptr; }
> #endif
> }
>
> It seems like the sip way of doing this would be to use a feature flag
> and guard this method with %If in the .sip file. However, wxPython's
> build process pre-generates all the .cpp code as part of the sdist
> build process, so the generated .cpp code is used on all platforms,
> where wxUSE_ACCESSIBILITY is both defined and not.
>
> Is there any way to solve this with sip using a cpp compile time flag?
> If I include the method unconditionally the .sip file, it fails to
> compile on platforms where wxUSE_ACCESSIBILITY is not defined because
> the method is flagged with SIP_OVERRIDE and it doesn't override
> anything on those platforms.
The design of sip assumes the .sip files are distributed and the .cpp
files are just build artifacts. The .sip files are part of an
installation and allow 3rd party packages to extend them by %Importing
them.
A feature results in a corresponding SIP_FEATURE_* macro to be defined
so you could try overriding it on the compiler command line.
You could also try overriding the definition of SIP_OVERRIDE on the
command line.
Phil
More information about the PyQt
mailing list