cmake/Help/command/add_compile_options.rst

53 lines
1.3 KiB
ReStructuredText
Raw Normal View History

2014-08-03 19:52:23 +02:00
add_compile_options
-------------------
2019-11-11 23:01:05 +01:00
Add options to the compilation of source files.
2014-08-03 19:52:23 +02:00
2019-11-11 23:01:05 +01:00
.. code-block:: cmake
2014-08-03 19:52:23 +02:00
add_compile_options(<option> ...)
2019-11-11 23:01:05 +01:00
Adds options to the :prop_dir:`COMPILE_OPTIONS` directory property.
These options are used when compiling targets from the current
directory and below.
2015-04-27 22:25:09 +02:00
2019-11-11 23:01:05 +01:00
Arguments
^^^^^^^^^
2014-08-03 19:52:23 +02:00
2023-05-23 16:38:00 +02:00
.. |command_name| replace:: ``add_compile_options``
.. include:: GENEX_NOTE.txt
2018-08-09 18:06:22 +02:00
2018-10-28 12:09:07 +01:00
.. include:: OPTIONS_SHELL.txt
2019-11-11 23:01:05 +01:00
Example
^^^^^^^
Since different compilers support different options, a typical use of
this command is in a compiler-specific conditional clause:
.. code-block:: cmake
if (MSVC)
2023-05-23 16:38:00 +02:00
# warning level 4
add_compile_options(/W4)
2019-11-11 23:01:05 +01:00
else()
2023-05-23 16:38:00 +02:00
# additional warnings
add_compile_options(-Wall -Wextra -Wpedantic)
2019-11-11 23:01:05 +01:00
endif()
2023-05-23 16:38:00 +02:00
To set per-language options, use the :genex:`$<COMPILE_LANGUAGE>`
or :genex:`$<COMPILE_LANGUAGE:languages>` generator expressions.
2019-11-11 23:01:05 +01:00
See Also
^^^^^^^^
2023-05-23 16:38:00 +02:00
* This command can be used to add any options. However, for
adding preprocessor definitions and include directories it is recommended
to use the more specific commands :command:`add_compile_definitions`
and :command:`include_directories`.
2019-11-11 23:01:05 +01:00
2023-05-23 16:38:00 +02:00
* The command :command:`target_compile_options` adds target-specific options.
2020-08-30 11:54:41 +02:00
2023-05-23 16:38:00 +02:00
* The source file property :prop_sf:`COMPILE_OPTIONS` adds options to one
source file.