About compilation flags with CMAKE

New to CMAKE i need an enlightenment. :woozy_face:

target_link_libraries(AppExample
PRIVATE
juce::juce_core
my::module
PUBLIC
juce::juce_recommended_config_flags
juce::juce_recommended_warning_flags)

  1. Is that linking with PUBLIC juce::juce_recommended_config_flags target implies that sibling PRIVATE JUCE modules use those flags at compilation?
  2. Is the flags are applied also for my::module (added with juce_add_module)?

Thanks.

This one isn’t a simple yes/no answer because JUCE modules are “interface libraries”. Let me first provide an example with a “normal” library:

add_library (foo STATIC)

add_executable (bar main.cpp)

target_compile_options (bar PRIVATE -ffoo -wbar)

target_link_libraries (bar PRIVATE foo)

In the above example, only the bar executable’s source files (ie main.cpp) will be compiled with the -ffoo -wbar flags, the compilation of static/shared libraries that the executable links will not be affected by those flags.

However, the way interface libraries work is that their source files are basically added to your target as if they belong to your target. The canonical use case is header-only libraries, but it’s legal to have cpp files in interface libraries too, which is what JUCE modules do. So the module source files are compiled as part of your target, meaning they inherit any flags your target has set on it.

To answer your specific questions, the sources for all juce modules added to AppExample will be compiled using the juce_recommended_config_flags and juce_recommended_warning_flags.

1 Like

Ok, so my assumption was (of course) wrong (anyway it would have been weird to have dependencies with sibling stuff). I thought that modules were built first then linked (and I couldn’t find any compilations options in JUCE’s .cmake machinery). I understand now! :laughing:

Thanks!

1 Like