CMakeTestCUDACompiler.cmake 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 the 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. string(REPLACE "\n" "\n " _output "${__CMAKE_CUDA_COMPILER_OUTPUT}")
  39. message(FATAL_ERROR "The CUDA compiler\n \"${CMAKE_CUDA_COMPILER}\"\n"
  40. "is not able to compile a simple test program.\nIt fails "
  41. "with the following output:\n ${_output}\n\n"
  42. "CMake will not be able to correctly generate this project.")
  43. else()
  44. if(CUDA_TEST_WAS_RUN)
  45. PrintTestCompilerStatus("CUDA" " -- works")
  46. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  47. "Determining if the CUDA compiler works passed with "
  48. "the following output:\n${__CMAKE_CUDA_COMPILER_OUTPUT}\n\n")
  49. endif()
  50. # Try to identify the ABI and configure it into CMakeCUDACompiler.cmake
  51. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
  52. CMAKE_DETERMINE_COMPILER_ABI(CUDA ${CMAKE_ROOT}/Modules/CMakeCUDACompilerABI.cu)
  53. if("x${CMAKE_CUDA_SIMULATE_ID}" STREQUAL "xMSVC")
  54. set(CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES "${CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES}")
  55. set(CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES "${CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES}")
  56. endif()
  57. # Re-configure to save learned information.
  58. configure_file(
  59. ${CMAKE_ROOT}/Modules/CMakeCUDACompiler.cmake.in
  60. ${CMAKE_PLATFORM_INFO_DIR}/CMakeCUDACompiler.cmake
  61. @ONLY
  62. )
  63. include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCUDACompiler.cmake)
  64. endif()
  65. unset(__CMAKE_CUDA_COMPILER_OUTPUT)