ParseImplicitLinkInfo.cmake 6.5 KB

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