diff options
author | Brad King <brad.king@kitware.com> | 2009-07-23 14:07:25 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2009-07-23 14:07:25 (GMT) |
commit | 07ea19ad1f280e7a1cb07ab2b52c0081f72251dd (patch) | |
tree | 3844b6660772215cdae9420ddcfa3574be35e8db /Modules/CMakeParseImplicitLinkInfo.cmake | |
parent | 797e49a1cc53fb120fad286665c875075eb18361 (diff) | |
download | CMake-07ea19ad1f280e7a1cb07ab2b52c0081f72251dd.zip CMake-07ea19ad1f280e7a1cb07ab2b52c0081f72251dd.tar.gz CMake-07ea19ad1f280e7a1cb07ab2b52c0081f72251dd.tar.bz2 |
ENH: Implicit link info for C, CXX, and Fortran
This teaches CMake to detect implicit link information for C, C++, and
Fortran compilers. We detect the implicit linker search directories and
implicit linker options for UNIX-like environments using verbose output
from compiler front-ends. We store results in new variables called
CMAKE_<LANG>_IMPLICIT_LINK_LIBRARIES
CMAKE_<LANG>_IMPLICIT_LINK_DIRECTORIES
The implicit libraries can contain linker flags as well as library
names.
Diffstat (limited to 'Modules/CMakeParseImplicitLinkInfo.cmake')
-rw-r--r-- | Modules/CMakeParseImplicitLinkInfo.cmake | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/Modules/CMakeParseImplicitLinkInfo.cmake b/Modules/CMakeParseImplicitLinkInfo.cmake new file mode 100644 index 0000000..b56781f --- /dev/null +++ b/Modules/CMakeParseImplicitLinkInfo.cmake @@ -0,0 +1,71 @@ + +# Function parse implicit linker options. +# This is used internally by CMake and should not be included by user +# code. + +function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var) + set(implicit_libs "") + set(implicit_dirs_tmp) + + # Parse implicit linker arguments. + set(linker "CMAKE_LINKER-NOTFOUND") + if(CMAKE_LINKER) + get_filename_component(linker ${CMAKE_LINKER} NAME) + endif() + set(linker_regex "/(${linker}|ld|collect2)") + string(REGEX REPLACE "\r?\n" ";" output_lines "${text}") + foreach(line IN LISTS output_lines) + set(cmd) + if("${line}" MATCHES "${linker_regex}") + 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}") + string(REGEX REPLACE ";-([LY]);" ";-\\1" args "${args}") + foreach(arg IN LISTS args) + if("${arg}" MATCHES "^-L(.:)?[/\\]") + # Unix search path. + string(REGEX REPLACE "^-L" "" dir "${arg}") + list(APPEND implicit_dirs_tmp ${dir}) + elseif("${arg}" MATCHES "^-l[^:]") + # Unix library. + string(REGEX REPLACE "^-l" "" lib "${arg}") + list(APPEND implicit_libs ${lib}) + elseif("${arg}" MATCHES "^(.:)?[/\\].*\\.a$") + # Unix library full path. + list(APPEND implicit_libs ${arg}) + elseif("${arg}" MATCHES "^-Y(P,)?") + # Sun search path. + string(REGEX REPLACE "^-Y(P,)?" "" dirs "${arg}") + string(REPLACE ":" ";" dirs "${dirs}") + list(APPEND implicit_dirs_tmp ${dirs}) + elseif("${arg}" MATCHES "^-l:") + # HP named library. + list(APPEND implicit_libs ${arg}) + endif() + endforeach() + break() + elseif("${line}" MATCHES "LPATH(=| is:? )") + # HP search path. + string(REGEX REPLACE ".*LPATH(=| is:? *)" "" paths "${line}") + string(REPLACE ":" ";" paths "${paths}") + list(APPEND implicit_dirs_tmp ${paths}) + endif() + endforeach() + + # Cleanup list of directories. + set(implicit_dirs "") + foreach(d IN LISTS implicit_dirs_tmp) + get_filename_component(dir "${d}" ABSOLUTE) + list(APPEND implicit_dirs "${dir}") + endforeach() + list(REMOVE_DUPLICATES implicit_dirs) + + # Return results. + set(${lib_var} "${implicit_libs}" PARENT_SCOPE) + set(${dir_var} "${implicit_dirs}" PARENT_SCOPE) +endfunction() |