Appending to CMAKE_C_FLAGS

后端 未结 3 1910
谎友^
谎友^ 2021-02-18 22:22

I\'m using CMake for a project that comes in two versions, one of which requires -lglapi and the other does not.

So far the lines we used look like that:



        
3条回答
  •  余生分开走
    2021-02-18 22:35

    Since CMake 3.4 you do:

    string(APPEND CMAKE_CXX_FLAGS " -lglapi")
    

    This very handy when you want to set the flags only for one language (C++ in the example above), but if you want to set the same flags for all languages, you can simply do:

    add_compile_options(-lglapi)
    

    Both commands change the flags for the whole directory, if you want to set the flags for only one target, do:

    target_compile_options(my_lib PUBLIC -lglapi)
    

    Flags on a target can either be PUBLIC, PRIVATE or INTERFACE, allowing to transitively forward the flags from one target to the other.

提交回复
热议问题