Fix '/Zc:__cplusplus' leaking into GNU-based compilers on Windows#787
Fix '/Zc:__cplusplus' leaking into GNU-based compilers on Windows#787axxel merged 2 commits intozxing-cpp:masterfrom bindreams:msvc-public-flag-guard
Conversation
|
You mean the generator expression ends up in |
|
Yes, exactly. |
|
From an idealist point of view, a better solution would be to move the code affected by the flag into a cpp file, and make the flag private. Then the issue would go away altogether. Current approach works only because MSVC does not provide a GNU-style frontend (yet), and Clang's MSVC-style frontend does not need this flag. CMake also has CMAKE_CXX_COMPILER_FRONTEND_VARIANT which is very useful with these kinds of issues, but the variable is not supported in generator expressions. |
|
Thanks for the effort and insight. Removing the public dependency on |
The change in #612 has introduced a bug when the library is used as a dependency on Windows with the Clang compiler.
For example, when zxing is installed via vcpkg, it is automatically compiled using MSVC and all is well. However, when a user (me) attempts to build a dependent program using a MSVC-compatible compiler with a GNU frontend, such as Clang (not mingw-based clang, the official one), the program fails to compile. This happens because zxing exports
/Zc:__cpluspluspublicly, even though the compiler might not support it. Example compilation error on a dependent project:I was able to fix this by using a generator expression around the flag. This change propagates to
ZXingTargets.cmakeand patching vcpkg to use my fork also seems to fix the issue.