From 4f5155f6aba7cb7cd8c0e5b75e43b38a70568eb1 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 29 Aug 2016 13:28:37 -0400 Subject: CUDA: We now properly perform CUDA compiler identification. --- Modules/CMakeCUDACompiler.cmake.in | 5 +++++ Modules/CMakeCUDACompilerABI.cu | 16 ++++++++++++++++ Modules/CMakeCUDAInformation.cmake | 4 ---- Modules/CMakeCompilerIdDetection.cmake | 5 +++++ Modules/CMakeDetermineCUDACompiler.cmake | 12 +++++++++--- Modules/CMakeTestCUDACompiler.cmake | 13 +++++++++++++ Modules/Compiler/NVIDIA-CUDA.cmake | 2 +- 7 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 Modules/CMakeCUDACompilerABI.cu diff --git a/Modules/CMakeCUDACompiler.cmake.in b/Modules/CMakeCUDACompiler.cmake.in index 78606e6..897fc52 100644 --- a/Modules/CMakeCUDACompiler.cmake.in +++ b/Modules/CMakeCUDACompiler.cmake.in @@ -1,8 +1,13 @@ set(CMAKE_CUDA_COMPILER "@CMAKE_CUDA_COMPILER@") set(CMAKE_CUDA_COMPILER_ID "@CMAKE_CUDA_COMPILER_ID@") +set(CMAKE_CUDA_COMPILER_VERSION "@CMAKE_CUDA_COMPILER_VERSION@") set(CMAKE_CUDA_STANDARD_COMPUTED_DEFAULT "@CMAKE_CUDA_STANDARD_COMPUTED_DEFAULT@") set(CMAKE_CUDA_COMPILER_ENV_VAR "CUDACXX") set(CMAKE_CUDA_COMPILER_ID_RUN 1) set(CMAKE_CUDA_SOURCE_FILE_EXTENSIONS cu) + +set(CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES "@CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES@") +set(CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES "@CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES@") +set(CMAKE_CUDA_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "@CMAKE_CUDA_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES@") diff --git a/Modules/CMakeCUDACompilerABI.cu b/Modules/CMakeCUDACompilerABI.cu new file mode 100644 index 0000000..5aa1b8a --- /dev/null +++ b/Modules/CMakeCUDACompilerABI.cu @@ -0,0 +1,16 @@ +#ifndef __CUDACC__ +# error "A C or C++ compiler has been selected for CUDA" +#endif + +#include "CMakeCompilerABI.h" + +int main(int argc, char* argv[]) +{ + int require = 0; + require += info_sizeof_dptr[argc]; +#if defined(ABI_ID) + require += info_abi[argc]; +#endif + (void)argv; + return require; +} diff --git a/Modules/CMakeCUDAInformation.cmake b/Modules/CMakeCUDAInformation.cmake index 491c35b..d3278e7 100644 --- a/Modules/CMakeCUDAInformation.cmake +++ b/Modules/CMakeCUDAInformation.cmake @@ -7,10 +7,6 @@ set(CMAKE_INCLUDE_FLAG_CUDA "-I") # Load compiler-specific information. if(CMAKE_CUDA_COMPILER_ID) include(Compiler/${CMAKE_CUDA_COMPILER_ID}-CUDA OPTIONAL) -else() - #couldn't id the cuda compile, fall back to the default setting - set(CMAKE_CUDA_COMPILER_ID "NVidia") - include(Compiler/NVidia-CUDA OPTIONAL) endif() # load the system- and compiler specific files diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake index 4732250..2881cb1 100644 --- a/Modules/CMakeCompilerIdDetection.cmake +++ b/Modules/CMakeCompilerIdDetection.cmake @@ -90,6 +90,11 @@ function(compiler_id_detection outvar lang) list(APPEND ordered_compilers MIPSpro) + #Currently the only CUDA compilers are NVIDIA + if(lang STREQUAL CUDA) + set(ordered_compilers NVIDIA) + endif() + if(CID_ID_DEFINE) foreach(Id ${ordered_compilers}) set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}# define ${CID_PREFIX}COMPILER_IS_${Id} 0\n") diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake index fd87358..a6863ef 100644 --- a/Modules/CMakeDetermineCUDACompiler.cmake +++ b/Modules/CMakeDetermineCUDACompiler.cmake @@ -27,10 +27,16 @@ mark_as_advanced(CMAKE_CUDA_COMPILER) if(NOT CMAKE_CUDA_COMPILER_ID_RUN) set(CMAKE_CUDA_COMPILER_ID_RUN 1) - list(APPEND CMAKE_CUDA_COMPILER_ID_MATCH_VENDORS NVidia) - set(CMAKE_CUDA_COMPILER_ID_MATCH_VENDOR_REGEX_NVidia "nvcc: NVIDIA \(R\) Cuda compiler driver") + # Try to identify the compiler. + set(CMAKE_CUDA_COMPILER_ID) + set(CMAKE_CUDA_PLATFORM_ID) + file(READ ${CMAKE_ROOT}/Modules/CMakePlatformId.h.in + CMAKE_CUDA_COMPILER_ID_PLATFORM_CONTENT) - set(CMAKE_CXX_COMPILER_ID_TOOL_MATCH_REGEX "\nLd[^\n]*(\n[ \t]+[^\n]*)*\n[ \t]+([^ \t\r\n]+)[^\r\n]*-o[^\r\n]*CompilerIdCXX/(\\./)?(CompilerIdCXX.xctest/)?CompilerIdCXX[ \t\n\\\"]") + list(APPEND CMAKE_CUDA_COMPILER_ID_MATCH_VENDORS NVIDIA) + set(CMAKE_CUDA_COMPILER_ID_MATCH_VENDOR_REGEX_NVIDIA "nvcc: NVIDIA \(R\) Cuda compiler driver") + + set(CMAKE_CXX_COMPILER_ID_TOOL_MATCH_REGEX "\nLd[^\n]*(\n[ \t]+[^\n]*)*\n[ \t]+([^ \t\r\n]+)[^\r\n]*-o[^\r\n]*CompilerIdCUDA/(\\./)?(CompilerIdCUDA.xctest/)?CompilerIdCUDA[ \t\n\\\"]") set(CMAKE_CXX_COMPILER_ID_TOOL_MATCH_INDEX 2) include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake) diff --git a/Modules/CMakeTestCUDACompiler.cmake b/Modules/CMakeTestCUDACompiler.cmake index e45d2ab..670b31d 100644 --- a/Modules/CMakeTestCUDACompiler.cmake +++ b/Modules/CMakeTestCUDACompiler.cmake @@ -53,6 +53,19 @@ else() "Determining if the CUDA compiler works passed with " "the following output:\n${__CMAKE_CUDA_COMPILER_OUTPUT}\n\n") endif() + + # Try to identify the ABI and configure it into CMakeCUDACompiler.cmake + include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake) + CMAKE_DETERMINE_COMPILER_ABI(CUDA ${CMAKE_ROOT}/Modules/CMakeCUDACompilerABI.cu) + + # Re-configure to save learned information. + configure_file( + ${CMAKE_ROOT}/Modules/CMakeCUDACompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeCUDACompiler.cmake + @ONLY + ) + include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCUDACompiler.cmake) endif() + unset(__CMAKE_CUDA_COMPILER_OUTPUT) diff --git a/Modules/Compiler/NVIDIA-CUDA.cmake b/Modules/Compiler/NVIDIA-CUDA.cmake index ae51138..6f12ff2 100644 --- a/Modules/Compiler/NVIDIA-CUDA.cmake +++ b/Modules/Compiler/NVIDIA-CUDA.cmake @@ -1,4 +1,4 @@ -set(CMAKE_CXX_VERBOSE_FLAG "-v") +set(CMAKE_CUDA_VERBOSE_FLAG "-v -Xcompiler=-v") set(CMAKE_CUDA_COMPILE_OPTIONS_PIE -Xcompiler=-fPIE) -- cgit v0.12