Override compile flags for single files

后端 未结 3 563
说谎
说谎 2020-11-28 03:51

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         


        
3条回答
  •  醉梦人生
    2020-11-28 04:19

    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).

提交回复
热议问题