[cmake-developers] Compile flags depending on source file property
Simon.Richter at hogyros.de
Fri Aug 3 19:12:22 EDT 2018
I'd like to compile different source files with slightly different
flags, calculating the flags dependent on source file properties.
The easiest example would be different warning flags for all generated
sources, as I have little influence over this code.
The only way I can think of doing this would be to remove the global
warning flag definitions from the toplevel CMakeLists.txt, and instead
have that define two different variables for the positive and negative
forms of a particular warning flag, dependent on compiler, and then
define the flag explicitly as source properties in each directory:
if(GCC or CLANG)
# determine if it actually supports -Wshadow ...
and later on
set(TARGET1_NON_GENERATED_FILES ... )
All of this is rather ugly, and escalates even more as there are more
different classes of source files.
What I'd like to see is something like a generator expression that is
evaluated once per source file, that would allow me to have a global
Since there is already a mechanism to carry the per-source COMPILE_FLAGS
property into the compile flags for the source file, I wonder if that
could be extended to a generic mechanism to derive source specific
compile flags from source properties?
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 488 bytes
Desc: OpenPGP digital signature
More information about the cmake-developers