| Issue |
61432
|
| Summary |
Cross-compiling from macOS host fails CheckAtomics cmake test
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
eggyal
|
When cross-compiling LLVM on macOS host (in my case, for Linux target) cmake fails:
```text
% cmake /path/to/llvm \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=x86_64 \
-DCMAKE_C_COMPILER=x86_64-unknown-linux-gnu-gcc \
-DCMAKE_CXX_COMPILER=x86_64-unknown-linux-gnu-g++ \
-DCMAKE_BUILD_TYPE=Release
[snip]
-- Performing Test HAVE_CXX_ATOMICS_WITH_LIB - Failed
CMake Error at cmake/modules/CheckAtomic.cmake:56 (message):
Host compiler must support std::atomic!
Call Stack (most recent call first):
cmake/config-ix.cmake:411 (include)
CMakeLists.txt:776 (include)
```
Relevant from `CMakeFiles/CMakeError.log`:
```text
Performing C++ SOURCE FILE Test HAVE_CXX_ATOMICS_WITH_LIB failed with the following output:
Change Dir: /path/to/build/CMakeFiles/CMakeScratch/TryCompile-lNXSZR
Run Build Command(s):/usr/bin/make -f Makefile cmTC_b0c0b/fast && /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/cmTC_b0c0b.dir/build.make CMakeFiles/cmTC_b0c0b.dir/build
Building CXX object CMakeFiles/cmTC_b0c0b.dir/src.cxx.o
/usr/local/bin/x86_64-unknown-linux-gnu-g++ -DHAVE_CXX_ATOMICS_WITH_LIB -std=c++11 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk -std=c++14 -o CMakeFiles/cmTC_b0c0b.dir/src.cxx.o -c /path/to/build/CMakeFiles/CMakeScratch/TryCompile-lNXSZR/src.cxx
In file included from /usr/local/Cellar/x86_64-unknown-linux-gnu/7.2.0/toolchain/x86_64-unknown-linux-gnu/include/c++/7.2.0/x86_64-unknown-linux-gnu/bits/c++config.h:533:0,
from /usr/local/Cellar/x86_64-unknown-linux-gnu/7.2.0/toolchain/x86_64-unknown-linux-gnu/include/c++/7.2.0/bits/atomic_base.h:35,
from /usr/local/Cellar/x86_64-unknown-linux-gnu/7.2.0/toolchain/x86_64-unknown-linux-gnu/include/c++/7.2.0/atomic:41,
from /path/to/build/CMakeFiles/CMakeScratch/TryCompile-lNXSZR/src.cxx:2:
/usr/local/Cellar/x86_64-unknown-linux-gnu/7.2.0/toolchain/x86_64-unknown-linux-gnu/include/c++/7.2.0/x86_64-unknown-linux-gnu/bits/os_defines.h:39:10: fatal error: features.h: No such file or directory
#include <features.h>
^~~~~~~~~~~~
compilation terminated.
make[1]: *** [CMakeFiles/cmTC_b0c0b.dir/src.cxx.o] Error 1
make: *** [cmTC_b0c0b/fast] Error 2
Source file was:
#include <atomic>
std::atomic<int> x;
std::atomic<short> y;
std::atomic<char> z;
int main() {
++z;
++y;
return ++x;
}
```
I note in particular that the C++ compiler was invoked with `-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk`. However, I don't think this option should be present when compiling for a non-Darwin target? Indeed if it is removed, the compilation succeeds:
```
% cat src.cxx
#include <atomic>
std::atomic<int> x;
std::atomic<short> y;
std::atomic<char> z;
int main() {
++z;
++y;
return ++x;
}
% x86_64-unknown-linux-gnu-g++ -DHAVE_CXX_ATOMICS_WITH_LIB -std=c++11 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk -std=c++14 -c src.cxx
In file included from /usr/local/Cellar/x86_64-unknown-linux-gnu/7.2.0/toolchain/x86_64-unknown-linux-gnu/include/c++/7.2.0/x86_64-unknown-linux-gnu/bits/c++config.h:533:0,
from /usr/local/Cellar/x86_64-unknown-linux-gnu/7.2.0/toolchain/x86_64-unknown-linux-gnu/include/c++/7.2.0/bits/atomic_base.h:35,
from /usr/local/Cellar/x86_64-unknown-linux-gnu/7.2.0/toolchain/x86_64-unknown-linux-gnu/include/c++/7.2.0/atomic:41,
from src.cxx:1:
/usr/local/Cellar/x86_64-unknown-linux-gnu/7.2.0/toolchain/x86_64-unknown-linux-gnu/include/c++/7.2.0/x86_64-unknown-linux-gnu/bits/os_defines.h:39:10: fatal error: features.h: No such file or directory
#include <features.h>
^~~~~~~~~~~~
compilation terminated.
% x86_64-unknown-linux-gnu-g++ -DHAVE_CXX_ATOMICS_WITH_LIB -std=c++11 -std=c++14 -c src.cxx && echo success
success
```
In a fresh CMake project using LLVM's `CheckAtomics` module, the `-isysroot` option isn't present... so it seems that LLVM's CMake project is responsible here.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs