CUDA with BASIS
CMake is now supporting CUDA as a native language. However it is not possible to use basis_add_libraray(TARGET files LANGUAGE CUDA) . The error message is :
CMake Error at CMake-Basis/3.3.1/share/modules/TargetTools.cmake:519 (target_link_libraries):
Target "cuda" of type UTILITY may not be linked into another target.
One may link only to STATIC or SHARED libraries, or to executables with the
ENABLE_EXPORTS property set.
Are they any plans to support CUDA?
Thanks for reporting this issue. I'll collect some notes here as to which functions may need to be extended in order to support CUDA with CMake 3.8+ (i.e., without need for FindCUDA).
-
basis_get_source_language: Recognize.cufilename extension https://github.com/cmake-basis/BASIS/blob/b21423c169a0d15feff046421bfd76092b559af5/src/cmake/modules/CommonTools.cmake#L2760 -
basis_add_library_target: SetsLANGUAGEtarget property toCXX(CMake does not define this target property, it may only be used by BASIS; see file property) https://github.com/cmake-basis/BASIS/blob/b21423c169a0d15feff046421bfd76092b559af5/src/cmake/modules/TargetTools.cmake#L2118 -
Enable
CUDAlanguage support of CMake 3.8+ inBasisProject.cmakefile usingbasis_project(no fix needed, user must specifyCUDAlanguage when used): https://github.com/cmake-basis/BASIS/blob/b21423c169a0d15feff046421bfd76092b559af5/src/cmake/modules/ProjectTools.cmake#L585 -
Pass
basis_project(LANGUAGES CUDA)on to CMake'sprojectcommand (also allowNONE?) (this is the most important change): https://github.com/cmake-basis/BASIS/blob/b21423c169a0d15feff046421bfd76092b559af5/src/cmake/modules/ProjectTools.cmake#L1869 -
Set property
CUDA_SEPARABLE_COMPILATIONappropriately. (though default value can be set by user by settingCMAKE_CUDA_SEPARABLE_COMPILATION). -
On macOS, set property
BUILD_RPATHto includeCMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES.
Note that the LANGUAGE option of basis_add_library is mainly used to determine which specialized function to use for defining the build target. When the option argument is CXX and it's not a MEX-file target, CMake's add_library function is used. Otherwise BASIS uses some custom basis_* functions which define custom build commands and targets.
Hence, I would try
basis_add_library(TARGET files LANGUAGE CXX)
until LANGUAGE argument CUDA is supported by basis_add_library and basis_add_executable.
See also: https://devblogs.nvidia.com/building-cuda-applications-cmake/