Why only for the Release configuration though? It would be much easier to turn on warning-as-error for all configurations.
You could also use some tool to parse the output of the build and detect the number of warnings. CTest does this, perhaps you could run your build using the ctest client and set up the warning failing flags that way.
The funny thing is I thought the contentious point here would be not enabling werror for all builds, that’s considered the best practice. In reality I find it cumbersome when making quick edits and getting something running but I definitely don’t want to be committing loads of warnings, they’re almost always pointing at some potential subtle bug.
The reason I asked the question here is that it feels like cmake should offer this but it doesn’t quite.
I just added the following in my mac/linux and windows specific sections which works fine:
Like Eyal suggested, you could have some option like *_LOCAL which would turn off werror just for local development. I don’t think turning it off for Debug config is really the answer, because you may also want to build the Release config locally while working on new changes.
The reason why you might want to have different settings for different configurations is quite simple:
While writing new code and experimenting with parameters, it happens very often that you comment out sections of code, but now a couple of local variables are no longer used. If warnings are always errors, then you can’t even compile to try out the experimental change until you’ve commented out the unused variables as well.
This also applies to class members, so having to change a header file could increase compile time exponentially.
It’s much more convenient to say “in debug mode, anything goes, in release mode, compile only if everything is 100% correct”.
This discussion reminds me very much of StackOverflow, where instead of offering a solution, often people argue “don’t do that”. Not very helpful IMO.
I still think the best answer is to not handle “fail the build if there are warnings” in the compiler.
For one, you should be running your tests in both debug & release while developing locally, I think it’s shortsighted to completely ignore the release configuration while making local changes.
Second, although this is possible to implement in CMake, as discussed in this thread, it’s still compiler-specific. I personally think the best solution is to run some tool/script in CI after the build to analyze the logs and detect the number of warnings.
Again: instead of helping, we get “don’t do that”. I want to also compile locally, on my machine, in the IDE, and still get errors while building a release version. So I can find potential mistakes and fix them before even pushing the change to the repo.
I think people have to accept that other people have different workflows. We’ve found something that works for our small team. We want to continue doing that.
I still think enabling werror for release is the simplest way to get CI failures for our builds.
As I said, werror for debug builds would work in an ideal world but for reasons @reFX mentioned and many work, it’s just not pragmatic.
Sure, maybe analysing compiler output using other tools is one approach but again, thinking in terms of dev time resources, I’d have to set up ctest to run our tests, which I’ve not even looked in to yet.
The main reason for moving to cmake was so we can use other ides like VS Code or CLion (which are supported on platforms like Linux) and keep our existing VS/Xcode workflows. The other feature of cmake is more control over the builds, PJ just doesn’t seem to cut it anymore, at least for us.
So that’s one, self contained task with a clear deliverable. To then say, right but if you want your CI to work the same way you also need to run everything through ctest, parse the output with some other tools and report failures in a whole new way is a chunk of time we just don’t have budget for right now.
Doing what I need was 4 lines of cmake.
If someone really wants to build locally without werror, it’s easy enough to turn that off. But that’s like 1% of builds if that. I’d go as far as saying almost all development is done in debug builds (with sanitizers) unless you’re profiling, which is a specialised task and perhaps one you could disable werror for whilst performing.
That’s a large part of my job. Often the developers of some algorithms build only the debug version, but I build mainly the release version, because I want to make sure performance is good and it’s the version we actually ship, so I want to make sure that debug and release behave the same; the optimizer sometimes does strange things.
It’s a simple fact that different teams have different requirements for different reasons. There is no one-size-fits-all solution here.
reFX’s contribution to the discussion is interesting I think in that it points to the different “cultures” in the build framework communities… I mean, there is a reason that Meson got developed, and it’s because they didn’t like the excess of what CMake had become. If you work with Meson a bit you get the feeling it is a lot leaner and neater, and I am pretty sure you could do this without any issue in a simple way.
With CMake a lot of “don’t do that” got baked into how it works, which is why it might actually be the case there’s no easy way to set up what the OP is looking for.
IMO CMake took off like a rocket during the 2010s, it was definitely a lot less popular before then, but it still has the original culture of the people who worked on it baked into the core. (FWIW I feel about JUCE the same way in this respect, but in the case of JUCE I take it as a positive! the JUCE APIs have a ‘human’ quality to them that make them easier to work with than other audio frameworks that are more dry and technical)
So what I think Ben is pointing at is that if you use other logical levels (that work for multi-Config generators), you can get a similar result but definitely a much more convoluted CMakeLists.txt file (which is honestly what you see in any significantly larger CMake-based FOSS project). The complexity of CMake is baked into the nature of CMake.
Yeah maybe, I do feel with this it’s just a feature they haven’t added because maybe no one wanted it. As you say, it’s a large project so they only have limited resources (but it is FOSS and they do merge PRs).
And as I said, there is a way to do it in cmake which isn’t so bad, it’s just I thought there might be a more canonical cmake way. There isn’t so I just live with it.
I’ve not looked in to Meson but have you seen the xmake project? It looks nice and lean but I bet you run in to a lack of feature support fairly quickly (take this opinion with a pinch of salt as I’ve not looked too deeply in to it).
At a glance it seems to fit nicely between CMake and Meson in terms of extremity. It felt like Meson dev was fueled out of frustration with the complexity of CMake. For me I understood how to work with each build system once I understood the thought process of the respective primary developer (team)s.
Right now CMake is doing everything I need and I invested heavily into learning it these past few years so it will take a mountain to get me to budge (the Meson work I did was mainly in porting a WebRTC audio processing module from Meson to CMake build… working with Bazel was out of the question there).