Add Extra Compiler Flags in CMake workflow


I just started working with CMake (was previously using Projucer) and I’m struggling to find out how to add extra compiler/linker options.

In Producer you could click on an exporter and there were edit boxes to add ‘Extra Compiler Flags’ and ‘Extra Linker Flags’

I’ve tried adding target_compile_options(Gain PRIVATE -fPIC) but I’m still getting linker errors saying I need to ‘recompile with -fPIC’

Full error message:
[build] /usr/bin/ld: images/libGainBinaryData.a(BinaryData1.cpp.o): relocation R_X86_64_PC32 against symbol `_ZN10BinaryData14background_pngE’ can not be used when making a shared object; recompile with -fPIC

This VST3/Standalone project was compiling without any issues before I tried to add a background image to my project. I’m not sure what difference that makes though.

Any help will be much appreciated.

Rather than dealing directly with compiler flags, it’s more idiomatic to set the POSITION_INDEPENDENT_CODE property on each target that requires it:

set_target_properties(myplugin PROPERTIES POSITION_INDEPENDENT_CODE ON)

Note that the plugin wrappers, shared code target, and binary data targets will all require this property to be set.

Thanks reuk, that worked perfectly.