Abseil CMake build fails on Apple M1 (ARM64)
Describe the bug
A CMake build of Abseil on my Mac mini M1 fails
$ cmake -S . -B cmake-out
$ cmake --build cmake-out -- VERBOSE=1
...
[ 0%] Building CXX object absl/base/CMakeFiles/strerror.dir/internal/strerror.cc.o
cd /Users/jgm/github/devjgm/abseil-cpp/cmake-out/absl/base && /Library/Developer/CommandLineTools/usr/bin/c++ -I/Users/jgm/github/devjgm/abseil-cpp -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk -Wall -Wextra -Wcast-qual -Wconversion -Wfloat-overflow-conversion -Wfloat-zero-conversion -Wfor-loop-analysis -Wformat-security -Wgnu-redeclared-enum -Winfinite-recursion -Winvalid-constexpr -Wliteral-conversion -Wmissing-declarations -Woverlength-strings -Wpointer-arith -Wself-assign -Wshadow -Wstring-conversion -Wtautological-overlap-compare -Wundef -Wuninitialized -Wunreachable-code -Wunused-comparison -Wunused-local-typedefs -Wunused-result -Wvla -Wwrite-strings -Wno-float-conversion -Wno-implicit-float-conversion -Wno-implicit-int-float-conversion -Wno-implicit-int-conversion -Wno-shorten-64-to-32 -Wno-sign-conversion -DNOMINMAX -MD -MT absl/base/CMakeFiles/strerror.dir/internal/strerror.cc.o -MF CMakeFiles/strerror.dir/internal/strerror.cc.o.d -o CMakeFiles/strerror.dir/internal/strerror.cc.o -c /Users/jgm/github/devjgm/abseil-cpp/absl/base/internal/strerror.cc
In file included from /Users/jgm/github/devjgm/abseil-cpp/absl/base/internal/strerror.cc:15:
In file included from /Users/jgm/github/devjgm/abseil-cpp/absl/base/internal/strerror.h:20:
In file included from /Users/jgm/github/devjgm/abseil-cpp/absl/base/config.h:67:
/Users/jgm/github/devjgm/abseil-cpp/absl/base/policy_checks.h:77:2: error: "C++ versions less than C++11 are not supported."
#error "C++ versions less than C++11 are not supported."
^
/Users/jgm/github/devjgm/abseil-cpp/absl/base/internal/strerror.cc:41:3: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto ret = strerror_r(errnum, buf, buflen);
^
/Users/jgm/github/devjgm/abseil-cpp/absl/base/internal/strerror.cc:65:1: error: unknown type name 'constexpr'
constexpr int kSysNerr = 135;
^
/Users/jgm/github/devjgm/abseil-cpp/absl/base/internal/strerror.cc:68:3: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto* table = new std::array<std::string, kSysNerr>;
^
/Users/jgm/github/devjgm/abseil-cpp/absl/base/internal/strerror.cc:79:16: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
static const auto* table = NewStrErrorTable();
^
3 warnings and 2 errors generated.
make[2]: *** [absl/base/CMakeFiles/strerror.dir/internal/strerror.cc.o] Error 1
make[1]: *** [absl/base/CMakeFiles/strerror.dir/all] Error 2
make: *** [all] Error 2
Steps to reproduce the bug
IMPORTANT On an Apple M1 machine
- Checkout the Abseil code. I'm using HEAD=a9831f1cbf93fb18dd951453635f488037454ce9
-
cmake -S . - B cmake-out -
cmake --build cmake-out(add-- VERBOSE=1to see the build command)
What version of Abseil are you using?
HEAD=a9831f1cbf93fb18dd951453635f488037454ce9
What operating system and version are you using
ProductName: macOS
ProductVersion: 11.3
BuildVersion: 20E232
What compiler and version are you using?
$ c++ --version
Apple clang version 12.0.5 (clang-1205.0.22.9)
Target: arm64-apple-darwin20.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
What build system are you using?
cmake version 3.20.2
Additional context
This is on a Mac mini M1
Looks like the default language version is not what I'd expect it to be:
$ cat test.cc
#include <iostream>
int main() {
std::cout << __cplusplus << "\n";
}
$ c++ -o test test.cc && ./test
199711 # <---
$ c++ -std=c++17 -o test test.cc && ./test
201703
And from man c++
The default C++ language standard is gnu++14
Huh.
Note setting -DCMAKE_CXX_STANDARD=11 on the cmake configure line seems to work.
This may be working as intended. I'm not sure. I don't understand the output of https://github.com/abseil/abseil-cpp/issues/955#issuecomment-831599980. And it would be nice if Abseil Just Worked w/ the naive cmake invocation above without explicitly specifying the language version, but I could see an argument for WAI here. I'll leave this open in case the Abseil folks have any thoughts/comments.
I don't know if it is feasible to both get this to work with a naive cmake invocation and still have Abseil work as intended.
If you are a programmer, due to nature of Abseil, understanding which C++ dialect is being used is pretty fundamental and needs to be a conscious choice. The C++ dialect needs to be consistently set between the libraries being compiled/linked together (unless you really know what you are doing). If the person building Abseil isn't making a conscious choice of C++ dialect, it seems to me that using the default is the only reasonable choice, since the best guess is that everything else is also being built with the default.
If you are just a user who needs to install Abseil, you might not know what a C++ dialect is. In that case, we really just want to naive cmake invocation to work.
I don't know how to reconcile these issues.
I think you're probably right about relying on the default. I think a reasonable solution may be to just document how to build and install this on macos. The doc can say that on macOS the user needs to select the C++ language standard to use for reasons, and they can compile with something like
cmake -DCMAKE_CXX_STANDARD=17 -DCMAKE_INSTALL_PREFIX=/foo/bar -S . -B cmake-out
cmake --build cmake-out
cmake --build cmake-out --target install