LLVMProcessSources.cmake 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. include(AddFileDependencies)
  2. include(CMakeParseArguments)
  3. function(llvm_replace_compiler_option var old new)
  4. # Replaces a compiler option or switch `old' in `var' by `new'.
  5. # If `old' is not in `var', appends `new' to `var'.
  6. # Example: llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
  7. # If the option already is on the variable, don't add it:
  8. if( "${${var}}" MATCHES "(^| )${new}($| )" )
  9. set(n "")
  10. else()
  11. set(n "${new}")
  12. endif()
  13. if( "${${var}}" MATCHES "(^| )${old}($| )" )
  14. string( REGEX REPLACE "(^| )${old}($| )" " ${n} " ${var} "${${var}}" )
  15. else()
  16. set( ${var} "${${var}} ${n}" )
  17. endif()
  18. set( ${var} "${${var}}" PARENT_SCOPE )
  19. endfunction(llvm_replace_compiler_option)
  20. macro(add_td_sources srcs)
  21. file(GLOB tds *.td)
  22. if( tds )
  23. source_group("TableGen descriptions" FILES ${tds})
  24. set_source_files_properties(${tds} PROPERTIES HEADER_FILE_ONLY ON)
  25. list(APPEND ${srcs} ${tds})
  26. endif()
  27. endmacro(add_td_sources)
  28. function(add_header_files_for_glob hdrs_out glob)
  29. file(GLOB hds ${glob})
  30. set(${hdrs_out} ${hds} PARENT_SCOPE)
  31. endfunction(add_header_files_for_glob)
  32. function(find_all_header_files hdrs_out additional_headerdirs)
  33. add_header_files_for_glob(hds *.h)
  34. list(APPEND all_headers ${hds})
  35. foreach(additional_dir ${additional_headerdirs})
  36. add_header_files_for_glob(hds "${additional_dir}/*.h")
  37. list(APPEND all_headers ${hds})
  38. add_header_files_for_glob(hds "${additional_dir}/*.inc")
  39. list(APPEND all_headers ${hds})
  40. endforeach(additional_dir)
  41. set( ${hdrs_out} ${all_headers} PARENT_SCOPE )
  42. endfunction(find_all_header_files)
  43. function(llvm_process_sources OUT_VAR)
  44. cmake_parse_arguments(ARG "" "" "ADDITIONAL_HEADERS;ADDITIONAL_HEADER_DIRS" ${ARGN})
  45. set(sources ${ARG_UNPARSED_ARGUMENTS})
  46. llvm_check_source_file_list( ${sources} )
  47. if( MSVC_IDE OR XCODE )
  48. # This adds .td and .h files to the Visual Studio solution:
  49. add_td_sources(sources)
  50. find_all_header_files(hdrs "${ARG_ADDITIONAL_HEADER_DIRS}")
  51. if (hdrs)
  52. set_source_files_properties(${hdrs} PROPERTIES HEADER_FILE_ONLY ON)
  53. endif()
  54. set_source_files_properties(${ARG_ADDITIONAL_HEADERS} PROPERTIES HEADER_FILE_ONLY ON)
  55. list(APPEND sources ${ARG_ADDITIONAL_HEADERS} ${hdrs})
  56. endif()
  57. set( ${OUT_VAR} ${sources} PARENT_SCOPE )
  58. endfunction(llvm_process_sources)
  59. function(llvm_check_source_file_list)
  60. set(listed ${ARGN})
  61. file(GLOB globbed *.c *.cpp)
  62. foreach(g ${globbed})
  63. get_filename_component(fn ${g} NAME)
  64. # HLSL Change - case insensitive
  65. string(TOLOWER "${fn}" fn_lower)
  66. string(TOLOWER "${listed}" listed_lower)
  67. # Don't reject hidden files. Some editors create backups in the
  68. # same directory as the file.
  69. if (NOT "${fn}" MATCHES "^\\.")
  70. list(FIND LLVM_OPTIONAL_SOURCES ${fn} idx)
  71. if( idx LESS 0 )
  72. list(FIND listed_lower ${fn_lower} idx) # HLSL Change - case insensitive
  73. if( idx LESS 0 )
  74. # HLSL Change - support HLSL_IGNORE_SOURCES
  75. if( idx LESS 0 )
  76. list(FIND HLSL_IGNORE_SOURCES ${fn} idx)
  77. if( idx LESS 0 )
  78. message(SEND_ERROR "Found unknown source file ${g}
  79. Please update ${CMAKE_CURRENT_LIST_FILE} or HLSL_IGNORE_SOURCES\n")
  80. endif()
  81. endif()
  82. endif()
  83. endif()
  84. endif()
  85. endforeach()
  86. endfunction(llvm_check_source_file_list)