首页 > 解决方案 > 缺少的变量是:CMAKE_CUDA_COMPILE_WHOLE_COMPILATION

问题描述

我正在尝试使用 CMake 来编译使用 cuda 的库。

我希望 cuda 是可选的,即如果系统上没有 nvcc,我希望我的库能够编译。

以下是我检查 CMake 中是否提供 cuda 的方法:

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 ()

以下是我设置的环境变量:

$> env | grep CXX
CUDAHOSTCXX=/usr/bin/g++-6
CUDACXX=/usr/bin/nvcc
CXX=/usr/bin/g++

这是 cmake 命令的输出:

$> 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.

我没有找到任何有用的关于 CMAKE_CUDA_COMPILE_WHOLE_COMPILATION 的东西。

我怎样才能使这个 cmake 工作?我错过了什么?

标签: cmakecuda

解决方案


我只是找出问题所在...

我在调用一个函数

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

我仍然不知道如何将 enable_cuda_if_available 设置的所有变量自动转发到父范围


推荐阅读