make2cmake.cmake 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. # Input variables
  36. #
  37. # verbose:BOOL=<> OFF: Be as quiet as possible (default)
  38. # ON : Extra output
  39. #
  40. # input_file:FILEPATH=<> Path to dependency file in makefile format
  41. #
  42. # output_file:FILEPATH=<> Path to file with dependencies in CMake readable variable
  43. #
  44. file(READ ${input_file} depend_text)
  45. if (NOT "${depend_text}" STREQUAL "")
  46. # message("FOUND DEPENDS")
  47. string(REPLACE "\\ " " " depend_text ${depend_text})
  48. # This works for the nvcc -M generated dependency files.
  49. string(REGEX REPLACE "^.* : " "" depend_text ${depend_text})
  50. string(REGEX REPLACE "[ \\\\]*\n" ";" depend_text ${depend_text})
  51. set(dependency_list "")
  52. foreach(file ${depend_text})
  53. string(REGEX REPLACE "^ +" "" file ${file})
  54. # OK, now if we had a UNC path, nvcc has a tendency to only output the first '/'
  55. # instead of '//'. Here we will test to see if the file exists, if it doesn't then
  56. # try to prepend another '/' to the path and test again. If it still fails remove the
  57. # path.
  58. if(NOT EXISTS "${file}")
  59. if (EXISTS "/${file}")
  60. set(file "/${file}")
  61. else()
  62. if(verbose)
  63. message(WARNING " Removing non-existent dependency file: ${file}")
  64. endif()
  65. set(file "")
  66. endif()
  67. endif()
  68. # Make sure we check to see if we have a file, before asking if it is not a directory.
  69. # if(NOT IS_DIRECTORY "") will return TRUE.
  70. if(file AND NOT IS_DIRECTORY "${file}")
  71. # If softlinks start to matter, we should change this to REALPATH. For now we need
  72. # to flatten paths, because nvcc can generate stuff like /bin/../include instead of
  73. # just /include.
  74. get_filename_component(file_absolute "${file}" ABSOLUTE)
  75. list(APPEND dependency_list "${file_absolute}")
  76. endif()
  77. endforeach()
  78. else()
  79. # message("FOUND NO DEPENDS")
  80. endif()
  81. # Remove the duplicate entries and sort them.
  82. list(REMOVE_DUPLICATES dependency_list)
  83. list(SORT dependency_list)
  84. foreach(file ${dependency_list})
  85. string(APPEND cuda_nvcc_depend " \"${file}\"\n")
  86. endforeach()
  87. file(WRITE ${output_file} "# Generated by: make2cmake.cmake\nSET(CUDA_NVCC_DEPEND\n ${cuda_nvcc_depend})\n\n")