1
0

CMakeParseImplicitLinkInfo.cmake 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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)
  17. set(implicit_libs "")
  18. set(implicit_dirs_tmp)
  19. # Parse implicit linker arguments.
  20. set(linker "CMAKE_LINKER-NOTFOUND")
  21. if(CMAKE_LINKER)
  22. get_filename_component(linker ${CMAKE_LINKER} NAME)
  23. endif()
  24. set(linker_regex "^( *|.*/)(${linker}|ld|collect2)")
  25. string(REGEX REPLACE "\r?\n" ";" output_lines "${text}")
  26. foreach(line IN LISTS output_lines)
  27. set(cmd)
  28. if("${line}" MATCHES "${linker_regex}")
  29. if(UNIX)
  30. separate_arguments(args UNIX_COMMAND "${line}")
  31. else()
  32. separate_arguments(args WINDOWS_COMMAND "${line}")
  33. endif()
  34. list(GET args 0 cmd)
  35. endif()
  36. if("${cmd}" MATCHES "${linker_regex}")
  37. string(REGEX REPLACE ";-([LYz]);" ";-\\1" args "${args}")
  38. foreach(arg IN LISTS args)
  39. if("${arg}" MATCHES "^-L(.:)?[/\\]")
  40. # Unix search path.
  41. string(REGEX REPLACE "^-L" "" dir "${arg}")
  42. list(APPEND implicit_dirs_tmp ${dir})
  43. elseif("${arg}" MATCHES "^-l[^:]")
  44. # Unix library.
  45. string(REGEX REPLACE "^-l" "" lib "${arg}")
  46. list(APPEND implicit_libs ${lib})
  47. elseif("${arg}" MATCHES "^(.:)?[/\\].*\\.a$")
  48. # Unix library full path.
  49. list(APPEND implicit_libs ${arg})
  50. elseif("${arg}" MATCHES "^-Y(P,)?")
  51. # Sun search path.
  52. string(REGEX REPLACE "^-Y(P,)?" "" dirs "${arg}")
  53. string(REPLACE ":" ";" dirs "${dirs}")
  54. list(APPEND implicit_dirs_tmp ${dirs})
  55. elseif("${arg}" MATCHES "^-l:")
  56. # HP named library.
  57. list(APPEND implicit_libs ${arg})
  58. elseif("${arg}" MATCHES "^-z(all|default|weak)extract")
  59. # Link editor option.
  60. list(APPEND implicit_libs ${arg})
  61. endif()
  62. endforeach()
  63. break()
  64. elseif("${line}" MATCHES "LPATH(=| is:? )")
  65. # HP search path.
  66. string(REGEX REPLACE ".*LPATH(=| is:? *)" "" paths "${line}")
  67. string(REPLACE ":" ";" paths "${paths}")
  68. list(APPEND implicit_dirs_tmp ${paths})
  69. endif()
  70. endforeach()
  71. # Cleanup list of directories.
  72. set(implicit_dirs "")
  73. foreach(d IN LISTS implicit_dirs_tmp)
  74. get_filename_component(dir "${d}" ABSOLUTE)
  75. list(APPEND implicit_dirs "${dir}")
  76. endforeach()
  77. list(REMOVE_DUPLICATES implicit_dirs)
  78. # Return results.
  79. set(${lib_var} "${implicit_libs}" PARENT_SCOPE)
  80. set(${dir_var} "${implicit_dirs}" PARENT_SCOPE)
  81. endfunction()