Skip to content

Commit a2f1bcb

Browse files
authored
[cherry-pick] Support cmake configure when system exists multiple cuda versions. (#1760)
* update cmake * typos
1 parent 44b144f commit a2f1bcb

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

cmake/cuda.cmake

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,37 @@ if (MSVC OR (NOT DEFINED CMAKE_CUDA_RUNTIME_LIBRARY))
1111
set(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
1212
endif ()
1313

14+
if (MSVC)
15+
# no plugin in BuildCustomizations and no specify cuda toolset
16+
if (NOT CMAKE_VS_PLATFORM_TOOLSET_CUDA)
17+
message(FATAL_ERROR "Please install CUDA MSBuildExtensions")
18+
endif ()
19+
20+
if (CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR)
21+
# find_package(CUDA) required ENV{CUDA_PATH}
22+
set(ENV{CUDA_PATH} ${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR})
23+
else ()
24+
# we use CUDA_PATH and ignore nvcc.exe
25+
# cmake will import highest cuda props version, which may not equal to CUDA_PATH
26+
if (NOT (DEFINED ENV{CUDA_PATH}))
27+
message(FATAL_ERROR "Please set CUDA_PATH environment variable")
28+
endif ()
29+
30+
string(REGEX REPLACE ".*v([0-9]+)\\..*" "\\1" _MAJOR $ENV{CUDA_PATH})
31+
string(REGEX REPLACE ".*v[0-9]+\\.([0-9]+).*" "\\1" _MINOR $ENV{CUDA_PATH})
32+
if (NOT (${CMAKE_VS_PLATFORM_TOOLSET_CUDA} STREQUAL "${_MAJOR}.${_MINOR}"))
33+
message(FATAL_ERROR "Auto detected cuda version ${CMAKE_VS_PLATFORM_TOOLSET_CUDA}"
34+
" is mismatch with ENV{CUDA_PATH} $ENV{CUDA_PATH}. Please modify CUDA_PATH"
35+
" to match ${CMAKE_VS_PLATFORM_TOOLSET_CUDA} or specify cuda toolset by"
36+
" cmake -T cuda=/path/to/cuda ..")
37+
endif ()
38+
39+
if (NOT (DEFINED ENV{CUDA_PATH_V${_MAJOR}_${_MINOR}}))
40+
message(FATAL_ERROR "Please set CUDA_PATH_V${_MAJOR}_${_MINOR} environment variable")
41+
endif ()
42+
endif ()
43+
endif ()
44+
1445
# nvcc compiler settings
1546
find_package(CUDA REQUIRED)
1647

cmake/tensorrt.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ else ()
2929
message(FATAL_ERROR "Cannot find TensorRT libs")
3030
endif ()
3131

32+
include(FindPackageHandleStandardArgs)
3233
find_package_handle_standard_args(TENSORRT DEFAULT_MSG TENSORRT_INCLUDE_DIR
3334
TENSORRT_LIBRARY)
3435
if (NOT TENSORRT_FOUND)

0 commit comments

Comments
 (0)