Skip to content

Commit

Permalink
[CMake] Fix ordering problem when checking and setting cuda flag
Browse files Browse the repository at this point in the history
In the ROOT build system, `CheckCompiler` is included before
`RootBuildOptions`. The problem with this is that when building with
`-Dall=ON`, the `cuda` flag is only set in `RootBuildOptions`, which is
too late to find the CUDA compiler in `CheckCompiler`. This results in
issues like root-project#15139:
```
CMake Error in roofit/batchcompute/CMakeLists.txt:
  Exporting the target "RooBatchCompute_CUDA" is not allowed since its linker
  language cannot be determined
```

This commit suggests a solution to this problem: just always enable the
CUDA language in CMake if it is found, and only set the `cuda` flag with
`-Dall=ON` if the CUDA language is enabled.
  • Loading branch information
guitargeek authored and kristupaspranc committed Apr 9, 2024
1 parent b137048 commit e188c6b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
18 changes: 7 additions & 11 deletions cmake/modules/CheckCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,14 @@ else()
set(CMAKE_Fortran_COMPILER CMAKE_Fortran_COMPILER-NOTFOUND)
endif()

#---Enable CUDA ---
if(cuda)
check_language(CUDA)
if (CMAKE_CUDA_COMPILER)
enable_language(CUDA)
if(NOT DEFINED CMAKE_CUDA_STANDARD)
set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD})
endif()
else()
message(FATAL_ERROR "CUDA not found. Ensure that the installation of CUDA is in the CMAKE_PREFIX_PATH, or disable CUDA features in ROOT with -Dcuda=OFF")
#---Enable CUDA if found on the system---
check_language(CUDA)
if (CMAKE_CUDA_COMPILER)
enable_language(CUDA)
if(NOT DEFINED CMAKE_CUDA_STANDARD)
set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD})
endif()
endif(cuda)
endif()

#----Test if clang setup works----------------------------------------------------------------------
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
Expand Down
11 changes: 4 additions & 7 deletions cmake/modules/RootBuildOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ if(all)
set(asimage_defvalue ON)
set(cefweb_defvalue ON)
set(clad_defvalue ON)
set(cuda_defvalue ON)
set(dataframe_defvalue ON)
set(test_distrdf_pyspark_defvalue ON)
set(test_distrdf_dask_defvalue ON)
Expand Down Expand Up @@ -255,7 +254,6 @@ if(all)
set(ssl_defvalue ON)
set(tmva_defvalue ON)
set(tmva-cpu_defvalue ON)
set(tmva-gpu_defvalue ON)
set(tmva-pymva_defvalue ON)
set(tmva-rmva_defvalue ON)
set(unuran_defvalue ON)
Expand All @@ -266,6 +264,10 @@ if(all)
set(x11_defvalue ON)
set(xml_defvalue ON)
set(xrootd_defvalue ON)
if(CMAKE_CUDA_COMPILER)
set(cuda_defvalue ON)
set(tmva-gpu_defvalue ON)
endif()
endif()

#--- The 'builtin_all' option switches ON all the built in options but GPL-------------------------------
Expand Down Expand Up @@ -367,11 +369,6 @@ if(roottest OR rootbench)
set(testing ON CACHE BOOL "" FORCE)
endif()

#---tmva-gpu option implies cuda
if(tmva-gpu)
set(cuda ON CACHE BOOL "" FORCE)
endif(tmva-gpu)

if(cudnn AND NOT cuda)
message(STATUS "Cannot enable cudnn without enabling cuda or tmva-gpu: cudnn is disabled.")
set(cudnn OFF)
Expand Down

0 comments on commit e188c6b

Please sign in to comment.