I use an external package in cmake, that uses INTERFACE_SOURCES. This means when I link the imported library to my target, the interface source files are automatically added to my target. When I compile my target, those external files are compiled too.
This causes a problem for me, because the external files cause compile warnings. I want to remove the warnings by setting a lower warning level when compiling the external files. But I do not know how to do this.
This is what I got so far.
# reduce the warning level for some files over which we have no control.
macro( remove_warning_flags_for_some_external_files myTarget )
# blacklist of files that throw warnings
set( blackListedExternalFiles
static_qt_plugins.cpp
)
get_target_property( linkedLibraries ${myTarget} LINK_LIBRARIES )
foreach(library ${linkedLibraries})
get_property( sources TARGET ${library} PROPERTY INTERFACE_SOURCES )
foreach(source ${sources})
get_filename_component(shortName ${source} NAME)
if( ${shortName} IN_LIST blackListedExternalFiles)
# everything works until here
# does not work
get_source_file_property( flags1 ${source} COMPILE_FLAGS)
# does not work
get_property(flags2 SOURCE ${source} PROPERTY COMPILE_FLAGS)
# exchange flags in list, this I can do
# set flags to source file, do not know how to
endif()
endforeach()
endforeach()
endmacro()
This is what this should do
- Go through all linked libraries and get the external INTERFACE_SOURCES source files.
- Check for each external source file if it appears in the black-list. If so, change its compile flags to a lower level.
The problem I have is with getting and setting the compile flags for those INTERFACE_SOURCES. The get_source_file_property() and get_property() calls return nothing.
How can I get and set the flags for these files that seem to not belong to my target, but are compiled at the same time?