ParseImplicitIncludeInfo.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. cmake_minimum_required(VERSION 3.0)
  2. project(Minimal NONE)
  3. #
  4. # list of targets to test. to add a target: put its files in the data
  5. # subdirectory and add it to this list... we run each target's
  6. # data/*.input file through the parser and check to see if it matches
  7. # the corresponding data/*.output file. note that the empty-* case
  8. # has special handling (it should not parse).
  9. #
  10. set(targets
  11. aix-C-XL-13.1.3 aix-CXX-XL-13.1.3
  12. aix-C-XLClang-16.1.0.1 aix-CXX-XLClang-16.1.0.1
  13. craype-C-Cray-8.7 craype-CXX-Cray-8.7 craype-Fortran-Cray-8.7
  14. craype-C-GNU-7.3.0 craype-CXX-GNU-7.3.0 craype-Fortran-GNU-7.3.0
  15. craype-C-Intel-18.0.2.20180210 craype-CXX-Intel-18.0.2.20180210
  16. craype-Fortran-Intel-18.0.2.20180210
  17. darwin-C-AppleClang-8.0.0.8000042 darwin-CXX-AppleClang-8.0.0.8000042
  18. darwin_nostdinc-C-AppleClang-8.0.0.8000042
  19. darwin_nostdinc-CXX-AppleClang-8.0.0.8000042
  20. empty-C empty-CXX
  21. freebsd-C-Clang-3.3.0 freebsd-CXX-Clang-3.3.0 freebsd-Fortran-GNU-4.6.4
  22. linux-C-GNU-7.3.0 linux-CXX-GNU-7.3.0 linux-Fortran-GNU-7.3.0
  23. linux-C-Intel-18.0.0.20170811 linux-CXX-Intel-18.0.0.20170811
  24. linux-C-PGI-18.10.1 linux-CXX-PGI-18.10.1
  25. linux-Fortran-PGI-18.10.1 linux_pgf77-Fortran-PGI-18.10.1
  26. linux_nostdinc-C-PGI-18.10.1 linux_nostdinc-CXX-PGI-18.10.1
  27. linux_nostdinc-Fortran-PGI-18.10.1
  28. linux-C-XL-12.1.0 linux-CXX-XL-12.1.0 linux-Fortran-XL-14.1.0
  29. linux_nostdinc-C-XL-12.1.0 linux_nostdinc-CXX-XL-12.1.0
  30. linux_nostdinc_i-C-XL-12.1.0 linux_nostdinc-CXX-XL-12.1.0
  31. linux-C-XL-16.1.0.0 linux-CXX-XL-16.1.0.0
  32. linux-CUDA-NVIDIA-9.2.148
  33. mingw.org-C-GNU-4.9.3 mingw.org-CXX-GNU-4.9.3
  34. netbsd-C-GNU-4.8.5 netbsd-CXX-GNU-4.8.5
  35. netbsd_nostdinc-C-GNU-4.8.5 netbsd_nostdinc-CXX-GNU-4.8.5
  36. openbsd-C-Clang-5.0.1 openbsd-CXX-Clang-5.0.1
  37. sunos-C-SunPro-5.13.0 sunos-CXX-SunPro-5.13.0 sunos-Fortran-SunPro-8.8.0
  38. )
  39. include(${CMAKE_ROOT}/Modules/CMakeParseImplicitIncludeInfo.cmake)
  40. #
  41. # load_compiler_info: read infile, parsing out cmake compiler info
  42. # variables as we go. returns language, a list of variables we set
  43. # (so we can clear them later), and the remaining verbose output
  44. # from the compiler.
  45. #
  46. function(load_compiler_info infile lang_var outcmvars_var outstr_var)
  47. unset(lang)
  48. unset(outcmvars)
  49. unset(outstr)
  50. file(READ "${infile}" in)
  51. string(REGEX REPLACE "\r?\n" ";" in_lines "${in}")
  52. foreach(line IN LISTS in_lines)
  53. # check for special CMAKE variable lines and parse them if found
  54. if("${line}" MATCHES "^CMAKE_([_A-Za-z0-9]+)=(.*)$")
  55. if("${CMAKE_MATCH_1}" STREQUAL "LANG") # handle CMAKE_LANG here
  56. set(lang "${CMAKE_MATCH_2}")
  57. else()
  58. set(CMAKE_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" PARENT_SCOPE)
  59. list(APPEND outcmvars "CMAKE_${CMAKE_MATCH_1}")
  60. endif()
  61. else()
  62. string(APPEND outstr "${line}\n")
  63. endif()
  64. endforeach()
  65. if(NOT lang)
  66. message("load_compiler_info: ${infile} no LANG info; default to C")
  67. set(lang C)
  68. endif()
  69. set(${lang_var} "${lang}" PARENT_SCOPE)
  70. set(${outcmvars_var} "${outcmvars}" PARENT_SCOPE)
  71. set(${outstr_var} "${outstr}" PARENT_SCOPE)
  72. endfunction()
  73. #
  74. # unload_compiler_info: clear out any CMAKE_* vars load previously set
  75. #
  76. function(unload_compiler_info cmvars)
  77. foreach(var IN LISTS cmvars)
  78. unset("${var}" PARENT_SCOPE)
  79. endforeach()
  80. endfunction()
  81. #
  82. # main test loop
  83. #
  84. foreach(t ${targets})
  85. set(infile "${CMAKE_SOURCE_DIR}/data/${t}.input")
  86. set(outfile "${CMAKE_SOURCE_DIR}/data/${t}.output")
  87. if (NOT EXISTS ${infile} OR NOT EXISTS ${outfile})
  88. message("missing files for target ${t} in ${CMAKE_SOURCE_DIR}/data")
  89. continue()
  90. endif()
  91. load_compiler_info(${infile} lang cmvars input)
  92. file(READ ${outfile} output)
  93. string(STRIP "${output}" output)
  94. cmake_parse_implicit_include_info("${input}" "${lang}" idirs log state)
  95. if(t MATCHES "^empty-") # empty isn't supposed to parse
  96. if("${state}" STREQUAL "done")
  97. message("empty parse failed: ${idirs}, log=${log}")
  98. endif()
  99. elseif(NOT "${state}" STREQUAL "done" OR NOT "${output}" STREQUAL "${idirs}")
  100. message("parse failed: state=${state}, ${output} != ${idirs}, log=${log}")
  101. endif()
  102. unload_compiler_info("${cmvars}")
  103. endforeach(t)