2 # Function parse implicit linker options.
3 # This is used internally by CMake and should not be included by user
6 function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var)
10 # Parse implicit linker arguments.
11 set(linker "CMAKE_LINKER-NOTFOUND")
13 get_filename_component(linker ${CMAKE_LINKER} NAME)
15 set(linker_regex "^( *|.*/)(${linker}|ld|collect2)")
16 string(REGEX REPLACE "\r?\n" ";" output_lines "${text}")
17 foreach(line IN LISTS output_lines)
19 if("${line}" MATCHES "${linker_regex}")
21 separate_arguments(args UNIX_COMMAND "${line}")
23 separate_arguments(args WINDOWS_COMMAND "${line}")
27 if("${cmd}" MATCHES "${linker_regex}")
28 string(REGEX REPLACE ";-([LYz]);" ";-\\1" args "${args}")
29 foreach(arg IN LISTS args)
30 if("${arg}" MATCHES "^-L(.:)?[/\\]")
32 string(REGEX REPLACE "^-L" "" dir "${arg}")
33 list(APPEND implicit_dirs_tmp ${dir})
34 elseif("${arg}" MATCHES "^-l[^:]")
36 string(REGEX REPLACE "^-l" "" lib "${arg}")
37 list(APPEND implicit_libs ${lib})
38 elseif("${arg}" MATCHES "^(.:)?[/\\].*\\.a$")
39 # Unix library full path.
40 list(APPEND implicit_libs ${arg})
41 elseif("${arg}" MATCHES "^-Y(P,)?")
43 string(REGEX REPLACE "^-Y(P,)?" "" dirs "${arg}")
44 string(REPLACE ":" ";" dirs "${dirs}")
45 list(APPEND implicit_dirs_tmp ${dirs})
46 elseif("${arg}" MATCHES "^-l:")
48 list(APPEND implicit_libs ${arg})
49 elseif("${arg}" MATCHES "^-z(all|default|weak)extract")
51 list(APPEND implicit_libs ${arg})
55 elseif("${line}" MATCHES "LPATH(=| is:? )")
57 string(REGEX REPLACE ".*LPATH(=| is:? *)" "" paths "${line}")
58 string(REPLACE ":" ";" paths "${paths}")
59 list(APPEND implicit_dirs_tmp ${paths})
63 # Cleanup list of directories.
65 foreach(d IN LISTS implicit_dirs_tmp)
66 get_filename_component(dir "${d}" ABSOLUTE)
67 list(APPEND implicit_dirs "${dir}")
69 list(REMOVE_DUPLICATES implicit_dirs)
72 set(${lib_var} "${implicit_libs}" PARENT_SCOPE)
73 set(${dir_var} "${implicit_dirs}" PARENT_SCOPE)