[CMake] How to ignore Juce warnings (only)?

Hi all,

I’ve got a project that works very fine using CMake. However, I lately concentrated on code quality, and set the warning flags as high as possible. I also consider warnings as errors. However, with GCC, JUCE raises some warnings that prevent the compilation from working.

Here is how I declare my warnings on the top CMakeLists.txt:

set(WARNING_FLAGS
            -Wall -Wextra -pedantic -pedantic-errors
            -Werror -Wsign-conversion -Wcast-align
    #JUCE doesn't like the following line!
            -Wconversion -Wnoexcept -Wundef -Wold-style-cast -Wcast-qual -Wlogical-op
            -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2
            -Winit-self -Wmissing-include-dirs -Woverloaded-virtual
            -Wredundant-decls -Wshadow -Wstrict-null-sentinel -Wstrict-overflow=5
            -Wno-unused -Wno-variadic-macros -Wno-parentheses -fdiagnostics-show-option
            )
set(NO_WARNING_FLAGS -w)

And then declare what projects need what warnings:

target_compile_options(MainSoftware PRIVATE ${WARNING_FLAGS})
target_compile_options(TestUnits PRIVATE ${WARNING_FLAGS})
target_compile_options(ThirdParty PRIVATE ${NO_WARNING_FLAGS})

My “third party” project uses lax compilation flags. My question is, how can I do that with Juce?

I tried “wrapping” Juce in its own project and link it to my “main software” and “test units” projects, but it didn’t work, since they use Juce macro (juce_add_gui_app, etc.), which already declare Juce.

Thanks!

This can be a bit difficult to do from outside the dependency (ie, from your cmake code and not inside the JUCE project), but the general way to do this would be:

  • Use target-specific warning flags to set them for only your targets, so that the JUCE .cpp files won’t generate any warnings
  • Specify the JUCE include directories as SYSTEM, so that those headers won’t generate any warnings

The way you’re specifying your warning flags is a bit concerning. You are hard-coding these flags that may only be valid for GCC or Clang; your CMake configuration will fail on MSVC. The way to specify different flags for different compilers is through generator expressions – as an example, here’s how I set up my default warning flags.

Thanks for your reply.

The way you’re specifying your warning flags is a bit concerning. You are hard-coding these flags that may only be valid for GCC or Clang; your CMake configuration will fail on MSVC.

Oh don’t worry, I only showed the GCC flags for simplicity’s sake. But thanks for your example.

This can be a bit difficult to do from outside the dependency (ie, from your cmake code and not inside the JUCE project)

Mmmh, I don’t understand that part. Is there any other way to do what I want? If I try to put the target_compile_options inside my projects (TestUnits, MainSoftware), they are ignored, so I thought declaring them at the top CMakeList was the only way to go.

1 Like