Merge pull request #27112 from cudawarped:add_cuda_c++17

cuda: Force C++17 Standard for CUDA targets when CUDA Toolkit >=12.8 #27112

Fix https://github.com/opencv/opencv/issues/27095.

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
cudawarped 2025-03-21 13:41:49 +02:00 committed by GitHub
parent afc4a9ac51
commit 1d9dda3f09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View File

@ -151,12 +151,14 @@ macro(ocv_cuda_compile VAR)
ocv_check_windows_crt_linkage() ocv_check_windows_crt_linkage()
ocv_nvcc_flags() ocv_nvcc_flags()
if(UNIX OR APPLE) if(NOT " ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_DEBUG} ${CUDA_NVCC_FLAGS}" MATCHES "-std=")
if(NOT " ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_DEBUG} ${CUDA_NVCC_FLAGS}" MATCHES "-std=") if(UNIX OR APPLE)
if(CUDA_VERSION VERSION_LESS "11.0") if(CUDA_VERSION VERSION_LESS "11.0")
list(APPEND CUDA_NVCC_FLAGS "--std=c++11") list(APPEND CUDA_NVCC_FLAGS "--std=c++11")
else() elseif(CUDA_VERSION VERSION_LESS "12.8")
list(APPEND CUDA_NVCC_FLAGS "--std=c++14") list(APPEND CUDA_NVCC_FLAGS "--std=c++14")
elseif(CUDA_VERSION VERSION_GREATER_EQUAL "12.8")
list(APPEND CUDA_NVCC_FLAGS "--std=c++17")
endif() endif()
endif() endif()
endif() endif()

View File

@ -33,10 +33,12 @@ if(CMAKE_CUDA_COMPILER AND CUDAToolkit_FOUND)
set(CUDA_TOOLKIT_INCLUDE ${CUDAToolkit_INCLUDE_DIRS}) set(CUDA_TOOLKIT_INCLUDE ${CUDAToolkit_INCLUDE_DIRS})
set(CUDA_VERSION_STRING ${CUDAToolkit_VERSION}) set(CUDA_VERSION_STRING ${CUDAToolkit_VERSION})
set(CUDA_VERSION ${CUDAToolkit_VERSION}) set(CUDA_VERSION ${CUDAToolkit_VERSION})
if(NOT CUDA_VERSION VERSION_LESS 11.0) if(CUDA_VERSION VERSION_LESS 11.0)
set(CMAKE_CUDA_STANDARD 11)
elseif(CUDA_VERSION VERSION_LESS 12.8)
set(CMAKE_CUDA_STANDARD 14) set(CMAKE_CUDA_STANDARD 14)
else() else()
set(CMAKE_CUDA_STANDARD 11) set(CMAKE_CUDA_STANDARD 17)
endif() endif()
if(UNIX AND NOT BUILD_SHARED_LIBS) if(UNIX AND NOT BUILD_SHARED_LIBS)
set(CUDA_LIB_EXT "_static") set(CUDA_LIB_EXT "_static")