make2cmake.cmake 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # James Bigler, NVIDIA Corp (nvidia.com - jbigler)
  2. # Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
  3. #
  4. # Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
  5. #
  6. # Copyright (c) 2007-2009
  7. # Scientific Computing and Imaging Institute, University of Utah
  8. #
  9. # This code is licensed under the MIT License. See the FindCUDA.cmake script
  10. # for the text of the license.
  11. # The MIT License
  12. #
  13. # License for the specific language governing rights and limitations under
  14. # Permission is hereby granted, free of charge, to any person obtaining a
  15. # copy of this software and associated documentation files (the "Software"),
  16. # to deal in the Software without restriction, including without limitation
  17. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  18. # and/or sell copies of the Software, and to permit persons to whom the
  19. # Software is furnished to do so, subject to the following conditions:
  20. #
  21. # The above copyright notice and this permission notice shall be included
  22. # in all copies or substantial portions of the Software.
  23. #
  24. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  25. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  27. # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  29. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  30. # DEALINGS IN THE SOFTWARE.
  31. #
  32. #######################################################################
  33. # This converts a file written in makefile syntax into one that can be included
  34. # by CMake.
  35. file(READ ${input_file} depend_text)
  36. if (NOT "${depend_text}" STREQUAL "")
  37. # message("FOUND DEPENDS")
  38. string(REPLACE "\\ " " " depend_text ${depend_text})
  39. # This works for the nvcc -M generated dependency files.
  40. string(REGEX REPLACE "^.* : " "" depend_text ${depend_text})
  41. string(REGEX REPLACE "[ \\\\]*\n" ";" depend_text ${depend_text})
  42. set(dependency_list "")
  43. foreach(file ${depend_text})
  44. string(REGEX REPLACE "^ +" "" file ${file})
  45. # OK, now if we had a UNC path, nvcc has a tendency to only output the first '/'
  46. # instead of '//'. Here we will test to see if the file exists, if it doesn't then
  47. # try to prepend another '/' to the path and test again. If it still fails remove the
  48. # path.
  49. if(NOT EXISTS "${file}")
  50. if (EXISTS "/${file}")
  51. set(file "/${file}")
  52. else()
  53. message(WARNING " Removing non-existent dependency file: ${file}")
  54. set(file "")
  55. endif()
  56. endif()
  57. if(NOT IS_DIRECTORY "${file}")
  58. # If softlinks start to matter, we should change this to REALPATH. For now we need
  59. # to flatten paths, because nvcc can generate stuff like /bin/../include instead of
  60. # just /include.
  61. get_filename_component(file_absolute "${file}" ABSOLUTE)
  62. list(APPEND dependency_list "${file_absolute}")
  63. endif()
  64. endforeach()
  65. else()
  66. # message("FOUND NO DEPENDS")
  67. endif()
  68. # Remove the duplicate entries and sort them.
  69. list(REMOVE_DUPLICATES dependency_list)
  70. list(SORT dependency_list)
  71. foreach(file ${dependency_list})
  72. set(cuda_nvcc_depend "${cuda_nvcc_depend} \"${file}\"\n")
  73. endforeach()
  74. file(WRITE ${output_file} "# Generated by: make2cmake.cmake\nSET(CUDA_NVCC_DEPEND\n ${cuda_nvcc_depend})\n\n")