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