1

With cmake one can pass compiler options with CMAKE_CXX_FLAGS and CMAKE_CXX_LINK_FLAGS to the linker.

But as far as I can see CMAKE_CXX_FLAGS are passed to the linker as well.

Is there a way to pass options to the compiler but not to the linker?

alfC
  • 14,261
  • 4
  • 67
  • 118
  • Does this answer your question? [How do I add a linker or compile flag in a CMake file?](https://stackoverflow.com/questions/11783932/how-do-i-add-a-linker-or-compile-flag-in-a-cmake-file). This [specific response](https://stackoverflow.com/a/28773403/3987854) shows how you *should* be passing compile/link options using CMake (i.e. not using `CMAKE_*_FLAGS`, as this is antiquated and discouraged). – Kevin Nov 10 '20 at 18:53

1 Answers1

0

Use target_compile_options to add compiler options to a specific target

https://cmake.org/cmake/help/latest/command/target_compile_options.html

Use target_link_options to add linker options to a specific target

https://cmake.org/cmake/help/latest/command/target_link_options.html

Modern cmake projects should avoid using CMAKE_CXX_FLAGS/CMAKE_CXX_LINK_FLAGS unless you really know what you are doing.