Files
CMake/Modules/CMakeBackwardCompatibilityCXX.cmake
Peter Kokot 50e57aa4ca CMAKE_COMPILER_IS_*: Replace with CMAKE_<LANG>_COMPILER_ID
Variables such as CMAKE_COMPILER_IS_GNUCC are documented as
obsolete/deprecated and ideally shouldn't be used in the code anymore
to have clearer compiler identifications.

In the past QCC compiler was identified as GNU and also had this
variable set to 1 (see policy CMP0047).  Same still applies for LCC
compiler (see policy CMP0129).
2025-03-29 20:31:49 +01:00

69 lines
2.3 KiB
CMake

# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file LICENSE.rst or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
CMakeBackwardCompatibilityCXX
-----------------------------
This module defines several backward compatibility cache variables for the
``CXX`` language to support early C++ (pre-C++98, ANSI C++).
The following modules are included by this module:
* :module:`TestForANSIForScope`
* :module:`TestForANSIStreamHeaders`
* :module:`TestForSSTREAM`
* :module:`TestForSTDNamespace`
Additionally, the following cache variable may be defined:
``CMAKE_ANSI_CXXFLAGS``
A space-separated string of compiler options for enabling ANSI C++ mode, if
available.
.. note::
This module is intended for C++ code written before ``C++ 98``. As of the
``C++ 98`` standard, these issues have been formally addressed, making such
checks obsolete.
Examples
^^^^^^^^
Including this module provides backward compatibility cache variables:
.. code-block:: cmake
include(CMakeBackwardCompatibilityCXX)
#]=======================================================================]
if(NOT CMAKE_SKIP_COMPATIBILITY_TESTS)
# check for some ANSI flags in the CXX compiler if it is not gnu
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
include(TestCXXAcceptsFlag)
set(CMAKE_TRY_ANSI_CXX_FLAGS "")
if(CMAKE_SYSTEM_NAME MATCHES "OSF")
set(CMAKE_TRY_ANSI_CXX_FLAGS "-std strict_ansi -nopure_cname")
endif()
# if CMAKE_TRY_ANSI_CXX_FLAGS has something in it, see
# if the compiler accepts it
if(NOT CMAKE_TRY_ANSI_CXX_FLAGS STREQUAL "")
check_cxx_accepts_flag(${CMAKE_TRY_ANSI_CXX_FLAGS} CMAKE_CXX_ACCEPTS_FLAGS)
# if the compiler liked the flag then set CMAKE_ANSI_CXXFLAGS
# to the flag
if(CMAKE_CXX_ACCEPTS_FLAGS)
set(CMAKE_ANSI_CXXFLAGS ${CMAKE_TRY_ANSI_CXX_FLAGS} CACHE INTERNAL
"What flags are required by the c++ compiler to make it ansi." )
endif()
endif()
endif()
set(CMAKE_CXX_FLAGS_SAVE ${CMAKE_CXX_FLAGS})
string(APPEND CMAKE_CXX_FLAGS " ${CMAKE_ANSI_CXXFLAGS}")
include(TestForANSIStreamHeaders)
include(CheckIncludeFileCXX)
include(TestForSTDNamespace)
include(TestForANSIForScope)
include(TestForSSTREAM)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_SAVE}")
endif()