ParseImplicitLinkInfo.cmake 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #
  2. # list of targets to test. to add a target: put its files in the data
  3. # subdirectory and add it to this list... we run each target's
  4. # data/*.input file through the parser and check to see if it matches
  5. # the corresponding data/*.output file. note that the empty-* case
  6. # has special handling (it should not parse).
  7. #
  8. set(targets
  9. aix-C-XL-13.1.3 aix-CXX-XL-13.1.3
  10. aix-C-XLClang-16.1.0.1 aix-CXX-XLClang-16.1.0.1
  11. aix-C-IBMClang-17.1.1.2 aix-CXX-IBMClang-17.1.1.2
  12. craype-C-Cray-8.7 craype-CXX-Cray-8.7 craype-Fortran-Cray-8.7
  13. craype-C-Cray-9.0-hlist-ad craype-CXX-Cray-9.0-hlist-ad craype-Fortran-Cray-9.0-hlist-ad
  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. freebsd-C-Clang-3.3.0 freebsd-CXX-Clang-3.3.0 freebsd-Fortran-GNU-4.6.4
  21. hand-C-empty hand-CXX-empty
  22. hand-C-relative hand-CXX-relative
  23. linux-C-GNU-7.3.0 linux-CXX-GNU-7.3.0 linux-Fortran-GNU-7.3.0
  24. linux-C-GNU-10.2.1-static-libgcc
  25. linux-CXX-GNU-10.2.1-static-libstdc++
  26. linux-Fortran-GNU-10.2.1-static-libgfortran
  27. linux-C-GNU-12.2.0 linux-CXX-GNU-12.2.0 linux-Fortran-GNU-12.2.0
  28. linux-C-Intel-18.0.0.20170811 linux-CXX-Intel-18.0.0.20170811
  29. linux-C-Intel-2021.10.0.20230609 linux-CXX-Intel-2021.10.0.20230609 linux-Fortran-Intel-2021.10.0.20230609
  30. linux-C-IntelLLVM-2023.2.0 linux-CXX-IntelLLVM-2023.2.0 linux-Fortran-IntelLLVM-2023.2.0
  31. linux-C-PGI-18.10.1 linux-CXX-PGI-18.10.1
  32. linux-Fortran-PGI-18.10.1 linux_pgf77-Fortran-PGI-18.10.1
  33. linux_nostdinc-C-PGI-18.10.1 linux_nostdinc-CXX-PGI-18.10.1
  34. linux_nostdinc-Fortran-PGI-18.10.1
  35. linux-C-NVHPC-21.1.0 linux-CXX-NVHPC-21.1.0
  36. linux-C-XL-12.1.0 linux-CXX-XL-12.1.0 linux-Fortran-XL-14.1.0
  37. linux_nostdinc-C-XL-12.1.0 linux_nostdinc-CXX-XL-12.1.0
  38. linux_nostdinc_i-C-XL-12.1.0 linux_nostdinc-CXX-XL-12.1.0
  39. linux-C-XL-16.1.0.0 linux-CXX-XL-16.1.0.0
  40. linux-CUDA-NVIDIA-10.1.168-CLANG linux-CUDA-NVIDIA-10.1.168-XLClang-v
  41. linux-CUDA-NVIDIA-9.2.148-GCC
  42. linux-Fortran-LLVMFlang-15.0.0
  43. linux-custom_clang-C-Clang-13.0.0 linux-custom_clang-CXX-Clang-13.0.0
  44. mingw.org-C-GNU-4.9.3 mingw.org-CXX-GNU-4.9.3
  45. netbsd-C-GNU-4.8.5 netbsd-CXX-GNU-4.8.5
  46. netbsd_nostdinc-C-GNU-4.8.5 netbsd_nostdinc-CXX-GNU-4.8.5
  47. openbsd-C-Clang-5.0.1 openbsd-CXX-Clang-5.0.1
  48. sunos-C-SunPro-5.13.0 sunos-CXX-SunPro-5.13.0 sunos-Fortran-SunPro-8.8.0
  49. sunos5.10_sparc32-C-GNU-5.5.0 sunos5.10_sparc32-CXX-GNU-5.5.0 sunos5.10_sparc32-Fortran-GNU-5.5.0
  50. sunos5.11_i386-C-GNU-5.5.0 sunos5.11_i386-CXX-GNU-5.5.0 sunos5.11_i386-Fortran-GNU-5.5.0
  51. windows_x86_64-C-MSVC-19.36.32543.0 windows_x86_64-CXX-MSVC-19.36.32543.0
  52. windows_x86_64-C-MSVC-19.38.33130.0-VS windows_x86_64-CXX-MSVC-19.38.33130.0-VS
  53. windows_x86_64-C-Clang-17.0.1-MSVC windows_x86_64-CXX-Clang-17.0.1-MSVC windows_x86_64-Fortran-LLVMFlang-17.0.1-MSVC
  54. windows_x86_64-Fortran-LLVMFlang-18.0.0-MSVC
  55. windows_x86_64-C-Intel-2021.9.0.20230302 windows_x86_64-CXX-Intel-2021.9.0.20230302 windows_x86_64-Fortran-Intel-2021.9.0.20230302
  56. windows_x86_64-C-IntelLLVM-2023.1.0 windows_x86_64-CXX-IntelLLVM-2023.1.0 windows_x86_64-Fortran-IntelLLVM-2023.1.0
  57. windows_arm64-C-Clang-17.0.1-MSVC windows_arm64-CXX-Clang-17.0.1-MSVC windows_arm64-Fortran-LLVMFlang-17.0.1-MSVC
  58. )
  59. if(CMAKE_HOST_WIN32)
  60. # The KWSys actual-case cache breaks case sensitivity on Windows.
  61. list(FILTER targets EXCLUDE REGEX "-XL|-SunPro")
  62. else()
  63. # Windows drive letters are not recognized as absolute on other platforms.
  64. list(FILTER targets EXCLUDE REGEX "mingw")
  65. endif()
  66. include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
  67. include(${CMAKE_ROOT}/Modules/CMakeParseLibraryArchitecture.cmake)
  68. #
  69. # load_compiler_info: read infile, parsing out cmake compiler info
  70. # variables as we go. returns language, a list of variables we set
  71. # (so we can clear them later), and the remaining verbose output
  72. # from the compiler.
  73. #
  74. function(load_compiler_info infile lang_var outcmvars_var outstr_var)
  75. unset(lang)
  76. unset(outcmvars)
  77. unset(outstr)
  78. file(READ "${infile}" in)
  79. string(REGEX REPLACE "\r?\n" ";" in_lines "${in}")
  80. foreach(line IN LISTS in_lines)
  81. # check for special CMAKE variable lines and parse them if found
  82. if("${line}" MATCHES "^CMAKE_([_A-Za-z0-9+]+)=(.*)$")
  83. if("${CMAKE_MATCH_1}" STREQUAL "LANG") # handle CMAKE_LANG here
  84. set(lang "${CMAKE_MATCH_2}")
  85. else()
  86. set(CMAKE_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" PARENT_SCOPE)
  87. list(APPEND outcmvars "CMAKE_${CMAKE_MATCH_1}")
  88. endif()
  89. else()
  90. string(APPEND outstr "${line}\n")
  91. endif()
  92. endforeach()
  93. if(NOT lang)
  94. message("load_compiler_info: ${infile} no LANG info; default to C")
  95. set(lang C)
  96. endif()
  97. set(${lang_var} "${lang}" PARENT_SCOPE)
  98. set(${outcmvars_var} "${outcmvars}" PARENT_SCOPE)
  99. set(${outstr_var} "${outstr}" PARENT_SCOPE)
  100. endfunction()
  101. #
  102. # load_platform_info: establish CMAKE_LIBRARY_ARCHITECTURE_REGEX
  103. # based on the target platform.
  104. #
  105. function(load_platform_info target)
  106. if(target MATCHES "linux-")
  107. set(CMAKE_LIBRARY_ARCHITECTURE_REGEX "[a-z0-9_]+(-[a-z0-9_]+)?-linux-gnu[a-z0-9_]*" PARENT_SCOPE)
  108. else()
  109. unset(CMAKE_LIBRARY_ARCHITECTURE_REGEX PARENT_SCOPE)
  110. endif()
  111. endfunction()
  112. #
  113. # main test loop
  114. #
  115. foreach(t ${targets})
  116. set(infile "${CMAKE_SOURCE_DIR}/../ParseImplicitData/${t}.input")
  117. set(outfile "${CMAKE_SOURCE_DIR}/results/${t}.output")
  118. if (NOT EXISTS ${infile})
  119. string(REPLACE "-empty" "" infile "${infile}")
  120. if (NOT EXISTS ${infile})
  121. message("missing input file for target ${t} in ${CMAKE_SOURCE_DIR}/../ParseImplicitData/")
  122. continue()
  123. endif()
  124. elseif(NOT EXISTS ${outfile})
  125. message("missing files for target ${t} in ${CMAKE_SOURCE_DIR}/results/")
  126. continue()
  127. endif()
  128. block()
  129. load_compiler_info(${infile} lang cmvars input)
  130. load_platform_info(${t})
  131. # Need to handle files with empty entries for both libs or dirs
  132. set(implicit_lib_output "")
  133. set(idirs_output "")
  134. set(implicit_objs "")
  135. set(library_arch_output "")
  136. set(linker_tool_output "")
  137. file(STRINGS ${outfile} outputs)
  138. foreach(line IN LISTS outputs)
  139. if(line MATCHES "libs=")
  140. string(REPLACE "libs=" "" implicit_lib_output "${line}")
  141. endif()
  142. if(line MATCHES "dirs=")
  143. string(REPLACE "dirs=" "" idirs_output "${line}")
  144. endif()
  145. if(line MATCHES "library_arch=")
  146. string(REPLACE "library_arch=" "" library_arch_output "${line}")
  147. endif()
  148. if(line MATCHES "linker_tool=")
  149. string(REPLACE "linker_tool=" "" linker_tool_output "${line}")
  150. endif()
  151. endforeach()
  152. cmake_parse_implicit_link_info2("${input}" log
  153. "${CMAKE_${lang}_IMPLICIT_OBJECT_REGEX}"
  154. LANGUAGE ${lang}
  155. COMPUTE_LINKER linker_tool
  156. COMPUTE_IMPLICIT_LIBS implicit_libs
  157. COMPUTE_IMPLICIT_DIRS idirs
  158. COMPUTE_IMPLICIT_FWKS implicit_fwks
  159. COMPUTE_IMPLICIT_OBJECTS implicit_objs)
  160. set(library_arch)
  161. cmake_parse_library_architecture(${lang} "${idirs}" "${implicit_objs}" library_arch)
  162. # File format
  163. # file(WRITE ${outfile} "libs=${implicit_libs}\ndirs=${idirs}\nlibrary_arch=${library_arch}\nlinker_tool=${linker_tool}\n")
  164. if(t MATCHES "windows" AND NOT CMAKE_HOST_WIN32)
  165. string(REPLACE "\\" "/" linker_tool "${linker_tool}")
  166. cmake_path(NORMAL_PATH linker_tool)
  167. endif()
  168. if(t MATCHES "-empty$") # empty isn't supposed to parse
  169. if("${state}" STREQUAL "done")
  170. message("empty parse failed: ${idirs}, log=${log}")
  171. endif()
  172. elseif(NOT "${idirs}" MATCHES "^${idirs_output}$")
  173. message("${t} parse failed: state=${state}, '${idirs}' does not match '^${idirs_output}$'")
  174. elseif(NOT "${implicit_libs}" MATCHES "^${implicit_lib_output}$")
  175. message("${t} parse failed: state=${state}, '${implicit_libs}' does not match '^${implicit_lib_output}$'")
  176. elseif((library_arch OR library_arch_output) AND NOT "${library_arch}" MATCHES "^${library_arch_output}$")
  177. message("${t} parse failed: state=${state}, '${library_arch}' does not match '^${library_arch_output}$'")
  178. elseif((linker_tool OR linker_tool_output) AND NOT "${linker_tool}" MATCHES "^${linker_tool_output}$")
  179. message("${t} parse failed: state=${state}, '${linker_tool}' does not match '^${linker_tool_output}$'")
  180. endif()
  181. endblock()
  182. endforeach(t)