[C++] CMake Configuration Broken When Setting CMAKE_CXX_COMPILER=clang++
- Dominant language
- C++
- Stars
- 17.1k
- Forks
- 4.3k
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 88
Description
### Describe the bug, including details regarding any error messages, version, and platform.
If you add `-DCMAKE_CXX_COMPILER=clang++` you get a rather confusing error message about the threads library not being found:
```bash
$ cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G Ninja -DARROW_COMPUTE=ON -DARROW_BUILD_TESTS=ON -DCMAKE_CXX_COMPILER=clang++
CMake Error at /usr/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
/usr/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.28/Modules/FindThreads.cmake:226 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
cmake_modules/ThirdpartyToolchain.cmake:1050 (find_package)
CMakeLists.txt:546 (include)
```
If you look at the CMake configuration log, you will see that the error actually doesn't have anything to do with thread support, but rather with the C compiler (in my case gcc) being provided arguments that only work with clang:
```yaml
---
events:
kind: "try_compile-v1"
backtrace:
- "/usr/share/cmake-3.28/Modules/Internal/CheckSourceCompiles.cmake:101 (try_compile)"
- "/usr/share/cmake-3.28/Modules/CheckCSourceCompiles.cmake:52 (cmake_check_source_compiles)"
- "/usr/share/cmake-3.28/Modules/FindThreads.cmake:97 (CHECK_C_SOURCE_COMPILES)"
- "/usr/share/cmake-3.28/Modules/FindThreads.cmake:163 (_threads_check_libc)"
- "cmake_modules/ThirdpartyToolchain.cmake:1050 (find_package)"
- "CMakeLists.txt:546 (include)"
checks:
- "Performing Test CMAKE_HAVE_LIBC_PTHREAD"
directories:
source: "/home/willayd/clones/arrow/cpp/build/CMakeFiles/CMakeScratch/TryCompile-C4sSBS"
binary: "/home/willayd/clones/arrow/cpp/build/CMakeFiles/CMakeScratch/TryCompile-C4sSBS"
cmakeVariables:
CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS: "/usr/bin/clang-scan-deps-18"
CMAKE_C_FLAGS: "-O0 -O0 -Qunused-arguments"
CMAKE_C_FLAGS_DEBUG: "-g -Werror -O0 -ggdb "
CMAKE_EXE_LINKER_FLAGS: ""
CMAKE_MODULE_PATH: "/home/willayd/clones/arrow/cpp/cmake_modules"
CMAKE_POSITION_INDEPENDENT_CODE: "ON"
buildResult:
variable: "CMAKE_HAVE_LIBC_PTHREAD"
cached: true
stdout: |
Change Dir: '/home/willayd/clones/arrow/cpp/build/CMakeFiles/CMakeScratch/TryCompile-C4sSBS'
Run Build Command(s): /usr/bin/ninja -v cmTC_500bc
[1/2] /usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD -O0 -O0 -Qunused-arguments -std=gnu11 -fPIE -o CMakeFiles/cmTC_500bc.dir/src.c.o -c /home/willayd/clones/arrow/cpp/build/CMakeFiles/CMakeScratch/TryCompile-C4sSBS/src.c
FAILED: CMakeFiles/cmTC_500bc.dir/src.c.o
/usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD -O0 -O0 -Qunused-arguments -std=gnu11 -fPIE -o CMakeFiles/cmTC_500bc.dir/src.c.o -c /home/willayd/clones/arrow/cpp/build/CMakeFiles/CMakeScratch/TryCompile-C4sSBS/src.c
cc: error: unrecognized command-line option ‘-Qunused-arguments’
ninja: build stopped: subcommand failed.
exitCode: 1
```
### Component(s)
C++
Contributor guide
Assessment
This issue has not been assessed yet.