CUDA: Visual Studio generators do not provide implicit link/include dirs
Hello,
I have read #19029 (closed) and none of the fixes/problems discussed there seem to be associated with this issue.
I have a cmake project that builds a CUDA static library using nvcc. The static library is then linked with .cpp files using the native OS compiler (cl.exe on Windows) to create executables.
The project works just fine when generating "Unix Makefiles". However it fails to generate a VS 2017 solution. The executables need to be linked with cudart therefore I follow this SO approach
One can compile native .cpp executables linked with CUDA static libraries by following this approach:
find_library(CUDART_LIBRARY cudart ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
add_executable(main main.cpp)
target_include_directories(main PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
target_link_libraries(main some_cuda_static_lib ${CUDART_LIBRARY})
However the variables ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES} and ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES} are empty (NOTFOUND)! When generating makefiles these variables get assigned properly. Why? Here is cmake output when generating VS 2017 sln:
cmake -G "Visual Studio 15 2017" -A x64 ..
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.17134.
-- The CXX compiler identification is MSVC 19.16.27030.1
-- The CUDA compiler identification is NVIDIA 10.1.105
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/nvcc.exe
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/nvcc.exe -- works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES:
-- CMAKE_CUDA_FLAGS: -D_WINDOWS -Xcompiler="/W3 /GR /EHsc" -arch=sm_50
CMake Warning (dev) at CMakeLists.txt:9 (find_package):
Policy CMP0074 is not set: find_package uses <PackageName>_ROOT variables.
Run "cmake --help-policy CMP0074" for policy details. Use the cmake_policy
command to set the policy and suppress this warning.
Environment variable Boost_ROOT is set to:
C:\Program Files\boost\boost_1_70_0
For compatibility, CMake is ignoring the variable.
This warning is for project developers. Use -Wno-dev to suppress it.
-- Boost version: 1.70.0
-- The C compiler identification is MSVC 19.16.27030.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDART_LIBRARY
linked by target "keysSample" in directory .../samples
linked by target "longKeysSample" in directory .../samples
linked by target "benchmarks" in directory .../benchmarks
linked by target "tests" in directory .../test
-- Configuring incomplete, errors occurred!
I have a fully updated Win10, VS2017 environment using cmake ver. 3.14.3 and CUDA 10.1. (I have only one Visual Studio installed)
Feel free to try to generate a VS 2017 solution by cloning this repository on GitHub