Fail better if enable_language() invoked before a project is defined
If we configure using the following CMakeLists.txt
:
cmake_minimum_required(VERSION 3.25)
enable_language(CUDA)
# Note: if we move the projct command here, all is fine
include(FindCUDA/select_compute_arch)
CUDA_DETECT_INSTALLED_GPUS(INSTALLED_GPU_CCS_1)
project(foo CUDA)
We get:
CMake Error at /path/to/cmake/3.28.1/share/cmake-3.28/Modules/FindCUDA/select_compute_arch.cmake:120 (file):
file failed to open for writing (Permission denied):
/detect_cuda_compute_capabilities.cu
Call Stack (most recent call first):
CMakeLists.txt:5 (CUDA_DETECT_INSTALLED_GPUS)
and some additional errors. Now, the problematic file is defined as:
"${PROJECT_BINARY_DIR}/detect_cuda_compute_capabilities.cu
which sort-of assumes ${PROJECT_BINARY_DIR} is not empty. Yet - it is empty before a project has been defined. edit: Since, apparently, enabling languages before a project is defined is unsupported, then the enable_language(CUDA)
command should be failing immediately, with the error saying that it can't be invoked with no project defined; the half-hearted effort doomed to fail is confusing to users.
Edited by Eyal Rozenberg