VS: Add support for determining CUDA compiler id

Teach `CMakeDetermineCompilerId` how to generate a vcxproj file using
the `CMAKE_VS_PLATFORM_TOOLSET_CUDA`.
This commit is contained in:
Brad King 2017-03-07 14:32:35 -05:00
parent 80e982d7ad
commit 82521e359f
2 changed files with 43 additions and 20 deletions

View File

@ -5,36 +5,40 @@ include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
include(${CMAKE_ROOT}/Modules//CMakeParseImplicitLinkInfo.cmake)
if( NOT ( ("${CMAKE_GENERATOR}" MATCHES "Make") OR
("${CMAKE_GENERATOR}" MATCHES "Ninja") ) )
("${CMAKE_GENERATOR}" MATCHES "Ninja") OR
("${CMAKE_GENERATOR}" MATCHES "Visual Studio (1|[7-9][0-9])") ) )
message(FATAL_ERROR "CUDA language not currently supported by \"${CMAKE_GENERATOR}\" generator")
endif()
if(NOT CMAKE_CUDA_COMPILER)
set(CMAKE_CUDA_COMPILER_INIT NOTFOUND)
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
else()
if(NOT CMAKE_CUDA_COMPILER)
set(CMAKE_CUDA_COMPILER_INIT NOTFOUND)
# prefer the environment variable CUDACXX
if(NOT $ENV{CUDACXX} STREQUAL "")
get_filename_component(CMAKE_CUDA_COMPILER_INIT $ENV{CUDACXX} PROGRAM PROGRAM_ARGS CMAKE_CUDA_FLAGS_ENV_INIT)
if(CMAKE_CUDA_FLAGS_ENV_INIT)
set(CMAKE_CUDA_COMPILER_ARG1 "${CMAKE_CUDA_FLAGS_ENV_INIT}" CACHE STRING "First argument to CXX compiler")
endif()
if(NOT EXISTS ${CMAKE_CUDA_COMPILER_INIT})
message(FATAL_ERROR "Could not find compiler set in environment variable CUDACXX:\n$ENV{CUDACXX}.\n${CMAKE_CUDA_COMPILER_INIT}")
# prefer the environment variable CUDACXX
if(NOT $ENV{CUDACXX} STREQUAL "")
get_filename_component(CMAKE_CUDA_COMPILER_INIT $ENV{CUDACXX} PROGRAM PROGRAM_ARGS CMAKE_CUDA_FLAGS_ENV_INIT)
if(CMAKE_CUDA_FLAGS_ENV_INIT)
set(CMAKE_CUDA_COMPILER_ARG1 "${CMAKE_CUDA_FLAGS_ENV_INIT}" CACHE STRING "First argument to CXX compiler")
endif()
if(NOT EXISTS ${CMAKE_CUDA_COMPILER_INIT})
message(FATAL_ERROR "Could not find compiler set in environment variable CUDACXX:\n$ENV{CUDACXX}.\n${CMAKE_CUDA_COMPILER_INIT}")
endif()
endif()
# finally list compilers to try
if(NOT CMAKE_CUDA_COMPILER_INIT)
set(CMAKE_CUDA_COMPILER_LIST nvcc)
endif()
# finally list compilers to try
if(NOT CMAKE_CUDA_COMPILER_INIT)
set(CMAKE_CUDA_COMPILER_LIST nvcc)
_cmake_find_compiler(CUDA)
else()
_cmake_find_compiler_path(CUDA)
endif()
_cmake_find_compiler(CUDA)
else()
_cmake_find_compiler_path(CUDA)
mark_as_advanced(CMAKE_CUDA_COMPILER)
endif()
mark_as_advanced(CMAKE_CUDA_COMPILER)
#Allow the user to specify a host compiler
set(CMAKE_CUDA_HOST_COMPILER "" CACHE FILEPATH "Host compiler to be used by nvcc")
if(NOT $ENV{CUDAHOSTCXX} STREQUAL "")
@ -75,7 +79,12 @@ if(MSVC_CUDA_ARCHITECTURE_ID)
"set(MSVC_CUDA_ARCHITECTURE_ID ${MSVC_CUDA_ARCHITECTURE_ID})")
endif()
if(CMAKE_CUDA_COMPILER_ID STREQUAL NVIDIA)
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
set(CMAKE_CUDA_HOST_LINK_LAUNCHER "${CMAKE_LINKER}")
set(CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES "")
set(CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES "")
set(CMAKE_CUDA_HOST_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "")
elseif(CMAKE_CUDA_COMPILER_ID STREQUAL NVIDIA)
set(_nvcc_log "")
string(REPLACE "\r" "" _nvcc_output_orig "${CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT}")
if(_nvcc_output_orig MATCHES "#\\\$ +LIBRARIES= *([^\n]*)\n")

View File

@ -241,6 +241,20 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS}
set(id_Import_targets "")
set(id_ItemDefinitionGroup_entry "")
set(id_Link_AdditionalDependencies "")
if(lang STREQUAL CUDA)
if(NOT CMAKE_VS_PLATFORM_TOOLSET_CUDA)
message(FATAL_ERROR "No CUDA toolset found.")
endif()
set(cuda_tools "CUDA ${CMAKE_VS_PLATFORM_TOOLSET_CUDA}")
set(id_compile "CudaCompile")
set(id_PostBuildEvent_Command [[echo CMAKE_CUDA_COMPILER=$(CudaToolkitBinDir)\nvcc.exe]])
string(CONCAT id_Import_props [[<Import Project="$(VCTargetsPath)\BuildCustomizations\]] "${cuda_tools}" [[.props" />]])
string(CONCAT id_Import_targets [[<Import Project="$(VCTargetsPath)\BuildCustomizations\]] "${cuda_tools}" [[.targets" />]])
if(CMAKE_VS_PLATFORM_NAME STREQUAL x64)
set(id_ItemDefinitionGroup_entry "<CudaCompile><TargetMachinePlatform>64</TargetMachinePlatform></CudaCompile>")
endif()
set(id_Link_AdditionalDependencies "<AdditionalDependencies>cudart.lib</AdditionalDependencies>")
endif()
configure_file(${CMAKE_ROOT}/Modules/CompilerId/VS-${v}.${ext}.in
${id_dir}/CompilerId${lang}.${ext} @ONLY)
if(CMAKE_VS_MSBUILD_COMMAND AND NOT lang STREQUAL "Fortran")