TestForSTDNamespace
This module checks whether the CXX compiler supports the std namespace for the C++ Standard Library.
Load this module in a CMake project with:
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:
-
CMAKE_NO_STD_NAMESPACE -
A cache variable containing the result of the check. It will be set to value
0if thestdnamespace is supported (C++ 98and newer), and to value1if not (ANSI C++).
Note
The std namespace got formally introduced in C++ 98 standard, making this issue obsolete.
Examples
Including this module will check for the std namespace support and define the CMAKE_NO_STD_NAMESPACE cache variable:
CMakeLists.txtinclude(TestForSTDNamespace) file( CONFIGURE OUTPUT config.h CONTENT "#cmakedefine CMAKE_NO_STD_NAMESPACE" )
which can be then used in a C++ program to define the missing namespace:
example.cxx#include "config.h" #ifdef CMAKE_NO_STD_NAMESPACE # define std #endif
See Also
- The
CMakeBackwardCompatibilityCXXmodule.
© 2000–2026 Kitware, Inc. and Contributors
Licensed under the BSD 3-clause License.
https://cmake.org/cmake/help/latest/module/TestForSTDNamespace.html