add_compile_options.rst 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. Arguments to ``add_compile_options`` may use "generator expressions" with
  12. the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
  13. manual for available expressions. See the :manual:`cmake-buildsystem(7)`
  14. manual for more on defining buildsystem properties.
  15. .. include:: OPTIONS_SHELL.txt
  16. Example
  17. ^^^^^^^
  18. Since different compilers support different options, a typical use of
  19. this command is in a compiler-specific conditional clause:
  20. .. code-block:: cmake
  21. if (MSVC)
  22. # warning level 4 and all warnings as errors
  23. add_compile_options(/W4 /WX)
  24. else()
  25. # lots of warnings and all warnings as errors
  26. add_compile_options(-Wall -Wextra -pedantic -Werror)
  27. endif()
  28. See Also
  29. ^^^^^^^^
  30. This command can be used to add any options. However, for
  31. adding preprocessor definitions and include directories it is recommended
  32. to use the more specific commands :command:`add_compile_definitions`
  33. and :command:`include_directories`.
  34. The command :command:`target_compile_options` adds target-specific options.