CMakeParseImplicitLinkInfo.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #=============================================================================
  2. # Copyright 2009 Kitware, Inc.
  3. #
  4. # Distributed under the OSI-approved BSD License (the "License");
  5. # see accompanying file Copyright.txt for details.
  6. #
  7. # This software is distributed WITHOUT ANY WARRANTY; without even the
  8. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. # See the License for more information.
  10. #=============================================================================
  11. # (To distributed this file outside of CMake, substitute the full
  12. # License text for the above reference.)
  13. # Function parse implicit linker options.
  14. # This is used internally by CMake and should not be included by user
  15. # code.
  16. function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var log_var)
  17. set(implicit_libs "")
  18. set(implicit_dirs_tmp)
  19. set(log "")
  20. # Parse implicit linker arguments.
  21. set(linker "CMAKE_LINKER-NOTFOUND")
  22. if(CMAKE_LINKER)
  23. get_filename_component(linker ${CMAKE_LINKER} NAME)
  24. endif()
  25. set(linker_regex "^( *|.*/)(${linker}|ld|collect2)")
  26. set(log "${log} link line regex: [${linker_regex}]\n")
  27. string(REGEX REPLACE "\r?\n" ";" output_lines "${text}")
  28. foreach(line IN LISTS output_lines)
  29. set(cmd)
  30. if("${line}" MATCHES "${linker_regex}")
  31. if(UNIX)
  32. separate_arguments(args UNIX_COMMAND "${line}")
  33. else()
  34. separate_arguments(args WINDOWS_COMMAND "${line}")
  35. endif()
  36. list(GET args 0 cmd)
  37. endif()
  38. if("${cmd}" MATCHES "${linker_regex}")
  39. set(log "${log} link line: [${line}]\n")
  40. string(REGEX REPLACE ";-([LYz]);" ";-\\1" args "${args}")
  41. foreach(arg IN LISTS args)
  42. if("${arg}" MATCHES "^-L(.:)?[/\\]")
  43. # Unix search path.
  44. string(REGEX REPLACE "^-L" "" dir "${arg}")
  45. list(APPEND implicit_dirs_tmp ${dir})
  46. set(log "${log} arg [${arg}] ==> dir [${dir}]\n")
  47. elseif("${arg}" MATCHES "^-l[^:]")
  48. # Unix library.
  49. string(REGEX REPLACE "^-l" "" lib "${arg}")
  50. list(APPEND implicit_libs ${lib})
  51. set(log "${log} arg [${arg}] ==> lib [${lib}]\n")
  52. elseif("${arg}" MATCHES "^(.:)?[/\\].*\\.a$")
  53. # Unix library full path.
  54. list(APPEND implicit_libs ${arg})
  55. set(log "${log} arg [${arg}] ==> lib [${arg}]\n")
  56. elseif("${arg}" MATCHES "^-Y(P,)?")
  57. # Sun search path.
  58. string(REGEX REPLACE "^-Y(P,)?" "" dirs "${arg}")
  59. string(REPLACE ":" ";" dirs "${dirs}")
  60. list(APPEND implicit_dirs_tmp ${dirs})
  61. set(log "${log} arg [${arg}] ==> dirs [${dirs}]\n")
  62. elseif("${arg}" MATCHES "^-l:")
  63. # HP named library.
  64. list(APPEND implicit_libs ${arg})
  65. set(log "${log} arg [${arg}] ==> lib [${arg}]\n")
  66. elseif("${arg}" MATCHES "^-z(all|default|weak)extract")
  67. # Link editor option.
  68. list(APPEND implicit_libs ${arg})
  69. set(log "${log} arg [${arg}] ==> opt [${arg}]\n")
  70. else()
  71. set(log "${log} arg [${arg}] ==> ignore\n")
  72. endif()
  73. endforeach()
  74. break()
  75. elseif("${line}" MATCHES "LPATH(=| is:? )")
  76. set(log "${log} LPATH line: [${line}]\n")
  77. # HP search path.
  78. string(REGEX REPLACE ".*LPATH(=| is:? *)" "" paths "${line}")
  79. string(REPLACE ":" ";" paths "${paths}")
  80. list(APPEND implicit_dirs_tmp ${paths})
  81. set(log "${log} dirs [${paths}]\n")
  82. else()
  83. set(log "${log} ignore line: [${line}]\n")
  84. endif()
  85. endforeach()
  86. # Cleanup list of directories.
  87. set(implicit_dirs "")
  88. foreach(d IN LISTS implicit_dirs_tmp)
  89. get_filename_component(dir "${d}" ABSOLUTE)
  90. list(APPEND implicit_dirs "${dir}")
  91. set(log "${log} collapse dir [${d}] ==> [${dir}]\n")
  92. endforeach()
  93. list(REMOVE_DUPLICATES implicit_dirs)
  94. # Log results.
  95. set(log "${log} implicit libs: [${implicit_libs}]\n")
  96. set(log "${log} implicit dirs: [${implicit_dirs}]\n")
  97. # Return results.
  98. set(${lib_var} "${implicit_libs}" PARENT_SCOPE)
  99. set(${dir_var} "${implicit_dirs}" PARENT_SCOPE)
  100. set(${log_var} "${log}" PARENT_SCOPE)
  101. endfunction()