0

In the cmake question Difference between add_compile_options and SET(CMAKE_CXX_FLAGS...) , the accepted answer compares setting CMAKE_CXX_FLAGS and using add_compile_options.

While the answer to the question lays out the differences, my question is which is best practice in a cmakefile? Are there benefits to using one over the other?

yodama
  • 659
  • 1
  • 9
  • 21
  • As you can see from the referenced answer, sometime setting `CMAKE_CXX_FLAGS` is preferred, but sometimes `add_compile_options` is better. This means that there is **no best practice** for prefer one way to another. What do you want from us? – Tsyvarev Feb 16 '19 at 20:02
  • @Tsyvarev I would like clarification on the referenced answer, since after reading through it I have somewhat of an idea of the difference, but it still isn't clear to me. If add_compile_options is more **precise**, which according to the referenced solution it scopes to only targets within the directory and subdirectories, then why not use it all the time instead of CMAKE_CXX_FLAGS? – yodama Feb 19 '19 at 16:37
  • As noted in the answer, `CMAKE_CXX_FLAGS` is regularly used for `-Wxxx` flags. Whether use it or not - is mainly up to your taste. – Tsyvarev Feb 19 '19 at 16:52
  • @Tsyvarev based on your answer then, it seems like CMAKE_CXX_FLAGS is only used because it was the original functionality, but as long as you are using a new enough version of Cmake, then `add_compile_options` is the better option, including for `-Wxxx` flags. – yodama Feb 19 '19 at 17:02
  • I wouldn't say that `add_compile_options` is **better** than `CMAKE_CXX_FLAGS`. In the referenced answer you may find a note about ordering of the flags, generated by `CMAKE_CXX_FLAGS` and `add_compile_options`. I perfectly understand your intention to have a 100% algorithm for choose between these approaches, but I fear that there is no such algorithm. – Tsyvarev Feb 19 '19 at 17:10
  • @Tsyvarev thank you for your patience in answering :) – yodama Feb 19 '19 at 18:14

0 Answers0