MSVC: Unable to build OpenSubdiv with ninja
LazyDodo opened this issue · comments
When building OSD 3.5.0 (likely earlier versions too given how long this setup has been there) with the visual studio generator in CMake, OSD builds flawlessly. However when you switch to the ninja generator it fails with the following error
[1/76] Building CXX object glLoader\CMakeFiles\glLoader_obj.dir\glLoader.cpp.obj
FAILED: glLoader/CMakeFiles/glLoader_obj.dir/glLoader.cpp.obj
C:\....\glLoader\glLoader.cpp(62) : error C2220: the following warning is treated as an error
C:\....\glLoader\glLoader.cpp(62) : warning C4702: unreachable code
(edited for verbosity)
Which begs the question, why doesn't building with Visual studio generator give this warning? well... turns out, CMake maps CLI options to xml options for in the VS project files, if one were to specify both /Wall
and /W3
like OSD does the last one wins as this is a single field in the VS project files, and OSD will build effectively with /W3
and with C4702 being a W4 warning, it does not get emitted and the build succeeds.
The Ninja generator however doesn't have to map anything to anything, it takes all the compiler flags and feeds them directly to the compiler, MSVC has a different take on things here when being fed both /Wall
and /W3
and goes "The most verbose option wins!" and effectively builds with /Wall
, C4702 does get emitted and because OSD builds with warnings as errors (/Wx
) the build fails.
Easy fix would be removing the /Wall
flag, as OSD has been silently building with /W3
for years now, if one would actually want to build on /Wall
one could remove the /w3
but a heads up there, building with /Wall
emits ~7200 warnings currently (~2400 unique ones) the C4702 warn above was just the first one it ran into., so that may be more than you're willing to chew off right now.
#1283 does not address the root cause (W3
for msbuild vs Wall
for ninja) . It's probably best to decide first what the preferred warning level (ie W3
or Wall
) is to get the 2 build systems in line, and only then see if you need to suppress (or fix) any additional warnings.
Filed as internal issue #OSD-396
The #1282 change suppresses all MSVC 2022 warnings except for:
warning C4702: unreachable code
- far\patchBuilder.cpp(1108)
- glLoader\glLoader.cpp(62)
warning C4191: type cast: unsafe conversion from 'FARPROC' to 'OpenSubdiv::internal::GLApi::PFNGETPROCADDRESS'
- glLoader\glApi.cpp(3148)
warning C5219: implicit conversion from 'int' to 'float', possible loss of data
- hbr\catmark.h(331)
- hbr\catmark.h(334)
- hbr\catmark.h(342)
- hbr\catmark.h(376)
- hbr\catmark.h(400)
I couldn't see an existing PR to address these (no result for unreachable
in search etc. I will look into these soon if I cannot see an existing PR.
Thanks all for the additional information. For tracking purposes marking this as Duplicate of #1269