CMake: `try_compile` source file syntax doesn't respect CMAKE_EXECUTABLE_SUFFIX
Minimal repro case:
cmake_minimum_required(VERSION 3.24.1)
project(foo LANGUAGES)
set(CMAKE_EXECUTABLE_SUFFIX "-dbg${CMAKE_EXECUTABLE_SUFFIX}")
set(CMAKE_CUDA_ARCHITECTURES native)
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
message(STATUS "CUDA enabled")
else()
message(FATAL_ERROR "CUDA not available")
endif()
Output of cmake -B build -S .
:
-- Looking for a CUDA compiler
-- Looking for a CUDA compiler - /opt/cuda/bin/nvcc
-- The CUDA compiler identification is NVIDIA 11.7.99
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - failed
-- Check for working CUDA compiler: /opt/cuda/bin/nvcc
CMake Error in /home/lahwaacz/stuff/build/CMakeFiles/CMakeTmp/CMakeLists.txt:
CUDA_ARCHITECTURES is set to "native", but no GPU was detected.
CMake Error in /home/lahwaacz/stuff/build/CMakeFiles/CMakeTmp/CMakeLists.txt:
CUDA_ARCHITECTURES is set to "native", but no GPU was detected.
CMake Error at /usr/share/cmake/Modules/CMakeTestCUDACompiler.cmake:89 (try_compile):
Failed to generate test project build system.
Call Stack (most recent call first):
CMakeLists.txt:8 (enable_language)
-- Configuring incomplete, errors occurred!
See also "/home/lahwaacz/stuff/build/CMakeFiles/CMakeOutput.log".
See also "/home/lahwaacz/stuff/build/CMakeFiles/CMakeError.log".
But the system actually has a GPU as reported by nvidia-smi
:
Wed Aug 24 20:34:44 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 515.65.01 Driver Version: 515.65.01 CUDA Version: 11.7 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... Off | 00000000:02:00.0 Off | N/A |
| 27% 33C P8 5W / 120W | 197MiB / 6144MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 549 G /usr/lib/Xorg 154MiB |
| 0 N/A N/A 956 G /usr/bin/sddm-greeter 38MiB |
+-----------------------------------------------------------------------------+
The issue does not appear when CMAKE_EXECUTABLE_SUFFIX
is empty.
Related to #23874, #19636 (closed)
Edited by Robert Maynard