add_compile_options.rst 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. add_compile_options
  2. -------------------
  3. Add options to the compilation of source files.
  4. .. code-block:: cmake
  5. add_compile_options(<option> ...)
  6. Adds options to the :prop_dir:`COMPILE_OPTIONS` directory property.
  7. These options are used when compiling targets from the current
  8. directory and below.
  9. Arguments
  10. ^^^^^^^^^
  11. .. |command_name| replace:: ``add_compile_options``
  12. .. include:: GENEX_NOTE.txt
  13. .. include:: OPTIONS_SHELL.txt
  14. Example
  15. ^^^^^^^
  16. Since different compilers support different options, a typical use of
  17. this command is in a compiler-specific conditional clause:
  18. .. code-block:: cmake
  19. if (MSVC)
  20. # warning level 4 and all warnings as errors
  21. add_compile_options(/W4 /WX)
  22. else()
  23. # lots of warnings and all warnings as errors
  24. add_compile_options(-Wall -Wextra -pedantic -Werror)
  25. endif()
  26. See Also
  27. ^^^^^^^^
  28. * This command can be used to add any options. However, for
  29. adding preprocessor definitions and include directories it is recommended
  30. to use the more specific commands :command:`add_compile_definitions`
  31. and :command:`include_directories`.
  32. * The command :command:`target_compile_options` adds target-specific options.
  33. * The source file property :prop_sf:`COMPILE_OPTIONS` adds options to one
  34. source file.