Appending to CMAKE_C_FLAGS

为君一笑 提交于 2019-12-05 01:03:46

Try to do this instead:

if(SINGLE_MODE)
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lglapi")
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lglapi")
endif(SINGLE_MODE)

Then, you are sure you append -lglapi to the existing ${CMAKE_CXX_FLAGS} string. Else, looks like something like a CMake list is being created.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!