File: TestForSSTREAM.cmake

package info (click to toggle)
cmake 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 147,284 kB
  • sloc: ansic: 403,915; cpp: 290,772; sh: 4,102; python: 3,357; yacc: 3,106; lex: 1,189; f90: 532; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 230; perl: 217; objc: 215; xml: 198; makefile: 97; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (85 lines) | stat: -rw-r--r-- 2,410 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file LICENSE.rst or https://cmake.org/licensing for details.

#[=======================================================================[.rst:
TestForSSTREAM
--------------

This module checks whether the C++ standard header ``<sstream>`` exists and
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.

This module defines the following cache variables:

``CMAKE_NO_ANSI_STRING_STREAM``
  A cache variable indicating whether the ``<sstream>`` header is available. It
  will be set to value ``0`` if ``<sstream>`` is available (``C++ 98`` and
  newer), and to value ``1`` if ``<sstream>`` is missing (``ANSI C++``).

``CMAKE_HAS_ANSI_STRING_STREAM``
  A cache variable that is the opposite of ``CMAKE_NO_ANSI_STRING_STREAM``
  (true if ``<sstream>`` is available and false if ``<sstream>`` is missing).

.. note::

  The ``<sstream>`` header was formally introduced in the ``C++ 98`` standard,
  making this check obsolete for modern compilers.

Examples
^^^^^^^^

Including this module will check for ``<sstream>`` support and define the
``CMAKE_NO_ANSI_STRING_STREAM`` cache variable:

.. code-block:: cmake
  :caption: ``CMakeLists.txt``

  include(TestForSSTREAM)
  file(
    CONFIGURE
    OUTPUT config.h
    CONTENT "#cmakedefine CMAKE_NO_ANSI_STRING_STREAM"
  )

Then it can be used in a C++ program:

.. code-block:: c++
  :caption: ``example.cxx``

  #include "config.h"

  #ifndef CMAKE_NO_ANSI_STRING_STREAM
  #  include <sstream>
  #endif

  int main() { ... }

See Also
^^^^^^^^

* The :module:`CMakeBackwardCompatibilityCXX` module.
#]=======================================================================]

if(NOT DEFINED CMAKE_HAS_ANSI_STRING_STREAM)
  message(CHECK_START "Check for sstream")
  try_compile(CMAKE_HAS_ANSI_STRING_STREAM
    SOURCES ${CMAKE_ROOT}/Modules/TestForSSTREAM.cxx
    )
  if (CMAKE_HAS_ANSI_STRING_STREAM)
    message(CHECK_PASS "found")
    set (CMAKE_NO_ANSI_STRING_STREAM 0 CACHE INTERNAL
         "Does the compiler support sstream")
  else ()
    message(CHECK_FAIL "not found")
    set (CMAKE_NO_ANSI_STRING_STREAM 1 CACHE INTERNAL
       "Does the compiler support sstream")
  endif ()
endif()