Compiler warning flags for all except ExternalProjects

I have an old cmake project and want to apply compiler warning flags for all targets except externals built with ExternalProject_Add. Is there any easy way to retro fit this?

Can’t say for sure, but what I would try:

  1. Check whether flags set via add_compile_options are applied to your targets added via ExternalProject_Add as well; if not → GOOD!
  2. Otherwise, do you have a list of all your “internal” targets? then you could loop over them and use target_compile_options to add the warning flags.
  3. If it’s easier to get a list of all external projects, you could “subtract” that from the list of targets available via BUILDSYSTEM_TARGETS (you’d probably have to do this recursively for subdirectories, see also this thread), then use this list to do option 2.

You can make a target that carries the flags and you link to from each of your targets (either manually or via something like looping over BUILDSYSTEM_TARGETS):

1 Like

I like the approach of having an interface target. My problem then becomes trying to figure out what syntax for target_link_libraries to use.

target_link_libraries(mytgt PRIVATE buildflags) 

or

target_link_libraries(mytgt buildflags) 

Apperently it is not possible to mix syntax for target_link_libraries.

Use PRIVATE.