Lets say I want to compile all the code with /W4
for a project with three libs/target
s.
A -> B -> C
What is the best practice to apply the flag project-wide?
I can think of two approaches:
Set
TARGET_COMPILE_OPTIONS(C PUBLIC "\W4")
inC
's CMake (which is a core library for the whole project) and every other library that depends onC
will inherit the flag via:TARGET_LINK_LIBRARIES(B C)
Pro: new libraries will inherit the flag automatically.
Con: compile flags for a project are implicit.Specify compile options for every target/lib separately.
Pro: the flags are explicitly specified and manageable separately for each lib.
Con: the flags need to be (not forgotten to be) set for a new lib.