Commit fd4fd9a2 authored by Brad King's avatar Brad King 💬
Browse files

Require C++11 to build CMake itself

CMake can now compile as C++11 on all supported platforms.  Check that
std::unique_ptr is available and fail early if missing.  This will allow
us to use C++11 more broadly in CMake's implementation (previously it
was restricted to the serve mode implementation).

Co-Author: Daniel Pfeifer <>
parent c47c011c
......@@ -80,6 +80,10 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE)
# check for available C++ features
message(FATAL_ERROR "The C++ compiler does not support C++11 (e.g. std::unique_ptr).")
# set the internal encoding of CMake to UTF-8
......@@ -23,20 +23,18 @@ format only a subset of files, such as those that are locally modified.
C++ Subset Permitted
CMake supports compiling as C++98 in addition to C++11 and C++14.
In order to support building on older toolchains some constructs
need to be handled with care:
CMake requires compiling as C++11 or above. However, in order to support
building on older toolchains some constructs need to be handled with care:
* Use ``CM_AUTO_PTR`` instead of ``std::auto_ptr``.
* Do not use ``CM_AUTO_PTR`` or ``std::auto_ptr``.
The ``std::auto_ptr`` template is deprecated in C++11. We want to use it
so we can build on C++98 compilers but we do not want to turn off compiler
warnings about deprecated interfaces in general. Use the ``CM_AUTO_PTR``
macro instead.
The ``std::auto_ptr`` template is deprecated in C++11. The ``CM_AUTO_PTR``
macro remains leftover from C++98 support until its uses can be ported to
``std::unique_ptr``. Do not add new uses of the macro.
* Use ``CM_EQ_DELETE;`` instead of ``= delete;``.
Defining functions as *deleted* is not supported in C++98. Using
Older C++11 compilers do not support deleting functions. Using
``CM_EQ_DELETE`` will delete the functions if the compiler supports it and
give them no implementation otherwise. Calling such a function will lead
to compiler errors if the compiler supports *deleted* functions and linker
* Support for building CMake itself with C++98 compilers was dropped.
CMake is now implemented using C++11.
......@@ -51,7 +51,7 @@ Building CMake from Scratch
You need to have a compiler and a make installed.
You need to have a C++ compiler (supporting C++11) and a ``make`` installed.
Run the ``bootstrap`` script you find in the source directory of CMake.
You can use the ``--help`` option to see the supported options.
You may use the ``--prefix=<install_prefix>`` option to specify a custom
......@@ -1004,58 +1004,45 @@ fi
# Check if C++ compiler works
echo '
#if defined(TEST1)
# include <iostream>
# include <iostream.h>
#include <iostream>
#include <memory>
#if __cplusplus >= 201103L && defined(__SUNPRO_CC) && __SUNPRO_CC < 0x5140
#error "SunPro <= 5.13 C++ 11 mode not supported due to bug in move semantics."
class NeedCXX
class Class
NeedCXX() { this->Foo = 1; }
int GetFoo() { return this->Foo; }
int Get() const { return this->Member; }
int Foo;
int Member = 1;
int main()
NeedCXX c;
#ifdef TEST3
cout << c.GetFoo() << endl;
std::cout << c.GetFoo() << std::endl;
auto const c = std::unique_ptr<Class>(new Class);
std::cout << c->Get() << std::endl;
return 0;
' > "${TMPFILE}.cxx"
for a in ${cmake_cxx_compilers}; do
for b in 1 2 3; do
if [ -z "${cmake_cxx_compiler}" ] && \
cmake_try_run "${a}" "${cmake_cxx_flags} -DTEST${b}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
for std in 14 11 98; do
for std in 17 14 11; do
try_flags="`cmake_extract_standard_flags \"${cmake_toolchain}\" CXX \"${std}\"`"
for flag in $try_flags; do
echo "Checking for wheter ${cmake_cxx_flags} supports ${flag}" >> cmake_bootstrap.log 2>&1
if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags} ${flag} -DTEST1" \
"${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
cmake_cxx_flags="${cmake_cxx_flags} ${flag} "
break 2
for compiler in ${cmake_cxx_compilers}; do
for flag in '' $try_flags; do
echo "Checking whether '${compiler} ${cmake_cxx_flags} ${flag}' works." >> cmake_bootstrap.log 2>&1
if cmake_try_run "${compiler}" "${cmake_cxx_flags} ${flag}" \
"${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
cmake_cxx_flags="${cmake_cxx_flags} ${flag} "
break 3
rm -f "${TMPFILE}.cxx"
if [ -z "${cmake_cxx_compiler}" ]; then
cmake_error 7 "Cannot find appropriate C++ compiler on this system.
cmake_error 7 "Cannot find a C++ compiler supporting C++11 on this system.
Please specify one using environment variable CXX.
See cmake_bootstrap.log for compilers attempted."
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment