1add_compile_options 2------------------- 3 4Add options to the compilation of source files. 5 6.. code-block:: cmake 7 8 add_compile_options(<option> ...) 9 10Adds options to the :prop_dir:`COMPILE_OPTIONS` directory property. 11These options are used when compiling targets from the current 12directory and below. 13 14Arguments 15^^^^^^^^^ 16 17Arguments to ``add_compile_options`` may use "generator expressions" with 18the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)` 19manual for available expressions. See the :manual:`cmake-buildsystem(7)` 20manual for more on defining buildsystem properties. 21 22.. include:: OPTIONS_SHELL.txt 23 24Example 25^^^^^^^ 26 27Since different compilers support different options, a typical use of 28this command is in a compiler-specific conditional clause: 29 30.. code-block:: cmake 31 32 if (MSVC) 33 # warning level 4 and all warnings as errors 34 add_compile_options(/W4 /WX) 35 else() 36 # lots of warnings and all warnings as errors 37 add_compile_options(-Wall -Wextra -pedantic -Werror) 38 endif() 39 40See Also 41^^^^^^^^ 42 43This command can be used to add any options. However, for 44adding preprocessor definitions and include directories it is recommended 45to use the more specific commands :command:`add_compile_definitions` 46and :command:`include_directories`. 47 48The command :command:`target_compile_options` adds target-specific options. 49 50The source file property :prop_sf:`COMPILE_OPTIONS` adds options to one 51source file. 52