diff --git a/Modules/CheckIncludeFile.cmake b/Modules/CheckIncludeFile.cmake index f070ba53f7..a3a2cee4b6 100644 --- a/Modules/CheckIncludeFile.cmake +++ b/Modules/CheckIncludeFile.cmake @@ -35,9 +35,24 @@ the way the check is run: .. include:: /module/CMAKE_REQUIRED_QUIET.txt -See the :module:`CheckIncludeFiles` module to check for multiple headers -at once. See the :module:`CheckIncludeFileCXX` module to check for headers -using the ``CXX`` language. +Examples +^^^^^^^^ + +Checking whether the ``C`` header ```` exists and storing the check +result in the ``HAVE_UNISTD_H`` cache variable: + +.. code-block:: cmake + + include(CheckIncludeFile) + + check_include_file(unistd.h HAVE_UNISTD_H) + +See Also +^^^^^^^^ + +* The :module:`CheckIncludeFileCXX` module to check for single ``C++`` header. +* The :module:`CheckIncludeFiles` module to check for one or more ``C`` or + ``C++`` headers at once. #]=======================================================================] include_guard(GLOBAL) diff --git a/Modules/CheckIncludeFileCXX.cmake b/Modules/CheckIncludeFileCXX.cmake index ec02b36a72..756abf16a5 100644 --- a/Modules/CheckIncludeFileCXX.cmake +++ b/Modules/CheckIncludeFileCXX.cmake @@ -35,8 +35,24 @@ the way the check is run: .. include:: /module/CMAKE_REQUIRED_QUIET.txt -See modules :module:`CheckIncludeFile` and :module:`CheckIncludeFiles` -to check for one or more ``C`` headers. +Examples +^^^^^^^^ + +Checking whether the ``C++23`` header ```` exists and storing the +check result in the ``HAVE_STDFLOAT_HEADER`` cache variable: + +.. code-block:: cmake + + include(CheckIncludeFileCXX) + + check_include_file_cxx(stdfloat HAVE_STDFLOAT_HEADER) + +See Also +^^^^^^^^ + +* The :module:`CheckIncludeFile` module to check for single ``C`` header. +* The :module:`CheckIncludeFiles` module to check for one or more ``C`` or + ``C++`` headers at once. #]=======================================================================] include_guard(GLOBAL) diff --git a/Modules/CheckIncludeFiles.cmake b/Modules/CheckIncludeFiles.cmake index 6dfb41da10..855d45053e 100644 --- a/Modules/CheckIncludeFiles.cmake +++ b/Modules/CheckIncludeFiles.cmake @@ -41,8 +41,41 @@ the way the check is run: .. include:: /module/CMAKE_REQUIRED_QUIET.txt -See modules :module:`CheckIncludeFile` and :module:`CheckIncludeFileCXX` -to check for a single header file in ``C`` or ``CXX`` languages. +Examples +^^^^^^^^ + +Checking whether one or more ``C`` headers exist and storing the check result +in cache variables: + +.. code-block:: cmake + + include(CheckIncludeFiles) + + check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) + + if(HAVE_SYS_SOCKET_H) + # The header on Darwin and BSD-like systems is not self-contained + # and also requires + check_include_files("sys/socket.h;net/if.h" HAVE_NET_IF_H) + else() + check_include_files(net/if.h HAVE_NET_IF_H) + endif() + +The ``LANGUAGE`` option can be used to specify which compiler to use. For +example, checking multiple ``C++`` headers, when both ``C`` and ``CXX`` +languages are enabled in the project: + +.. code-block:: cmake + + include(CheckIncludeFiles) + + check_include_files("header_1.hpp;header_2.hpp" HAVE_HEADERS LANGUAGE CXX) + +See Also +^^^^^^^^ + +* The :module:`CheckIncludeFile` module to check for single ``C`` header. +* The :module:`CheckIncludeFileCXX` module to check for single ``C++`` header. #]=======================================================================] include_guard(GLOBAL)