CMakeTestCUDACompiler.cmake 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. if(CMAKE_CUDA_COMPILER_FORCED)
  4. # The compiler configuration was forced by the user.
  5. # Assume the user has configured all compiler information.
  6. set(CMAKE_CUDA_COMPILER_WORKS TRUE)
  7. return()
  8. endif()
  9. include(CMakeTestCompilerCommon)
  10. # Remove any cached result from an older CMake version.
  11. # We now store this in CMakeCUDACompiler.cmake.
  12. unset(CMAKE_CUDA_COMPILER_WORKS CACHE)
  13. # This file is used by EnableLanguage in cmGlobalGenerator to
  14. # determine that that selected cuda compiler can actually compile
  15. # and link the most basic of programs. If not, a fatal error
  16. # is set and cmake stops processing commands and will not generate
  17. # any makefiles or projects.
  18. if(NOT CMAKE_CUDA_COMPILER_WORKS)
  19. PrintTestCompilerStatus("CUDA" "")
  20. file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/main.cu
  21. "#ifndef __CUDACC__\n"
  22. "# error \"The CMAKE_CUDA_COMPILER is set to an invalid CUDA compiler\"\n"
  23. "#endif\n"
  24. "int main(){return 0;}\n")
  25. try_compile(CMAKE_CUDA_COMPILER_WORKS ${CMAKE_BINARY_DIR}
  26. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/main.cu
  27. OUTPUT_VARIABLE __CMAKE_CUDA_COMPILER_OUTPUT)
  28. # Move result from cache to normal variable.
  29. set(CMAKE_CUDA_COMPILER_WORKS ${CMAKE_CUDA_COMPILER_WORKS})
  30. unset(CMAKE_CUDA_COMPILER_WORKS CACHE)
  31. set(CUDA_TEST_WAS_RUN 1)
  32. endif()
  33. if(NOT CMAKE_CUDA_COMPILER_WORKS)
  34. PrintTestCompilerStatus("CUDA" " -- broken")
  35. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  36. "Determining if the CUDA compiler works failed with "
  37. "the following output:\n${__CMAKE_CUDA_COMPILER_OUTPUT}\n\n")
  38. message(FATAL_ERROR "The CUDA compiler \"${CMAKE_CUDA_COMPILER}\" "
  39. "is not able to compile a simple test program.\nIt fails "
  40. "with the following output:\n ${__CMAKE_CUDA_COMPILER_OUTPUT}\n\n"
  41. "CMake will not be able to correctly generate this project.")
  42. else()
  43. if(CUDA_TEST_WAS_RUN)
  44. PrintTestCompilerStatus("CUDA" " -- works")
  45. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  46. "Determining if the CUDA compiler works passed with "
  47. "the following output:\n${__CMAKE_CUDA_COMPILER_OUTPUT}\n\n")
  48. endif()
  49. # Try to identify the ABI and configure it into CMakeCUDACompiler.cmake
  50. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
  51. CMAKE_DETERMINE_COMPILER_ABI(CUDA ${CMAKE_ROOT}/Modules/CMakeCUDACompilerABI.cu)
  52. if("x${CMAKE_CUDA_SIMULATE_ID}" STREQUAL "xMSVC")
  53. set(CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES "${CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES}")
  54. set(CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES "${CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES}")
  55. endif()
  56. # Re-configure to save learned information.
  57. configure_file(
  58. ${CMAKE_ROOT}/Modules/CMakeCUDACompiler.cmake.in
  59. ${CMAKE_PLATFORM_INFO_DIR}/CMakeCUDACompiler.cmake
  60. @ONLY
  61. )
  62. include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCUDACompiler.cmake)
  63. endif()
  64. unset(__CMAKE_CUDA_COMPILER_OUTPUT)