I'm trying to compile some coda using CUDA with MakeFiles generated by CMake.
I'd like to use CHECK_CXX_COMPILER_FLAG or something similar to check if the used nvcc version supports a given flag. In my case it is "--expt-relaxed-constexpr" (Cuda 7.5) and "--relaxed-constexpr" (Cuda 7?)
Of course I could compare the CUDA version but I find the compile-flag check more fail-safe.
Is there any CMake command similar to CHECK_CXX_COMPILER_FLAG that invokes the nvcc compiler and not the host compiler?
I am not aware of an official way to check for a specific nvcc
flag, but you can write a macro yourself rather simply:
CheckNvccCompilerFlag.cmake
MACRO(CHECK_NVCC_COMPILER_FLAG _FLAG _RESULT)
EXECUTE_PROCESS(COMMAND ${CUDA_NVCC_EXECUTABLE} "${_FLAG}" ERROR_VARIABLE NVCC_OUT)
IF("${NVCC_OUT}" MATCHES "Unknown option")
SET(${_RESULT} 0)
ELSE()
SET(${_RESULT} 1)
ENDIF()
ENDMACRO()
A demo use:
CMakeList.txt
PROJECT(cuda_flag_test)
FIND_PACKAGE(CUDA)
INCLUDE(CheckNvccCompilerFlag.cmake)
CHECK_NVCC_COMPILER_FLAG("--asdf" HAS_NVCC_ASDF)
IF(HAS_NVCC_ASDF)
MESSAGE(STATUS "asdf is supported")
ENDIF()
CHECK_NVCC_COMPILER_FLAG("--relaxed-constexpr" HAS_NVCC_RELAXED_CONSTEXPR)
IF(HAS_NVCC_RELAXED_CONSTEXPR)
MESSAGE(STATUS "relaxed-constexpr is supported")
ENDIF()
output
...
-- Found CUDA: /opt/cuda (found version "7.0")
-- relaxed-constexpr is supported
...
(Personally, I would rely on CUDA_VERSION
.)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments