Different compile flags for same file in different targets

前端 未结 5 520
臣服心动
臣服心动 2020-12-18 19:08

I would like to include a .cpp-file in two different targets (becoming two VS projects after running CMake). I would like to set different COMPILE_FLAGS for these projects.<

5条回答
  •  [愿得一人]
    2020-12-18 19:43

    I solved this problem using 2 flags, one for the source-file, one for the target.

    macro(enable_on_source target src)
        set_source_files_properties(${src}
                                    PROPERTIES COMPILE_OPTIONS "-OptionModule")
        set_target_properties(${target}
                              PROPERTIES COMPILE_OPTIONS "-OptionTarget")
    endmacro()
    

    and during compilation I'm doing things only if both options are set.

    This completely independent of directory-scopes and what not.

提交回复
热议问题