diff --git a/Help/command/add_compile_options.rst b/Help/command/add_compile_options.rst index cd537b65be..3f7ab6c0ec 100644 --- a/Help/command/add_compile_options.rst +++ b/Help/command/add_compile_options.rst @@ -41,7 +41,8 @@ this command is in a compiler-specific conditional clause: endif() To set per-language options, use the :genex:`$` -or :genex:`$` generator expressions. +or :genex:`$ ` +generator expressions. See Also ^^^^^^^^ diff --git a/Help/command/target_compile_features.rst b/Help/command/target_compile_features.rst index 1b40948472..2d569e96c3 100644 --- a/Help/command/target_compile_features.rst +++ b/Help/command/target_compile_features.rst @@ -34,7 +34,7 @@ The named ```` must have been created by a command such as .. |more_see_also| replace:: See the :manual:`cmake-compile-features(7)` manual for information on compile features and a list of supported compilers. .. include:: include/GENEX_NOTE.rst - :start-line: 1 + :start-line: 2 See Also ^^^^^^^^ diff --git a/Help/command/target_compile_options.rst b/Help/command/target_compile_options.rst index c734c1acad..6fb86cd569 100644 --- a/Help/command/target_compile_options.rst +++ b/Help/command/target_compile_options.rst @@ -69,3 +69,6 @@ See Also * :variable:`CMAKE__FLAGS` and :variable:`CMAKE__FLAGS_` add language-wide flags passed to all invocations of the compiler. This includes invocations that drive compiling and those that drive linking. + +* The :module:`CheckCompilerFlag` module to check whether the compiler + supports a given flag. diff --git a/Help/command/target_precompile_headers.rst b/Help/command/target_precompile_headers.rst index 61bd97387e..acd83a8a8c 100644 --- a/Help/command/target_precompile_headers.rst +++ b/Help/command/target_precompile_headers.rst @@ -71,7 +71,8 @@ included by absolute path. For example: ) .. |command_name| replace:: ``target_precompile_headers`` -.. |more_see_also| replace:: The :genex:`$` generator +.. |more_see_also| replace:: The :genex:`$ + ` generator expression is particularly useful for specifying a language-specific header to precompile for only one language (e.g. ``CXX`` and not ``C``). In this case, header file names that are not explicitly in double quotes or angle @@ -79,7 +80,7 @@ included by absolute path. For example: brackets inside a generator expression, be sure to encode the closing ``>`` as :genex:`$`. For example: .. include:: include/GENEX_NOTE.rst - :start-line: 1 + :start-line: 2 .. code-block:: cmake diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst index 6dffd4a980..4bc0435440 100644 --- a/Help/manual/cmake-generator-expressions.7.rst +++ b/Help/manual/cmake-generator-expressions.7.rst @@ -1288,14 +1288,12 @@ related to most of the expressions in this sub-section. .. versionadded:: 3.3 The compile language of source files when evaluating compile options. - See :ref:`the related boolean expression - ` - ``$`` + See the related boolean expression + :genex:`$ ` for notes about the portability of this generator expression. -.. _`Boolean COMPILE_LANGUAGE Generator Expression`: - .. genex:: $ + :target: COMPILE_LANGUAGE:languages .. versionadded:: 3.3 diff --git a/Modules/CheckCCompilerFlag.cmake b/Modules/CheckCCompilerFlag.cmake index 9f7b179cb3..8cf387dea2 100644 --- a/Modules/CheckCCompilerFlag.cmake +++ b/Modules/CheckCCompilerFlag.cmake @@ -5,33 +5,51 @@ CheckCCompilerFlag ------------------ -Check once whether the C compiler supports a given flag. +This module provides a command to check whether the C compiler supports a +given flag. + +Load this module in a CMake project with: + +.. code-block:: cmake + + include(CheckCCompilerFlag) + +Commands +^^^^^^^^ + +This module provides the following command: .. command:: check_c_compiler_flag + Checks once whether the C compiler supports a given flag: + .. code-block:: cmake - check_c_compiler_flag( ) + check_c_compiler_flag( ) -Check once that the ```` is accepted by the compiler without a diagnostic. -The result is stored in the internal cache variable specified by -````, with boolean ``true`` for success and boolean ``false`` for -failure. + This command checks once that the ```` is accepted by the C compiler + without producing a diagnostic message. Multiple flags can be specified + in one argument as a string using a :ref:`semicolon-separated list + `. -``true`` indicates only that the compiler did not issue a diagnostic message -when given the flag. Whether the flag has any effect is beyond the scope of -this module. + The result of the check is stored in the internal cache variable specified + by ````, with boolean true for success and boolean false for + failure. -Internally, :command:`try_compile` is used to perform the check. If -:variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` is set to ``EXECUTABLE`` (default), -the check compiles and links an executable program. If set to -``STATIC_LIBRARY``, the check is compiled but not linked. + A successful result only indicates that the compiler did not report an + error when given the flag. Whether the flag has any effect, or the + intended one, is outside the scope of this module. -See also :command:`check_compiler_flag` for a more general command syntax. + .. note:: -The compile and link commands can be influenced by setting any of the -following variables prior to calling ``check_c_compiler_flag()``. Unknown flags -in these variables can case a false negative result. + Since the underlying :command:`try_compile` command also uses flags from + variables like :variable:`CMAKE__FLAGS`, unknown or unsupported + flags in those variables may result in a false negative for this check. + + .. rubric:: Variables Affecting the Check + + The following variables may be set before calling this command to modify + the way the check is run: .. include:: /module/include/CMAKE_REQUIRED_FLAGS.rst @@ -47,6 +65,37 @@ in these variables can case a false negative result. .. include:: /module/include/CMAKE_REQUIRED_QUIET.rst + .. include:: /module/include/CMAKE_TRY_COMPILE_TARGET_TYPE.rst + +Examples +^^^^^^^^ + +The following example demonstrates how to use this module to check support +for the C compiler flag ``-fno-optimize-strlen``, which disables +optimizations related to the ``strlen()`` C function in GCC and Clang +compilers. The result of the check is stored in the internal cache +variable ``HAVE_FNO_OPTIMIZE_STRLEN``, and the flag is conditionally enabled +using the :command:`target_compile_options` command. The +:genex:`$ ` generator +expression ensures that the flag is added only to ``C`` source files. + +.. code-block:: cmake + + include(CheckCCompilerFlag) + check_c_compiler_flag(-fno-optimize-strlen HAVE_FNO_OPTIMIZE_STRLEN) + + if(HAVE_FNO_OPTIMIZE_STRLEN) + target_compile_options( + example + PRIVATE $<$:-fno-optimize-strlen> + ) + endif() + +See Also +^^^^^^^^ + +* The :module:`CheckCompilerFlag` module for a more general command to check + whether a compiler flag is supported. #]=======================================================================] include_guard(GLOBAL) diff --git a/Modules/CheckCXXCompilerFlag.cmake b/Modules/CheckCXXCompilerFlag.cmake index 4e179f7662..a39ee530e3 100644 --- a/Modules/CheckCXXCompilerFlag.cmake +++ b/Modules/CheckCXXCompilerFlag.cmake @@ -5,33 +5,51 @@ CheckCXXCompilerFlag ------------------------ -Check once whether the CXX compiler supports a given flag. +This module provides a command to check whether the C++ compiler supports a +given flag. + +Load this module in a CMake project with: + +.. code-block:: cmake + + include(CheckCXXCompilerFlag) + +Commands +^^^^^^^^ + +This module provides the following command: .. command:: check_cxx_compiler_flag + Checks once whether the C++ compiler supports a given flag: + .. code-block:: cmake - check_cxx_compiler_flag( ) + check_cxx_compiler_flag( ) -Check once that the ```` is accepted by the compiler without a diagnostic. -The result is stored in the internal cache variable specified by -````, with boolean ``true`` for success and boolean ``false`` for -failure. + This command checks once that the ```` is accepted by the ``CXX`` + compiler without producing a diagnostic message. Multiple flags can be + specified in one argument as a string using a :ref:`semicolon-separated + list `. -``true`` indicates only that the compiler did not issue a diagnostic message -when given the flag. Whether the flag has any effect is beyond the scope of -this module. + The result of the check is stored in the internal cache variable specified + by ````, with boolean true for success and boolean false for + failure. -Internally, :command:`try_compile` is used to perform the check. If -:variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` is set to ``EXECUTABLE`` (default), -the check compiles and links an executable program. If set to -``STATIC_LIBRARY``, the check is compiled but not linked. + A successful result only indicates that the compiler did not report an + error when given the flag. Whether the flag has any effect, or the + intended one, is outside the scope of this module. -See also :command:`check_compiler_flag` for a more general command syntax. + .. note:: -The compile and link commands can be influenced by setting any of the -following variables prior to calling ``check_cxx_compiler_flag()``. Unknown flags -in these variables can case a false negative result. + Since the underlying :command:`try_compile` command also uses flags from + variables like :variable:`CMAKE__FLAGS`, unknown or unsupported + flags in those variables may result in a false negative for this check. + + .. rubric:: Variables Affecting the Check + + The following variables may be set before calling this command to modify + the way the check is run: .. include:: /module/include/CMAKE_REQUIRED_FLAGS.rst @@ -46,6 +64,36 @@ in these variables can case a false negative result. .. include:: /module/include/CMAKE_REQUIRED_LINK_DIRECTORIES.rst .. include:: /module/include/CMAKE_REQUIRED_QUIET.rst + + .. include:: /module/include/CMAKE_TRY_COMPILE_TARGET_TYPE.rst + +Examples +^^^^^^^^ + +The following example demonstrates how to use this module to check +the C++ compiler flag ``-fsycl``. The result of the check is stored in the +internal cache variable ``HAVE_FSYCL_FLAG``, and the flag is conditionally +enabled using the :command:`target_compile_options` command. The +:genex:`$ ` generator +expression ensures that the flag is added only to ``CXX`` source files. + +.. code-block:: cmake + + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag(-fsycl HAVE_FSYCL_FLAG) + + if(HAVE_FSYCL_FLAG) + target_compile_options( + example + PRIVATE $<$:-fsycl> + ) + endif() + +See Also +^^^^^^^^ + +* The :module:`CheckCompilerFlag` module for a more general command to check + whether a compiler flag is supported. #]=======================================================================] include_guard(GLOBAL) diff --git a/Modules/CheckCompilerFlag.cmake b/Modules/CheckCompilerFlag.cmake index a5c308dff0..969e6f6f1a 100644 --- a/Modules/CheckCompilerFlag.cmake +++ b/Modules/CheckCompilerFlag.cmake @@ -7,31 +7,68 @@ CheckCompilerFlag .. versionadded:: 3.19 -Check once whether the ```` compiler supports a given flag. +This module provides a command to check whether the compiler supports a given +flag. + +Load this module in a CMake project with: + +.. code-block:: cmake + + include(CheckCompilerFlag) + +Commands +^^^^^^^^ + +This module provides the following command: .. command:: check_compiler_flag + Checks once whether the compiler supports a given flag: + .. code-block:: cmake - check_compiler_flag( ) + check_compiler_flag( ) -Check once that the ```` is accepted by the ```` compiler without -a diagnostic. The result is stored in the internal cache variable specified by -````, with boolean ``true`` for success and boolean ``false`` for -failure. + This command checks once that the ```` is accepted by the ```` + compiler without producing a diagnostic message. The result of the check + is stored in the internal cache variable specified by ````. -``true`` indicates only that the compiler did not issue a diagnostic message -when given the flag. Whether the flag has any effect is beyond the scope of -this module. + The arguments are: -Internally, :command:`try_compile` is used to perform the check. If -:variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` is set to ``EXECUTABLE`` (default), -the check compiles and links an executable program. If set to -``STATIC_LIBRARY``, the check is compiled but not linked. + ```` + The language of the compiler used for the check. Supported languages + are: ``C``, ``CXX``, ``CUDA``, ``Fortran``, ``HIP``, ``ISPC``, ``OBJC``, + and ``OBJCXX``, and ``Swift``. -The compile and link commands can be influenced by setting any of the -following variables prior to calling ``check_compiler_flag()``. Unknown flags -in these variables can case a false negative result. + .. versionadded:: 3.21 + Support for ``HIP`` language. + + .. versionadded:: 3.26 + Support for ``Swift`` language. + + ```` + Compiler flag(s) to check. Multiple flags can be specified in one + argument as a string using a :ref:`semicolon-separated list + `. + + ```` + Variable name of an internal cache variable to store the result of the + check, with boolean true for success and boolean false for failure. + + A successful result only indicates that the compiler did not report an + error when given the flag. Whether the flag has any effect, or the + intended one, is outside the scope of this module. + + .. note:: + + Since the underlying :command:`try_compile` command also uses flags from + variables like :variable:`CMAKE__FLAGS`, unknown or unsupported + flags in those variables may result in a false negative for this check. + + .. rubric:: Variables Affecting the Check + + The following variables may be set before calling this command to modify + the way the check is run: .. include:: /module/include/CMAKE_REQUIRED_FLAGS.rst @@ -47,6 +84,37 @@ in these variables can case a false negative result. .. include:: /module/include/CMAKE_REQUIRED_QUIET.rst + .. include:: /module/include/CMAKE_TRY_COMPILE_TARGET_TYPE.rst + +Examples +^^^^^^^^ + +The following example demonstrates how to use this module to check support +for the C compiler flag ``-fno-optimize-strlen``, which disables +optimizations related to the ``strlen()`` C function in GCC and Clang +compilers. The result of the check is stored in the internal cache +variable ``HAVE_FNO_OPTIMIZE_STRLEN``, and the flag is conditionally enabled +using the :command:`target_compile_options` command. The +:genex:`$ ` generator +expression ensures that the flag is added only to ``C`` source files. + +.. code-block:: cmake + + include(CheckCompilerFlag) + check_compiler_flag(C -fno-optimize-strlen HAVE_FNO_OPTIMIZE_STRLEN) + + if(HAVE_FNO_OPTIMIZE_STRLEN) + target_compile_options( + example + PRIVATE $<$:-fno-optimize-strlen> + ) + endif() + +See Also +^^^^^^^^ + +* The :module:`CheckLinkerFlag` module to check whether a linker flag is + supported by the compiler. #]=======================================================================] include_guard(GLOBAL) diff --git a/Modules/CheckFortranCompilerFlag.cmake b/Modules/CheckFortranCompilerFlag.cmake index 695e4fa693..e9434147a6 100644 --- a/Modules/CheckFortranCompilerFlag.cmake +++ b/Modules/CheckFortranCompilerFlag.cmake @@ -7,33 +7,51 @@ CheckFortranCompilerFlag .. versionadded:: 3.3 -Check once whether the Fortran compiler supports a given flag. +This module provides a command to check whether the Fortran compiler supports +a given flag. + +Load this module in a CMake project with: + +.. code-block:: cmake + + include(CheckFortranCompilerFlag) + +Commands +^^^^^^^^ + +This module provides the following command: .. command:: check_fortran_compiler_flag + Checks once whether the Fortran compiler supports a given flag: + .. code-block:: cmake - check_fortran_compiler_flag( ) + check_fortran_compiler_flag( ) -Check once that the ```` is accepted by the compiler without a diagnostic. -The result is stored in the internal cache variable specified by -````, with boolean ``true`` for success and boolean ``false`` for -failure. + This command checks once that the ```` is accepted by the Fortran + compiler without producing a diagnostic message. Multiple flags can be + specified in one argument as a string using a :ref:`semicolon-separated list + `. -``true`` indicates only that the compiler did not issue a diagnostic message -when given the flag. Whether the flag has any effect is beyond the scope of -this module. + The result of the check is stored in the internal cache variable specified + by ````, with boolean true for success and boolean false for + failure. -Internally, :command:`try_compile` is used to perform the check. If -:variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` is set to ``EXECUTABLE`` (default), -the check compiles and links an executable program. If set to -``STATIC_LIBRARY``, the check is compiled but not linked. + A successful result only indicates that the compiler did not report an + error when given the flag. Whether the flag has any effect, or the + intended one, is outside the scope of this module. -See also :command:`check_compiler_flag` for a more general command syntax. + .. note:: -The compile and link commands can be influenced by setting any of the -following variables prior to calling ``check_fortran_compiler_flag()``. Unknown -flags in these variables can case a false negative result. + Since the underlying :command:`try_compile` command also uses flags from + variables like :variable:`CMAKE__FLAGS`, unknown or unsupported + flags in those variables may result in a false negative for this check. + + .. rubric:: Variables Affecting the Check + + The following variables may be set before calling this command to modify + the way the check is run: .. include:: /module/include/CMAKE_REQUIRED_FLAGS.rst @@ -49,6 +67,36 @@ flags in these variables can case a false negative result. .. include:: /module/include/CMAKE_REQUIRED_QUIET.rst + .. include:: /module/include/CMAKE_TRY_COMPILE_TARGET_TYPE.rst + +Examples +^^^^^^^^ + +The following example demonstrates how to use this module to check +the Fortran compiler flag ``-fallow-argument-mismatch``. The result of the +check is stored in the internal cache variable ``HAVE_FORTRAN_FLAG``, and +the flag is conditionally enabled using the :command:`target_compile_options` +command. The :genex:`$ ` +generator expression ensures that the flag is added only to ``Fortran`` +source files. + +.. code-block:: cmake + + include(CheckFortranCompilerFlag) + check_fortran_compiler_flag(-fallow-argument-mismatch HAVE_FORTRAN_FLAG) + + if(HAVE_FORTRAN_FLAG) + target_compile_options( + example + PRIVATE $<$:-fallow-argument-mismatch> + ) + endif() + +See Also +^^^^^^^^ + +* The :module:`CheckCompilerFlag` module for a more general command to check + whether a compiler flag is supported. #]=======================================================================] include_guard(GLOBAL) diff --git a/Modules/CheckLinkerFlag.cmake b/Modules/CheckLinkerFlag.cmake index 1639aad6cf..b17a96ce71 100644 --- a/Modules/CheckLinkerFlag.cmake +++ b/Modules/CheckLinkerFlag.cmake @@ -142,6 +142,8 @@ See Also * The :variable:`CMAKE_LINKER_TYPE` variable to specify the linker, which will be used also by this module. +* The :module:`CheckCompilerFlag` module to check whether a compiler flag + is supported. #]=======================================================================] include_guard(GLOBAL) diff --git a/Modules/CheckOBJCCompilerFlag.cmake b/Modules/CheckOBJCCompilerFlag.cmake index 84cfeaa0fb..1f4c6ed953 100644 --- a/Modules/CheckOBJCCompilerFlag.cmake +++ b/Modules/CheckOBJCCompilerFlag.cmake @@ -7,33 +7,51 @@ CheckOBJCCompilerFlag .. versionadded:: 3.16 -Check once whether the Objective-C compiler supports a given flag. +This module provides a command to check whether the Objective-C compiler +supports a given flag. + +Load this module in a CMake project with: + +.. code-block:: cmake + + include(CheckOBJCCompilerFlag) + +Commands +^^^^^^^^ + +This module provides the following command: .. command:: check_objc_compiler_flag + Checks once whether the Objective-C compiler supports a given flag: + .. code-block:: cmake - check_objc_compiler_flag( ) + check_objc_compiler_flag( ) -Check once that the ```` is accepted by the compiler without a diagnostic. -The result is stored in the internal cache variable specified by -````, with boolean ``true`` for success and boolean ``false`` for -failure. + This command checks once that the ```` is accepted by the ``OBJC`` + compiler without producing a diagnostic message. Multiple flags can be + specified in one argument as a string using a + :ref:`semicolon-separated list `. -``true`` indicates only that the compiler did not issue a diagnostic message -when given the flag. Whether the flag has any effect is beyond the scope of -this module. + The result of the check is stored in the internal cache variable specified + by ````, with boolean true for success and boolean false for + failure. -Internally, :command:`try_compile` is used to perform the check. If -:variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` is set to ``EXECUTABLE`` (default), -the check compiles and links an executable program. If set to -``STATIC_LIBRARY``, the check is compiled but not linked. + A successful result only indicates that the compiler did not report an + error when given the flag. Whether the flag has any effect, or the + intended one, is outside the scope of this module. -See also :command:`check_compiler_flag` for a more general command syntax. + .. note:: -The compile and link commands can be influenced by setting any of the -following variables prior to calling ``check_objc_compiler_flag()``. Unknown -flags in these variables can case a false negative result. + Since the underlying :command:`try_compile` command also uses flags from + variables like :variable:`CMAKE__FLAGS`, unknown or unsupported + flags in those variables may result in a false negative for this check. + + .. rubric:: Variables Affecting the Check + + The following variables may be set before calling this command to modify + the way the check is run: .. include:: /module/include/CMAKE_REQUIRED_FLAGS.rst @@ -49,6 +67,35 @@ flags in these variables can case a false negative result. .. include:: /module/include/CMAKE_REQUIRED_QUIET.rst + .. include:: /module/include/CMAKE_TRY_COMPILE_TARGET_TYPE.rst + +Examples +^^^^^^^^ + +The following example demonstrates how to use this module to check the +Objective-C compiler flag ``-fobjc-arc``. The result of the check is +stored in the internal cache variable ``HAVE_OBJC_ARC``, and the flag is +conditionally enabled using the :command:`target_compile_options` command. +The :genex:`$ ` generator +expression ensures that the flag is added only to ``OBJC`` source files. + +.. code-block:: cmake + + include(CheckOBJCCompilerFlag) + check_objc_compiler_flag(-fobjc-arc HAVE_OBJC_ARC) + + if(HAVE_OBJC_ARC) + target_compile_options( + example + PRIVATE $<$:-fobjc-arc> + ) + endif() + +See Also +^^^^^^^^ + +* The :module:`CheckCompilerFlag` module for a more general command to check + whether a compiler flag is supported. #]=======================================================================] include_guard(GLOBAL) diff --git a/Modules/CheckOBJCXXCompilerFlag.cmake b/Modules/CheckOBJCXXCompilerFlag.cmake index 5562fa4e02..d8ffe49e08 100644 --- a/Modules/CheckOBJCXXCompilerFlag.cmake +++ b/Modules/CheckOBJCXXCompilerFlag.cmake @@ -7,33 +7,51 @@ CheckOBJCXXCompilerFlag .. versionadded:: 3.16 -Check once whether the Objective-C++ compiler supports a given flag. +This module provides a command to check whether the Objective-C++ compiler +supports a given flag. + +Load this module in a CMake project with: + +.. code-block:: cmake + + include(CheckOBJCXXCompilerFlag) + +Commands +^^^^^^^^ + +This module provides the following command: .. command:: check_objcxx_compiler_flag + Checks once whether the Objective-C++ compiler supports a given flag: + .. code-block:: cmake - check_objcxx_compiler_flag( ) + check_objcxx_compiler_flag( ) -Check once that the ```` is accepted by the compiler without a diagnostic. -The result is stored in the internal cache variable specified by -````, with boolean ``true`` for success and boolean ``false`` for -failure. + This command checks once that the ```` is accepted by the ``OBJCXX`` + compiler without producing a diagnostic message. Multiple flags can be + specified in one argument as a string using a + :ref:`semicolon-separated list `. -``true`` indicates only that the compiler did not issue a diagnostic message -when given the flag. Whether the flag has any effect is beyond the scope of -this module. + The result of the check is stored in the internal cache variable specified + by ````, with boolean true for success and boolean false for + failure. -Internally, :command:`try_compile` is used to perform the check. If -:variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` is set to ``EXECUTABLE`` (default), -the check compiles and links an executable program. If set to -``STATIC_LIBRARY``, the check is compiled but not linked. + A successful result only indicates that the compiler did not report an + error when given the flag. Whether the flag has any effect, or the + intended one, is outside the scope of this module. -See also :command:`check_compiler_flag` for a more general command syntax. + .. note:: -The compile and link commands can be influenced by setting any of the -following variables prior to calling ``check_objcxx_compiler_flag()``. Unknown -flags in these variables can case a false negative result. + Since the underlying :command:`try_compile` command also uses flags from + variables like :variable:`CMAKE__FLAGS`, unknown or unsupported + flags in those variables may result in a false negative for this check. + + .. rubric:: Variables Affecting the Check + + The following variables may be set before calling this command to modify + the way the check is run: .. include:: /module/include/CMAKE_REQUIRED_FLAGS.rst @@ -49,6 +67,35 @@ flags in these variables can case a false negative result. .. include:: /module/include/CMAKE_REQUIRED_QUIET.rst + .. include:: /module/include/CMAKE_TRY_COMPILE_TARGET_TYPE.rst + +Examples +^^^^^^^^ + +The following example demonstrates how to use this module to check the +Objective-C++ compiler flag ``-fobjc-arc``. The result of the check is +stored in the internal cache variable ``HAVE_OBJC_ARC``, and the flag is +conditionally enabled using the :command:`target_compile_options` command. +The :genex:`$ ` generator +expression ensures that the flag is added only to ``OBJCXX`` source files. + +.. code-block:: cmake + + include(CheckOBJCXXCompilerFlag) + check_objcxx_compiler_flag(-fobjc-arc HAVE_OBJC_ARC) + + if(HAVE_OBJC_ARC) + target_compile_options( + example + PRIVATE $<$:-fobjc-arc> + ) + endif() + +See Also +^^^^^^^^ + +* The :module:`CheckCompilerFlag` module for a more general command to check + whether a compiler flag is supported. #]=======================================================================] include_guard(GLOBAL) diff --git a/Tests/FortranOnly/CMakeLists.txt b/Tests/FortranOnly/CMakeLists.txt index 6917cef402..d32c3bdff6 100644 --- a/Tests/FortranOnly/CMakeLists.txt +++ b/Tests/FortranOnly/CMakeLists.txt @@ -93,7 +93,7 @@ endif() unset(Fortran_BOGUS_FLAG CACHE) include(CheckFortranCompilerFlag) -CHECK_Fortran_COMPILER_FLAG(-_this_is_not_a_flag_ Fortran_BOGUS_FLAG) +check_fortran_compiler_flag(-_this_is_not_a_flag_ Fortran_BOGUS_FLAG) if (Fortran_BOGUS_FLAG) message(SEND_ERROR "CHECK_Fortran_COMPILER_FLAG() succeeded, but should have failed") endif()