CMake 3.10.1 bootstrap fails on Mac OS X 10.8.5 with "Cannot find a C++ compiler supporting C++11 on this system."
Symptoms
On Mac OS X 10.8.5, attempting to execute ./bootstrap
results in an error message including the following text:
Error when bootstrapping CMake:
Cannot find a C++ compiler supporting C++11 on this system.
The most relevant section (due to use of -std=c++11
) of cmake_bootstrap.log
seems to be:
Try: clang++
Line: clang++ -std=c++11 cmake_bootstrap_35535_test.cxx -o cmake_bootstrap_35535_test
---------- file -----------------------
#include <iostream>
#include <memory>
#include <unordered_map>
#if __cplusplus < 201103L
#error "Compiler is not in a mode aware of C++11."
#endif
#if defined(__SUNPRO_CC) && __SUNPRO_CC < 0x5140
#error "SunPro <= 5.13 mode not supported due to bug in move semantics."
#endif
class Class
{
public:
int Get() const { return this->Member; }
private:
int Member = 1;
};
int main()
{
auto const c = std::unique_ptr<Class>(new Class);
std::cout << c->Get() << std::endl;
return 0;
}
------------------------------------------
cmake_bootstrap_35535_test.cxx:4:10: fatal error: 'unordered_map' file not found
#include <unordered_map>
^
1 error generated.
Test failed to compile
Context
I had previously installed CMake 3.9.6 successfully (via Homebrew).
The output of clang++ --version
was:
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
Investigation
I was fairly certain I'd used the version of clang
with C++11 before so was surprised that the bootstrap code seemed to think it didn't support it.
I tried removing the unordered_map
include and got a different error (which I don't remember).
The error relating to unordered_map
led me to "What could cause clang to not find the unordered_map header?" which mentions that in addition to -std=c++11
that -stdlib=libstdc++
is also required.
Workaround
I was able get the bootstrap to complete successfully by adding the following environment variable (I now realise I may have only needed the latter part):
CXXFLAGS="-std=c++11 -stdlib=libc++"
Specifically:
CXXFLAGS="-std=c++11 -stdlib=libc++" ./bootstrap --prefix=/usr/local/Cellar/cmake/3.10.1 --no-system-libs --parallel=8 --datadir=/share/cmake --docdir=/share/doc/cmake --mandir=/share/man --system-zlib --system-bzip2 --system-curl --sphinx-man --sphinx-build=/usr/local/opt/sphinx-doc/bin/sphinx-build -- -DCMAKE_BUILD_TYPE=Release
This installation was using Homebrew which no longer seems to use "externally set" environment variables so I had to edit the cmake
formula to include this line before the execution of bootstrap
:
ENV["CXXFLAGS"] = "-std=c++11 -stdlib=libc++"
Root cause
I've not actually tracked down the underlying root cause of the issue but the following seem relevant:
-stdlib
Need for It seems the need for the addition of -stdlib
is known because it's present in: https://github.com/Kitware/CMake/blob/e710d6953dae27f73452095df6d7b2d7ec698fd1/Utilities/Release/osx_release.cmake#L13
set(CXXFLAGS "-stdlib=libc++")
I wonder if this perhaps also needs to be added to something like: Modules/Compiler/AppleClang-CXX.cmake
?
Potentially related commits
-
The
unordered_map
error comes from this commit but it's only a symptom: "bootstrap: Check support for unordered_map from compiler mode" -
Presumably this change to require C++11 led to the error occurring but isn't in and of itself the underlying issue: Require C++11 to build CMake itself
These other commits also interact with this process: