TestForANSIStreamHeaders
This module checks whether the CXX compiler supports standard library headers without the .h extension (e.g. <iostream>).
Load this module in a CMake project with:
include(TestForANSIStreamHeaders)
Early versions of C++ (pre-C++98) didn't support including standard headers without extensions.
This module defines the following cache variable:
-
CMAKE_NO_ANSI_STREAM_HEADERS -
A cache variable containing the result of the check. It will be set to value
0if the standard headers can be included without the.hextension (C++ 98and newer), and to value1if.his required (ANSI C++).
Note
The C++ standard headers without extensions got formally introduced in the C++ 98 standard, making this issue obsolete.
Examples
Including this module will check how the C++ standard headers can be included and define the CMAKE_NO_ANSI_STREAM_HEADERS cache variable:
CMakeLists.txtinclude(TestForANSIStreamHeaders) file( CONFIGURE OUTPUT config.h CONTENT "#cmakedefine CMAKE_NO_ANSI_STREAM_HEADERS" )
C++ program can then include the available header conditionally:
example.cxx#include "config.h"
#ifdef CMAKE_NO_ANSI_STREAM_HEADERS
# include <iostream.h>
#else
# include <iostream>
#endif
int main() { ... }
See Also
- The
CMakeBackwardCompatibilityCXXmodule.
© 2000–2026 Kitware, Inc. and Contributors
Licensed under the BSD 3-clause License.
https://cmake.org/cmake/help/latest/module/TestForANSIStreamHeaders.html