Reputation: 451
I am trying to use CMake to compile a library using cuda.
I want cuda to be optional, i.e. I want my library to compile if nvcc is not available on the system.
Here is how I am checking if cuda is available in my CMake:
include(CheckLanguage)
check_language(CUDA)
if (CMAKE_CUDA_COMPILER)
enable_language(CUDA)
else()
message(WARNING "CUDA not found: GPU features won't be available.")
endif ()
Here are the environment variables I am setting:
$> env | grep CXX
CUDAHOSTCXX=/usr/bin/g++-6
CUDACXX=/usr/bin/nvcc
CXX=/usr/bin/g++
Here is the output of the cmake command:
$> cmake ..
-- The CXX compiler identification is GNU 7.4.0
-- Check for working CXX compiler: /usr/bin/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for a CUDA compiler
-- Looking for a CUDA compiler - /usr/bin/nvcc
-- The CUDA compiler identification is NVIDIA 9.1.85
-- Check for working CUDA compiler: /usr/bin/nvcc
-- Check for working CUDA compiler: /usr/bin/nvcc -- works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Configuring done
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_CUDA_COMPILE_WHOLE_COMPILATION
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
I am not finding anything usefull conserning CMAKE_CUDA_COMPILE_WHOLE_COMPILATION.
How can I make this cmake works? What did I missed?
Upvotes: 2
Views: 2237
Reputation: 451
I just fingure out what the problem was...
I was calling a function
function(enable_cuda_if_available)
# Here CUDA is properly found and variable are correctly set
include(CheckLanguage)
check_language(CUDA)
if (CMAKE_CUDA_COMPILER)
enable_language(CUDA)
else ()
message(WARNING "CUDA not found: GPU features won't be available.")
endif ()
endfunction()
enable_cuda_if_available()
# Here CUDA's variables have not been forwarded to the parent scope and leading to an error
I still don't know how to automatically forward all variables set by enable_cuda_if_available to the parent scope
Upvotes: 2