TestForSSTREAM.cmake 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. TestForSSTREAM
  5. --------------
  6. This module checks whether the C++ standard header ``<sstream>`` exists and
  7. functions correctly. In early versions of C++ (pre-C++98), this header was not
  8. formally standardized and may not have been available.
  9. This module defines the following cache variables:
  10. ``CMAKE_NO_ANSI_STRING_STREAM``
  11. A cache variable indicating whether the ``<sstream>`` header is available. It
  12. will be set to value ``0`` if ``<sstream>`` is available (``C++ 98`` and
  13. newer), and to value ``1`` if ``<sstream>`` is missing (``ANSI C++``).
  14. ``CMAKE_HAS_ANSI_STRING_STREAM``
  15. A cache variable that is the opposite of ``CMAKE_NO_ANSI_STRING_STREAM``
  16. (true if ``<sstream>`` is available and false if ``<sstream>`` is missing).
  17. .. note::
  18. The ``<sstream>`` header was formally introduced in the ``C++ 98`` standard,
  19. making this check obsolete for modern compilers.
  20. Examples
  21. ^^^^^^^^
  22. Including this module will check for ``<sstream>`` support and define the
  23. ``CMAKE_NO_ANSI_STRING_STREAM`` cache variable:
  24. .. code-block:: cmake
  25. include(TestForSSTREAM)
  26. file(
  27. CONFIGURE
  28. OUTPUT config.h
  29. CONTENT "#cmakedefine CMAKE_NO_ANSI_STRING_STREAM"
  30. )
  31. Then it can be used in a C++ program:
  32. .. code-block:: c++
  33. #include "config.h"
  34. #ifndef CMAKE_NO_ANSI_STRING_STREAM
  35. # include <sstream>
  36. #endif
  37. int main() { ... }
  38. #]=======================================================================]
  39. if(NOT DEFINED CMAKE_HAS_ANSI_STRING_STREAM)
  40. message(CHECK_START "Check for sstream")
  41. try_compile(CMAKE_HAS_ANSI_STRING_STREAM
  42. SOURCES ${CMAKE_ROOT}/Modules/TestForSSTREAM.cxx
  43. )
  44. if (CMAKE_HAS_ANSI_STRING_STREAM)
  45. message(CHECK_PASS "found")
  46. set (CMAKE_NO_ANSI_STRING_STREAM 0 CACHE INTERNAL
  47. "Does the compiler support sstream")
  48. else ()
  49. message(CHECK_FAIL "not found")
  50. set (CMAKE_NO_ANSI_STRING_STREAM 1 CACHE INTERNAL
  51. "Does the compiler support sstream")
  52. endif ()
  53. endif()