I would like to use a global set of flags for compiling a project, meaning that at my top-level CMakeLists.txt file I have specified:
ADD_DEFINITIONS ( -Wall
Using @Fraser answer, I created the following to handle the Qt includes because the variable includes multiple paths separated by semicolons. This means I had to first add a foreach()
loop and create the include flags by hand. But that allows me to have one exception: foo.cpp (that one file uses Qt for now but long term I want to remove that dependency and I want to make sure not Qt creeps in anywhere else).
find_package(Qt5Core REQUIRED)
set(QT_INCLUDE_PROPERTIES "")
foreach(DIR ${Qt5Core_INCLUDE_DIRS})
set(QT_INCLUDE_PROPERTIES "${QT_INCLUDE_PROPERTIES} -isystem ${DIR}")
endforeach()
set_source_files_properties(foo.cpp PROPERTIES
COMPILE_FLAGS
${QT_INCLUDE_PROPERTIES}
)
Notice also that I use the -isystem
instead of -I
to avoid some warnings that Qt headers otherwise generate (I have a ton of warnings turned on).