2009-07-23 18:07:25 +04:00
|
|
|
|
2009-09-28 19:46:51 +04:00
|
|
|
#=============================================================================
|
|
|
|
# Copyright 2009 Kitware, Inc.
|
|
|
|
#
|
|
|
|
# Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
# see accompanying file Copyright.txt for details.
|
|
|
|
#
|
|
|
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
# See the License for more information.
|
|
|
|
#=============================================================================
|
2010-08-07 04:48:47 +04:00
|
|
|
# (To distribute this file outside of CMake, substitute the full
|
2009-09-28 19:46:51 +04:00
|
|
|
# License text for the above reference.)
|
|
|
|
|
2009-07-23 18:07:25 +04:00
|
|
|
# Function parse implicit linker options.
|
|
|
|
# This is used internally by CMake and should not be included by user
|
|
|
|
# code.
|
|
|
|
|
2012-12-05 22:46:04 +04:00
|
|
|
function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var fwk_var log_var obj_regex)
|
2009-11-05 20:17:08 +03:00
|
|
|
set(implicit_libs_tmp "")
|
2009-07-23 18:07:25 +04:00
|
|
|
set(implicit_dirs_tmp)
|
2012-12-05 22:46:04 +04:00
|
|
|
set(implicit_fwks_tmp)
|
2009-10-06 23:16:12 +04:00
|
|
|
set(log "")
|
2009-07-23 18:07:25 +04:00
|
|
|
|
|
|
|
# Parse implicit linker arguments.
|
|
|
|
set(linker "CMAKE_LINKER-NOTFOUND")
|
|
|
|
if(CMAKE_LINKER)
|
|
|
|
get_filename_component(linker ${CMAKE_LINKER} NAME)
|
|
|
|
endif()
|
2009-10-07 16:43:51 +04:00
|
|
|
# Construct a regex to match linker lines. It must match both the
|
|
|
|
# whole line and just the command (argv[0]).
|
|
|
|
set(linker_regex "^( *|.*[/\\])(${linker}|ld|collect2)[^/\\]*( |$)")
|
2011-01-24 19:18:18 +03:00
|
|
|
set(linker_exclude_regex "collect2 version ")
|
2009-10-07 00:31:43 +04:00
|
|
|
set(log "${log} link line regex: [${linker_regex}]\n")
|
2009-07-23 18:07:25 +04:00
|
|
|
string(REGEX REPLACE "\r?\n" ";" output_lines "${text}")
|
|
|
|
foreach(line IN LISTS output_lines)
|
|
|
|
set(cmd)
|
2011-01-24 19:18:18 +03:00
|
|
|
if("${line}" MATCHES "${linker_regex}" AND
|
|
|
|
NOT "${line}" MATCHES "${linker_exclude_regex}")
|
2012-12-05 20:49:13 +04:00
|
|
|
if(XCODE)
|
|
|
|
# Xcode unconditionally adds a path under the project build tree and
|
|
|
|
# on older versions it is not reported with proper quotes. Remove it.
|
|
|
|
string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" _dir_regex "${CMAKE_BINARY_DIR}")
|
|
|
|
string(REGEX REPLACE " -[FL]${_dir_regex}/([^ ]| [^-])+( |$)" " " xline "${line}")
|
|
|
|
if(NOT "x${xline}" STREQUAL "x${line}")
|
|
|
|
set(log "${log} reduced line: [${line}]\n to: [${xline}]\n")
|
|
|
|
set(line "${xline}")
|
|
|
|
endif()
|
|
|
|
endif()
|
2009-07-23 18:07:25 +04:00
|
|
|
if(UNIX)
|
|
|
|
separate_arguments(args UNIX_COMMAND "${line}")
|
|
|
|
else()
|
|
|
|
separate_arguments(args WINDOWS_COMMAND "${line}")
|
|
|
|
endif()
|
|
|
|
list(GET args 0 cmd)
|
|
|
|
endif()
|
|
|
|
if("${cmd}" MATCHES "${linker_regex}")
|
2009-10-06 23:16:12 +04:00
|
|
|
set(log "${log} link line: [${line}]\n")
|
2009-07-28 16:36:11 +04:00
|
|
|
string(REGEX REPLACE ";-([LYz]);" ";-\\1" args "${args}")
|
2009-07-23 18:07:25 +04:00
|
|
|
foreach(arg IN LISTS args)
|
|
|
|
if("${arg}" MATCHES "^-L(.:)?[/\\]")
|
|
|
|
# Unix search path.
|
|
|
|
string(REGEX REPLACE "^-L" "" dir "${arg}")
|
|
|
|
list(APPEND implicit_dirs_tmp ${dir})
|
2009-10-06 23:16:12 +04:00
|
|
|
set(log "${log} arg [${arg}] ==> dir [${dir}]\n")
|
2009-07-23 18:07:25 +04:00
|
|
|
elseif("${arg}" MATCHES "^-l[^:]")
|
|
|
|
# Unix library.
|
|
|
|
string(REGEX REPLACE "^-l" "" lib "${arg}")
|
2009-11-05 20:17:08 +03:00
|
|
|
list(APPEND implicit_libs_tmp ${lib})
|
2009-10-06 23:16:12 +04:00
|
|
|
set(log "${log} arg [${arg}] ==> lib [${lib}]\n")
|
2009-07-23 18:07:25 +04:00
|
|
|
elseif("${arg}" MATCHES "^(.:)?[/\\].*\\.a$")
|
|
|
|
# Unix library full path.
|
2009-11-05 20:17:08 +03:00
|
|
|
list(APPEND implicit_libs_tmp ${arg})
|
2009-10-06 23:16:12 +04:00
|
|
|
set(log "${log} arg [${arg}] ==> lib [${arg}]\n")
|
2010-12-10 01:07:34 +03:00
|
|
|
elseif("${arg}" MATCHES "^(.:)?[/\\].*\\.o$"
|
|
|
|
AND obj_regex AND "${arg}" MATCHES "${obj_regex}")
|
|
|
|
# Object file full path.
|
|
|
|
list(APPEND implicit_libs_tmp ${arg})
|
|
|
|
set(log "${log} arg [${arg}] ==> obj [${arg}]\n")
|
2011-01-24 19:18:18 +03:00
|
|
|
elseif("${arg}" MATCHES "^-Y(P,)?[^0-9]")
|
|
|
|
# Sun search path ([^0-9] avoids conflict with Mac -Y<num>).
|
2009-07-23 18:07:25 +04:00
|
|
|
string(REGEX REPLACE "^-Y(P,)?" "" dirs "${arg}")
|
|
|
|
string(REPLACE ":" ";" dirs "${dirs}")
|
|
|
|
list(APPEND implicit_dirs_tmp ${dirs})
|
2009-10-06 23:16:12 +04:00
|
|
|
set(log "${log} arg [${arg}] ==> dirs [${dirs}]\n")
|
2009-07-23 18:07:25 +04:00
|
|
|
elseif("${arg}" MATCHES "^-l:")
|
|
|
|
# HP named library.
|
2009-11-05 20:17:08 +03:00
|
|
|
list(APPEND implicit_libs_tmp ${arg})
|
2009-10-06 23:16:12 +04:00
|
|
|
set(log "${log} arg [${arg}] ==> lib [${arg}]\n")
|
2009-07-28 16:36:11 +04:00
|
|
|
elseif("${arg}" MATCHES "^-z(all|default|weak)extract")
|
|
|
|
# Link editor option.
|
2009-11-05 20:17:08 +03:00
|
|
|
list(APPEND implicit_libs_tmp ${arg})
|
2009-10-06 23:16:12 +04:00
|
|
|
set(log "${log} arg [${arg}] ==> opt [${arg}]\n")
|
|
|
|
else()
|
|
|
|
set(log "${log} arg [${arg}] ==> ignore\n")
|
2009-07-23 18:07:25 +04:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
break()
|
|
|
|
elseif("${line}" MATCHES "LPATH(=| is:? )")
|
2009-10-06 23:16:12 +04:00
|
|
|
set(log "${log} LPATH line: [${line}]\n")
|
2009-07-23 18:07:25 +04:00
|
|
|
# HP search path.
|
|
|
|
string(REGEX REPLACE ".*LPATH(=| is:? *)" "" paths "${line}")
|
|
|
|
string(REPLACE ":" ";" paths "${paths}")
|
|
|
|
list(APPEND implicit_dirs_tmp ${paths})
|
2009-10-06 23:16:12 +04:00
|
|
|
set(log "${log} dirs [${paths}]\n")
|
|
|
|
else()
|
|
|
|
set(log "${log} ignore line: [${line}]\n")
|
2009-07-23 18:07:25 +04:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2012-12-05 20:49:13 +04:00
|
|
|
# Look for library search paths reported by linker.
|
|
|
|
if("${output_lines}" MATCHES ";Library search paths:((;\t[^;]+)+)")
|
|
|
|
string(REPLACE ";\t" ";" implicit_dirs_match "${CMAKE_MATCH_1}")
|
|
|
|
set(log "${log} Library search paths: [${implicit_dirs_match}]\n")
|
|
|
|
list(APPEND implicit_dirs_tmp ${implicit_dirs_match})
|
|
|
|
endif()
|
2012-12-05 22:46:04 +04:00
|
|
|
if("${output_lines}" MATCHES ";Framework search paths:((;\t[^;]+)+)")
|
|
|
|
string(REPLACE ";\t" ";" implicit_fwks_match "${CMAKE_MATCH_1}")
|
|
|
|
set(log "${log} Framework search paths: [${implicit_fwks_match}]\n")
|
|
|
|
list(APPEND implicit_fwks_tmp ${implicit_fwks_match})
|
|
|
|
endif()
|
2012-12-05 20:49:13 +04:00
|
|
|
|
2009-11-05 20:17:08 +03:00
|
|
|
# Cleanup list of libraries and flags.
|
|
|
|
# We remove items that are not language-specific.
|
|
|
|
set(implicit_libs "")
|
|
|
|
foreach(lib IN LISTS implicit_libs_tmp)
|
|
|
|
if("${lib}" MATCHES "^(crt.*\\.o|gcc.*|System.*)$")
|
|
|
|
set(log "${log} remove lib [${lib}]\n")
|
|
|
|
else()
|
|
|
|
list(APPEND implicit_libs "${lib}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2012-12-05 22:46:04 +04:00
|
|
|
# Cleanup list of library and framework directories.
|
|
|
|
set(desc_dirs "library")
|
|
|
|
set(desc_fwks "framework")
|
|
|
|
foreach(t dirs fwks)
|
|
|
|
set(implicit_${t} "")
|
|
|
|
foreach(d IN LISTS implicit_${t}_tmp)
|
|
|
|
get_filename_component(dir "${d}" ABSOLUTE)
|
|
|
|
string(FIND "${dir}" "${CMAKE_FILES_DIRECTORY}/" pos)
|
|
|
|
if(NOT pos LESS 0)
|
|
|
|
set(msg ", skipping non-system directory")
|
|
|
|
else()
|
|
|
|
set(msg "")
|
|
|
|
list(APPEND implicit_${t} "${dir}")
|
|
|
|
endif()
|
|
|
|
set(log "${log} collapse ${desc_${t}} dir [${d}] ==> [${dir}]${msg}\n")
|
|
|
|
endforeach()
|
|
|
|
list(REMOVE_DUPLICATES implicit_${t})
|
2009-07-23 18:07:25 +04:00
|
|
|
endforeach()
|
|
|
|
|
2009-10-06 23:16:12 +04:00
|
|
|
# Log results.
|
|
|
|
set(log "${log} implicit libs: [${implicit_libs}]\n")
|
|
|
|
set(log "${log} implicit dirs: [${implicit_dirs}]\n")
|
2012-12-05 22:46:04 +04:00
|
|
|
set(log "${log} implicit fwks: [${implicit_fwks}]\n")
|
2009-10-06 23:16:12 +04:00
|
|
|
|
2009-07-23 18:07:25 +04:00
|
|
|
# Return results.
|
|
|
|
set(${lib_var} "${implicit_libs}" PARENT_SCOPE)
|
|
|
|
set(${dir_var} "${implicit_dirs}" PARENT_SCOPE)
|
2012-12-05 22:46:04 +04:00
|
|
|
set(${fwk_var} "${implicit_fwks}" PARENT_SCOPE)
|
2009-10-06 23:16:12 +04:00
|
|
|
set(${log_var} "${log}" PARENT_SCOPE)
|
2009-07-23 18:07:25 +04:00
|
|
|
endfunction()
|