CMakeParseImplicitLinkInfo.cmake 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Function parse implicit linker options.
  2. # This is used internally by CMake and should not be included by user
  3. # code.
  4. function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var)
  5. set(implicit_libs "")
  6. set(implicit_dirs_tmp)
  7. # Parse implicit linker arguments.
  8. set(linker "CMAKE_LINKER-NOTFOUND")
  9. if(CMAKE_LINKER)
  10. get_filename_component(linker ${CMAKE_LINKER} NAME)
  11. endif()
  12. set(linker_regex "/(${linker}|ld|collect2)")
  13. string(REGEX REPLACE "\r?\n" ";" output_lines "${text}")
  14. foreach(line IN LISTS output_lines)
  15. set(cmd)
  16. if("${line}" MATCHES "${linker_regex}")
  17. if(UNIX)
  18. separate_arguments(args UNIX_COMMAND "${line}")
  19. else()
  20. separate_arguments(args WINDOWS_COMMAND "${line}")
  21. endif()
  22. list(GET args 0 cmd)
  23. endif()
  24. if("${cmd}" MATCHES "${linker_regex}")
  25. string(REGEX REPLACE ";-([LY]);" ";-\\1" args "${args}")
  26. foreach(arg IN LISTS args)
  27. if("${arg}" MATCHES "^-L(.:)?[/\\]")
  28. # Unix search path.
  29. string(REGEX REPLACE "^-L" "" dir "${arg}")
  30. list(APPEND implicit_dirs_tmp ${dir})
  31. elseif("${arg}" MATCHES "^-l[^:]")
  32. # Unix library.
  33. string(REGEX REPLACE "^-l" "" lib "${arg}")
  34. list(APPEND implicit_libs ${lib})
  35. elseif("${arg}" MATCHES "^(.:)?[/\\].*\\.a$")
  36. # Unix library full path.
  37. list(APPEND implicit_libs ${arg})
  38. elseif("${arg}" MATCHES "^-Y(P,)?")
  39. # Sun search path.
  40. string(REGEX REPLACE "^-Y(P,)?" "" dirs "${arg}")
  41. string(REPLACE ":" ";" dirs "${dirs}")
  42. list(APPEND implicit_dirs_tmp ${dirs})
  43. elseif("${arg}" MATCHES "^-l:")
  44. # HP named library.
  45. list(APPEND implicit_libs ${arg})
  46. endif()
  47. endforeach()
  48. break()
  49. elseif("${line}" MATCHES "LPATH(=| is:? )")
  50. # HP search path.
  51. string(REGEX REPLACE ".*LPATH(=| is:? *)" "" paths "${line}")
  52. string(REPLACE ":" ";" paths "${paths}")
  53. list(APPEND implicit_dirs_tmp ${paths})
  54. endif()
  55. endforeach()
  56. # Cleanup list of directories.
  57. set(implicit_dirs "")
  58. foreach(d IN LISTS implicit_dirs_tmp)
  59. get_filename_component(dir "${d}" ABSOLUTE)
  60. list(APPEND implicit_dirs "${dir}")
  61. endforeach()
  62. list(REMOVE_DUPLICATES implicit_dirs)
  63. # Return results.
  64. set(${lib_var} "${implicit_libs}" PARENT_SCOPE)
  65. set(${dir_var} "${implicit_dirs}" PARENT_SCOPE)
  66. endfunction()