[cairo] cairomm: Visual Studio WIN32 define clash with Surface::Type::WIN32

Francesco Pretto ceztko at gmail.com
Wed Jan 6 10:05:24 UTC 2021


I'm experiencing a clash between the very commonly defined macro WIN32 and
the Surface::Type::WIN32 enum identifier. Basically WIN32 is default
defined in all Visual Studio IDE projects (.vcxproj projects), and there's
not much to do about it: a regular Visual Studio project trying to use
cairomm will fail building because of expansion of the Surface::Type::WIN32
identifier to 1. I elaborate a bit more about default defined macros in
Windows/Visual Studio world:
1) MSVC **compiler** (not msbuild project build configuration)
intrinsically defines _WIN32. This is officially documented in this page
2) Historically all Visual Studio versions also default defines WIN32 macro
for IDE built projects. I can't find official statements about it but there
are many mentions about this[2] and it can be easily tested by creating a
command line project and specifically checking against the WIN32 define.
Also very relevant: CMake generated projects also define WIN32, and you can
test it easily or read the words of the project maintainer Brad King[3].
Much software will break if WIN32 is not defined, in my experience much
more than 50% of software either using WIN32 or _WIN32.

Because of the reasons in 2) the choice for cairomm of naming an identifier
WIN32 was unlucky and unfortunate, and if you want to the library to be
usable in commonly run Visual Studio environments there's not much choice
other than breaking the API and rename the Surface::Type::WIN32 identifier
to something else. My suggestion is renaming:
-  Surface::Type::WIN32 ->  Surface::Type::WIN32GDI;
- For sake of consistency also WIN32_PRINTING could be renamed
to WIN32GDI_PRINTING, but this is optional.

I guess the amount of users that would break with this change is very low.
Also it would be a non breaking ABI change. I'm not the right person to
talk about this, though.

Attached the patch that does rename. It can also be used as a temporary fix
for users that want to use cairomm in a VS built project.


[2] https://stackoverflow.com/a/662543/213871
[3] https://cmake.org/Bug/view.php?id=14827#c35569
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20210106/2de84589/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: WIN32-WIN32GDI.patch
Type: application/octet-stream
Size: 634 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20210106/2de84589/attachment-0001.obj>

More information about the cairo mailing list