如何使用 clang 3.6.0 和 libc++ 构建 cmake 3.1.3?

How to build cmake 3.1.3 using clang 3.6.0 and libc++?

我正在尝试使用 clang 及其自己的 c++ 库构建 cmake 3.1.3,即:

export CC=clang 
export CXX=clang++ 
export CXXFLAGS="-std=c++11 -stdlib=libc++" 
export LDFLAGS="-lc++ -lc++abi"

接着是

./bootstrap

但是,由于 bootstrap 脚本测试 CXX 编译器的方式,这不起作用。如果我破解 bootstrap 文件并将 LDFLAGS 添加到 CXX 测试中,我就可以开始编译 cmake。但是,一旦我到达 bootstrap 阶段,编译 cmake 二进制文件就坏了。我做错了什么?

使用 Angew 的想法并尝试使用现有的 cmake 安装进行编译实际上会让你走得更远:如果你使用与上面几乎相同的导出:

export CC=clang 
export CXX=clang++ 
export CXXFLAGS="-std=c++11 -stdlib=libc++" 
export LDFLAGS="-L${COMPILERROOT}/lib -lc++ -lc++abi"

和一个小 sed 来绕过一个奇怪的编译错误(假设你在不同的构建目录中并且你将 cmake 源提取到当前目录的 ../cmake 目录)

sed -i s/kwsys_ios::hex/cmsys_ios::istringstream::hex/g ../cmake/Source/kwsys/SystemInformation.cxx
sed -i s/kwsys_ios::dec/cmsys_ios::istringstream::dec/g ../cmake/Source/kwsys/SystemInformation.cxx

然后您可以通过以下方式编译 cmake:

cmake ../cmake/ -DCMAKE_INSTALL_PREFIX=${INSTALLDIR}
make -j${NPROC}
make install

例如,如果我尝试安装 Cern ROOT6,它仍然会崩溃:

This warning is for project developers.  Use -Wno-dev to suppress it.
uncaught_exception not yet implemented

Program received signal SIGABRT, Aborted.
0x00007ffff6e495e9 in raise () from /lib64/libc.so.6
(gdb) bt
#0  0x00007ffff6e495e9 in raise () from /lib64/libc.so.6
#1  0x00007ffff6e4acf8 in abort () from /lib64/libc.so.6
#2  0x00007ffff7b755a5 in std::uncaught_exception() () from /home/balzer/middleware/software/clang/3.6.0/lib/libc++.so.1
#3  0x00007ffff7ba80fd in std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::~sentry() () from /home/balzer/middleware/software/clang/3.6.0/lib/libc++.so.1
#4  0x0000000000531561 in std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) ()
#5  0x0000000000530c8c in std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<< <std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) ()
#6  0x000000000052fccb in cmakemainMessageCallback(char const*, char const*, bool&, void*) ()
#7  0x00000000007527c9 in cmSystemTools::Message(char const*, char const*) ()
#8  0x000000000085c934 in cmake::IssueMessage(cmake::MessageType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmListFileBacktrace const&) ()
#9  0x000000000062a756 in cmMakefile::IssueMessage(cmake::MessageType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const ()
#10 0x00000000009c56cb in cmConditionEvaluator::GetDefinitionIfUnquoted(cmExpandedCommandArgument const&) const ()
#11 0x00000000009c57fd in cmConditionEvaluator::GetVariableOrString(cmExpandedCommandArgument const&) const ()
#12 0x00000000009c0600 in cmConditionEvaluator::HandleLevel2(std::__1::list<cmExpandedCommandArgument, std::__1::allocator<cmExpandedCommandArgument> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, cmake::MessageType&) ()
#13 0x00000000009bce3b in cmConditionEvaluator::IsTrue(std::__1::vector<cmExpandedCommandArgument, std::__1::allocator<cmExpandedCommandArgument> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, cmake::MessageType&) ()
#14 0x00000000009bdd5e in cmConditionEvaluator::HandleLevel0(std::__1::list<cmExpandedCommandArgument, std::__1::allocator<cmExpandedCommandArgument> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, cmake::MessageType&) ()
#15 0x00000000009bcd91 in cmConditionEvaluator::IsTrue(std::__1::vector<cmExpandedCommandArgument, std::__1::allocator<cmExpandedCommandArgument> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, cmake::MessageType&) ()
#16 0x00000000009d902b in cmIfCommand::InvokeInitialPass(std::__1::vector<cmListFileArgument, std::__1::allocator<cmListFileArgument> > const&, cmExecutionStatus&) ()
#17 0x000000000062b4d6 in cmMakefile::ExecuteCommand(cmListFileFunction const&, cmExecutionStatus&) ()
#18 0x000000000098ffb1 in cmForEachFunctionBlocker::IsFunctionBlocked(cmListFileFunction const&, cmMakefile&, cmExecutionStatus&) ()
#19 0x000000000062c5cb in cmMakefile::IsFunctionBlocked(cmListFileFunction const&, cmExecutionStatus&) ()
#20 0x000000000062b21c in cmMakefile::ExecuteCommand(cmListFileFunction const&, cmExecutionStatus&) ()
#21 0x0000000000630242 in cmMakefile::ReadListFile(char const*, char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, bool) ()
#22 0x00000000005cbad4 in cmLocalGenerator::ReadInputFile() ()
#23 0x00000000005cb437 in cmLocalGenerator::Configure() ()
#24 0x0000000000ca2af8 in cmLocalUnixMakefileGenerator3::Configure() ()
#25 0x0000000000bf3df6 in cmGlobalGenerator::Configure() ()
#26 0x0000000000c44edd in cmGlobalUnixMakefileGenerator3::Configure() ()
#27 0x000000000084c49e in cmake::ActualConfigure() ()
#28 0x0000000000849b24 in cmake::Configure() ()
#29 0x0000000000850efa in cmake::Run(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, bool) ()
#30 0x000000000052f665 in do_cmake(int, char const* const*) ()
#31 0x000000000052c149 in main ()

但是,如果我将 -Wno-dev 选项添加到 cmake 调用中,它就可以正常工作。