1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-18 00:02:21 +08:00

CMakeBackwardCompatibilityCXX: Add intro code blocks

This is mainly a sync with other CMake modules for consistency:
- Added intro code blocks showing how to include the modules.
- Adjusted examples sections.
- Added "See Also" sections.
This commit is contained in:
Peter Kokot
2025-05-18 18:38:27 +02:00
parent e33692e625
commit 26dd965037
5 changed files with 103 additions and 12 deletions

View File

@@ -8,6 +8,12 @@ CMakeBackwardCompatibilityCXX
This module defines several backward compatibility cache variables for the This module defines several backward compatibility cache variables for the
``CXX`` language to support early C++ (pre-C++98, ANSI C++). ``CXX`` language to support early C++ (pre-C++98, ANSI C++).
Load this module in a CMake project with:
.. code-block:: cmake
include(CMakeBackwardCompatibilityCXX)
The following modules are included by this module: The following modules are included by this module:
* :module:`TestForANSIForScope` * :module:`TestForANSIForScope`
@@ -30,11 +36,23 @@ Additionally, the following cache variable may be defined:
Examples Examples
^^^^^^^^ ^^^^^^^^
Including this module provides backward compatibility cache variables: Including this module provides backward compatibility cache variables, which
can be used in C++. For example:
.. code-block:: cmake .. code-block:: cmake
:caption: ``CMakeLists.txt``
include(CMakeBackwardCompatibilityCXX) include(CMakeBackwardCompatibilityCXX)
file(
CONFIGURE
OUTPUT config.h
CONTENT [[
#cmakedefine CMAKE_NO_ANSI_FOR_SCOPE
#cmakedefine CMAKE_NO_ANSI_STRING_STREAM
#cmakedefine CMAKE_NO_ANSI_STREAM_HEADERS
#cmakedefine CMAKE_NO_STD_NAMESPACE
]]
)
#]=======================================================================] #]=======================================================================]
if(NOT CMAKE_SKIP_COMPATIBILITY_TESTS) if(NOT CMAKE_SKIP_COMPATIBILITY_TESTS)

View File

@@ -6,9 +6,16 @@ TestForANSIForScope
------------------- -------------------
This module checks whether the ``CXX`` compiler restricts the scope of variables This module checks whether the ``CXX`` compiler restricts the scope of variables
declared in a for-init-statement to the loop body. In early C++ (pre-C++98), declared in a for-init-statement to the loop body.
variables declared in ``for(<init-statement> ...)`` could remain accessible
outside the loop after its body (``for() { <body> }``). Load this module in a CMake project with:
.. code-block:: cmake
include(TestForANSIForScope)
In early C++ (pre-C++98), variables declared in ``for(<init-statement> ...)``
could remain accessible outside the loop after its body (``for() { <body> }``).
This module defines the following cache variable: This module defines the following cache variable:
@@ -29,8 +36,30 @@ Including this module will check the ``for()`` loop scope behavior and define
the ``CMAKE_NO_ANSI_FOR_SCOPE`` cache variable: the ``CMAKE_NO_ANSI_FOR_SCOPE`` cache variable:
.. code-block:: cmake .. code-block:: cmake
:caption: ``CMakeLists.txt``
include(TestForANSIForScope) include(TestForANSIForScope)
file(
CONFIGURE
OUTPUT config.h
CONTENT "#cmakedefine CMAKE_NO_ANSI_FOR_SCOPE"
)
which can be then used in a C++ program:
.. code-block:: c++
:caption: ``example.cxx``
#include "config.h"
#ifdef CMAKE_NO_ANSI_FOR_SCOPE
# define for if(false) {} else for
#endif
See Also
^^^^^^^^
* The :module:`CMakeBackwardCompatibilityCXX` module.
#]=======================================================================] #]=======================================================================]
if(NOT DEFINED CMAKE_ANSI_FOR_SCOPE) if(NOT DEFINED CMAKE_ANSI_FOR_SCOPE)

View File

@@ -6,9 +6,16 @@ TestForANSIStreamHeaders
------------------------ ------------------------
This module checks whether the ``CXX`` compiler supports standard library This module checks whether the ``CXX`` compiler supports standard library
headers without the ``.h`` extension (e.g. ``<iostream>``). Early headers without the ``.h`` extension (e.g. ``<iostream>``).
versions of C++ (pre-C++98) didn't support including standard headers without
extensions. Load this module in a CMake project with:
.. code-block:: cmake
include(TestForANSIStreamHeaders)
Early versions of C++ (pre-C++98) didn't support including standard headers
without extensions.
This module defines the following cache variable: This module defines the following cache variable:
@@ -30,6 +37,7 @@ Including this module will check how the C++ standard headers can be included
and define the ``CMAKE_NO_ANSI_STREAM_HEADERS`` cache variable: and define the ``CMAKE_NO_ANSI_STREAM_HEADERS`` cache variable:
.. code-block:: cmake .. code-block:: cmake
:caption: ``CMakeLists.txt``
include(TestForANSIStreamHeaders) include(TestForANSIStreamHeaders)
file( file(
@@ -41,6 +49,7 @@ and define the ``CMAKE_NO_ANSI_STREAM_HEADERS`` cache variable:
C++ program can then include the available header conditionally: C++ program can then include the available header conditionally:
.. code-block:: c++ .. code-block:: c++
:caption: ``example.cxx``
#include "config.h" #include "config.h"
@@ -51,6 +60,11 @@ C++ program can then include the available header conditionally:
#endif #endif
int main() { ... } int main() { ... }
See Also
^^^^^^^^
* The :module:`CMakeBackwardCompatibilityCXX` module.
#]=======================================================================] #]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/CheckIncludeFileCXX.cmake) include(${CMAKE_CURRENT_LIST_DIR}/CheckIncludeFileCXX.cmake)

View File

@@ -6,7 +6,15 @@ TestForSSTREAM
-------------- --------------
This module checks whether the C++ standard header ``<sstream>`` exists and This module checks whether the C++ standard header ``<sstream>`` exists and
functions correctly. In early versions of C++ (pre-C++98), this header was not functions correctly.
Load this module in a CMake project with:
.. code-block:: cmake
include(TestForSSTREAM)
In early versions of C++ (pre-C++98), the ``<sstream>`` header was not
formally standardized and may not have been available. formally standardized and may not have been available.
This module defines the following cache variables: This module defines the following cache variables:
@@ -32,6 +40,7 @@ Including this module will check for ``<sstream>`` support and define the
``CMAKE_NO_ANSI_STRING_STREAM`` cache variable: ``CMAKE_NO_ANSI_STRING_STREAM`` cache variable:
.. code-block:: cmake .. code-block:: cmake
:caption: ``CMakeLists.txt``
include(TestForSSTREAM) include(TestForSSTREAM)
file( file(
@@ -43,6 +52,7 @@ Including this module will check for ``<sstream>`` support and define the
Then it can be used in a C++ program: Then it can be used in a C++ program:
.. code-block:: c++ .. code-block:: c++
:caption: ``example.cxx``
#include "config.h" #include "config.h"
@@ -51,6 +61,11 @@ Then it can be used in a C++ program:
#endif #endif
int main() { ... } int main() { ... }
See Also
^^^^^^^^
* The :module:`CMakeBackwardCompatibilityCXX` module.
#]=======================================================================] #]=======================================================================]
if(NOT DEFINED CMAKE_HAS_ANSI_STRING_STREAM) if(NOT DEFINED CMAKE_HAS_ANSI_STRING_STREAM)

View File

@@ -6,10 +6,18 @@ TestForSTDNamespace
------------------- -------------------
This module checks whether the ``CXX`` compiler supports the ``std`` namespace This module checks whether the ``CXX`` compiler supports the ``std`` namespace
for the C++ Standard Library. Early versions of C++ (pre-C++98) did not have a for the C++ Standard Library.
requirement for a dedicated namespace of C++ Standard Template Library (STL)
components (e.g. ``list``, etc.) and other parts of the C++ Standard Library Load this module in a CMake project with:
(such as I/O streams ``cout``, ``endl``, etc), so they were available globally.
.. code-block:: cmake
include(TestForSTDNamespace)
Early versions of C++ (pre-C++98) did not have a requirement for a dedicated
namespace of C++ Standard Template Library (STL) components (e.g. ``list``,
etc.) and other parts of the C++ Standard Library (such as I/O streams
``cout``, ``endl``, etc), so they were available globally.
This module defines the following cache variable: This module defines the following cache variable:
@@ -30,6 +38,7 @@ Including this module will check for the ``std`` namespace support and define
the ``CMAKE_NO_STD_NAMESPACE`` cache variable: the ``CMAKE_NO_STD_NAMESPACE`` cache variable:
.. code-block:: cmake .. code-block:: cmake
:caption: ``CMakeLists.txt``
include(TestForSTDNamespace) include(TestForSTDNamespace)
file( file(
@@ -41,12 +50,18 @@ the ``CMAKE_NO_STD_NAMESPACE`` cache variable:
which can be then used in a C++ program to define the missing namespace: which can be then used in a C++ program to define the missing namespace:
.. code-block:: c++ .. code-block:: c++
:caption: ``example.cxx``
#include "config.h" #include "config.h"
#ifdef CMAKE_NO_STD_NAMESPACE #ifdef CMAKE_NO_STD_NAMESPACE
# define std # define std
#endif #endif
See Also
^^^^^^^^
* The :module:`CMakeBackwardCompatibilityCXX` module.
#]=======================================================================] #]=======================================================================]
if(NOT DEFINED CMAKE_STD_NAMESPACE) if(NOT DEFINED CMAKE_STD_NAMESPACE)