CheckInclude{FileCXX,File,Files}: Add examples

This adds some examples to modules for checking headers.
This commit is contained in:
Peter Kokot 2025-03-06 23:05:57 +01:00
parent c2d9b5944a
commit d3b7f0d272
No known key found for this signature in database
GPG Key ID: A94800907AA79B36
3 changed files with 71 additions and 7 deletions

View File

@ -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 ``<unistd.h>`` 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)

View File

@ -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 ``<stdfloat>`` 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)

View File

@ -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 <net/if.h> header on Darwin and BSD-like systems is not self-contained
# and also requires <sys/socket.h>
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)