ParseImplicitLinkInfo.cmake 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. cmake_minimum_required(VERSION 3.14)
  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-Cray-9.0-hlist-ad craype-CXX-Cray-9.0-hlist-ad craype-Fortran-Cray-9.0-hlist-ad
  15. craype-C-GNU-7.3.0 craype-CXX-GNU-7.3.0 craype-Fortran-GNU-7.3.0
  16. craype-C-Intel-18.0.2.20180210 craype-CXX-Intel-18.0.2.20180210
  17. craype-Fortran-Intel-18.0.2.20180210
  18. darwin-C-AppleClang-8.0.0.8000042 darwin-CXX-AppleClang-8.0.0.8000042
  19. darwin_nostdinc-C-AppleClang-8.0.0.8000042
  20. darwin_nostdinc-CXX-AppleClang-8.0.0.8000042
  21. freebsd-C-Clang-3.3.0 freebsd-CXX-Clang-3.3.0 freebsd-Fortran-GNU-4.6.4
  22. hand-C-empty hand-CXX-empty
  23. hand-C-relative hand-CXX-relative
  24. linux-C-GNU-7.3.0 linux-CXX-GNU-7.3.0 linux-Fortran-GNU-7.3.0
  25. linux-C-GNU-10.2.1-static-libgcc
  26. linux-CXX-GNU-10.2.1-static-libstdc++
  27. linux-Fortran-GNU-10.2.1-static-libgfortran
  28. linux-C-Intel-18.0.0.20170811 linux-CXX-Intel-18.0.0.20170811
  29. linux-C-PGI-18.10.1 linux-CXX-PGI-18.10.1
  30. linux-Fortran-PGI-18.10.1 linux_pgf77-Fortran-PGI-18.10.1
  31. linux_nostdinc-C-PGI-18.10.1 linux_nostdinc-CXX-PGI-18.10.1
  32. linux_nostdinc-Fortran-PGI-18.10.1
  33. linux-C-NVHPC-21.1.0 linux-CXX-NVHPC-21.1.0
  34. linux-C-XL-12.1.0 linux-CXX-XL-12.1.0 linux-Fortran-XL-14.1.0
  35. linux_nostdinc-C-XL-12.1.0 linux_nostdinc-CXX-XL-12.1.0
  36. linux_nostdinc_i-C-XL-12.1.0 linux_nostdinc-CXX-XL-12.1.0
  37. linux-C-XL-16.1.0.0 linux-CXX-XL-16.1.0.0
  38. linux-CUDA-NVIDIA-10.1.168-CLANG linux-CUDA-NVIDIA-10.1.168-XLClang-v
  39. linux-CUDA-NVIDIA-9.2.148-GCC
  40. linux-Fortran-LLVMFlang-15.0.0
  41. linux-custom_clang-C-Clang-13.0.0 linux-custom_clang-CXX-Clang-13.0.0
  42. mingw.org-C-GNU-4.9.3 mingw.org-CXX-GNU-4.9.3
  43. netbsd-C-GNU-4.8.5 netbsd-CXX-GNU-4.8.5
  44. netbsd_nostdinc-C-GNU-4.8.5 netbsd_nostdinc-CXX-GNU-4.8.5
  45. openbsd-C-Clang-5.0.1 openbsd-CXX-Clang-5.0.1
  46. sunos-C-SunPro-5.13.0 sunos-CXX-SunPro-5.13.0 sunos-Fortran-SunPro-8.8.0
  47. )
  48. if(CMAKE_HOST_WIN32)
  49. # The KWSys actual-case cache breaks case sensitivity on Windows.
  50. list(FILTER targets EXCLUDE REGEX "-XL|-SunPro")
  51. else()
  52. # Windows drive letters are not recognized as absolute on other platforms.
  53. list(FILTER targets EXCLUDE REGEX "mingw")
  54. endif()
  55. include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
  56. include(${CMAKE_ROOT}/Modules/CMakeParseLibraryArchitecture.cmake)
  57. #
  58. # load_compiler_info: read infile, parsing out cmake compiler info
  59. # variables as we go. returns language, a list of variables we set
  60. # (so we can clear them later), and the remaining verbose output
  61. # from the compiler.
  62. #
  63. function(load_compiler_info infile lang_var outcmvars_var outstr_var)
  64. unset(lang)
  65. unset(outcmvars)
  66. unset(outstr)
  67. file(READ "${infile}" in)
  68. string(REGEX REPLACE "\r?\n" ";" in_lines "${in}")
  69. foreach(line IN LISTS in_lines)
  70. # check for special CMAKE variable lines and parse them if found
  71. if("${line}" MATCHES "^CMAKE_([_A-Za-z0-9+]+)=(.*)$")
  72. if("${CMAKE_MATCH_1}" STREQUAL "LANG") # handle CMAKE_LANG here
  73. set(lang "${CMAKE_MATCH_2}")
  74. else()
  75. set(CMAKE_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" PARENT_SCOPE)
  76. list(APPEND outcmvars "CMAKE_${CMAKE_MATCH_1}")
  77. endif()
  78. else()
  79. string(APPEND outstr "${line}\n")
  80. endif()
  81. endforeach()
  82. if(NOT lang)
  83. message("load_compiler_info: ${infile} no LANG info; default to C")
  84. set(lang C)
  85. endif()
  86. set(${lang_var} "${lang}" PARENT_SCOPE)
  87. set(${outcmvars_var} "${outcmvars}" PARENT_SCOPE)
  88. set(${outstr_var} "${outstr}" PARENT_SCOPE)
  89. endfunction()
  90. #
  91. # unload_compiler_info: clear out any CMAKE_* vars load previously set
  92. #
  93. function(unload_compiler_info cmvars)
  94. foreach(var IN LISTS cmvars)
  95. unset("${var}" PARENT_SCOPE)
  96. endforeach()
  97. endfunction()
  98. #
  99. # load_platform_info: establish CMAKE_LIBRARY_ARCHITECTURE_REGEX
  100. # based on the target platform.
  101. #
  102. function(load_platform_info target)
  103. if(target MATCHES "linux-")
  104. set(CMAKE_LIBRARY_ARCHITECTURE_REGEX "[a-z0-9_]+(-[a-z0-9_]+)?-linux-gnu[a-z0-9_]*" PARENT_SCOPE)
  105. else()
  106. unset(CMAKE_LIBRARY_ARCHITECTURE_REGEX PARENT_SCOPE)
  107. endif()
  108. endfunction()
  109. #
  110. # main test loop
  111. #
  112. foreach(t ${targets})
  113. set(infile "${CMAKE_SOURCE_DIR}/../ParseImplicitData/${t}.input")
  114. set(outfile "${CMAKE_SOURCE_DIR}/results/${t}.output")
  115. if (NOT EXISTS ${infile})
  116. string(REPLACE "-empty" "" infile "${infile}")
  117. if (NOT EXISTS ${infile})
  118. message("missing input file for target ${t} in ${CMAKE_SOURCE_DIR}/../ParseImplicitData/")
  119. continue()
  120. endif()
  121. elseif(NOT EXISTS ${outfile})
  122. message("missing files for target ${t} in ${CMAKE_SOURCE_DIR}/results/")
  123. continue()
  124. endif()
  125. load_compiler_info(${infile} lang cmvars input)
  126. load_platform_info(${t})
  127. # Need to handle files with empty entries for both libs or dirs
  128. set(implicit_lib_output "")
  129. set(idirs_output "")
  130. set(implicit_objs "")
  131. set(library_arch_output "")
  132. file(STRINGS ${outfile} outputs)
  133. foreach(line IN LISTS outputs)
  134. if(line MATCHES "libs=")
  135. string(REPLACE "libs=" "" implicit_lib_output "${line}")
  136. endif()
  137. if(line MATCHES "dirs=")
  138. string(REPLACE "dirs=" "" idirs_output "${line}")
  139. endif()
  140. if(line MATCHES "library_arch=")
  141. string(REPLACE "library_arch=" "" library_arch_output "${line}")
  142. endif()
  143. endforeach()
  144. cmake_parse_implicit_link_info("${input}" implicit_libs idirs implicit_fwks log
  145. "${CMAKE_${lang}_IMPLICIT_OBJECT_REGEX}"
  146. LANGUAGE ${lang}
  147. COMPUTE_IMPLICIT_OBJECTS implicit_objs)
  148. set(library_arch)
  149. cmake_parse_library_architecture(${lang} "${idirs}" "${implicit_objs}" library_arch)
  150. # File format
  151. # file(WRITE ${outfile} "libs=${implicit_libs}\ndirs=${idirs}\nlibrary_arch=${library_arch}")
  152. if(t MATCHES "-empty$") # empty isn't supposed to parse
  153. if("${state}" STREQUAL "done")
  154. message("empty parse failed: ${idirs}, log=${log}")
  155. endif()
  156. elseif(NOT "${idirs}" MATCHES "^${idirs_output}$")
  157. message("${t} parse failed: state=${state}, '${idirs}' does not match '^${idirs_output}$'")
  158. elseif(NOT "${implicit_libs}" MATCHES "^${implicit_lib_output}$")
  159. message("${t} parse failed: state=${state}, '${implicit_libs}' does not match '^${implicit_lib_output}$'")
  160. elseif((library_arch OR library_arch_output) AND NOT "${library_arch}" MATCHES "^${library_arch_output}$")
  161. message("${t} parse failed: state=${state}, '${library_arch}' does not match '^${library_arch_output}$'")
  162. endif()
  163. unload_compiler_info("${cmvars}")
  164. endforeach(t)