summaryrefslogtreecommitdiff
path: root/Modules/FindCUDA
diff options
context:
space:
mode:
authorBjoern Thiel <bjoern.thiel@mpibpc.mpg.de>2017-01-25 09:45:18 +0100
committerBrad King <brad.king@kitware.com>2017-01-25 10:31:27 -0500
commitc1f3086de70793ee5552986347291d814b796232 (patch)
treecb495cf3693b3d8d15b668bf363edb3ee2124557 /Modules/FindCUDA
parenta007f15344007a6261209a409c6988b0e4c4b7e0 (diff)
downloadcmake-c1f3086de70793ee5552986347291d814b796232.tar.gz
FindCUDA: Enable CUDA_SELECT_NVCC_ARCH_FLAGS Auto for MSVC
Fixes: #16525
Diffstat (limited to 'Modules/FindCUDA')
-rw-r--r--Modules/FindCUDA/select_compute_arch.cmake20
1 files changed, 11 insertions, 9 deletions
diff --git a/Modules/FindCUDA/select_compute_arch.cmake b/Modules/FindCUDA/select_compute_arch.cmake
index 5ce71a9103..19fc14f3f4 100644
--- a/Modules/FindCUDA/select_compute_arch.cmake
+++ b/Modules/FindCUDA/select_compute_arch.cmake
@@ -44,9 +44,10 @@ endif ()
#
function(CUDA_DETECT_INSTALLED_GPUS OUT_VARIABLE)
if(NOT CUDA_GPU_DETECT_OUTPUT)
- set(cufile ${PROJECT_BINARY_DIR}/detect_cuda_archs.cu)
+ set(file ${PROJECT_BINARY_DIR}/detect_cuda_compute_capabilities.cpp)
- file(WRITE ${cufile} ""
+ file(WRITE ${file} ""
+ "#include <cuda_runtime.h>\n"
"#include <cstdio>\n"
"int main()\n"
"{\n"
@@ -62,14 +63,15 @@ function(CUDA_DETECT_INSTALLED_GPUS OUT_VARIABLE)
" return 0;\n"
"}\n")
- execute_process(COMMAND "${CUDA_NVCC_EXECUTABLE}" "--run" "${cufile}"
- WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/CMakeFiles/"
- RESULT_VARIABLE nvcc_res OUTPUT_VARIABLE nvcc_out
- ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
+ try_run(run_result compile_result ${PROJECT_BINARY_DIR} ${file}
+ CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${CUDA_INCLUDE_DIRS}"
+ LINK_LIBRARIES ${CUDA_LIBRARIES}
+ RUN_OUTPUT_VARIABLE compute_capabilities)
- if(nvcc_res EQUAL 0)
- string(REPLACE "2.1" "2.1(2.0)" nvcc_out "${nvcc_out}")
- set(CUDA_GPU_DETECT_OUTPUT ${nvcc_out} CACHE INTERNAL "Returned GPU architetures from detect_gpus tool" FORCE)
+ if(run_result EQUAL 0)
+ string(REPLACE "2.1" "2.1(2.0)" compute_capabilities "${compute_capabilities}")
+ set(CUDA_GPU_DETECT_OUTPUT ${compute_capabilities}
+ CACHE INTERNAL "Returned GPU architetures from detect_gpus tool" FORCE)
endif()
endif()