From fff1c6d275cd24294cb0848b245d166b77e55c12 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 7 Oct 2009 08:43:51 -0400 Subject: [PATCH] More robust implicit link line detection regex The regex used by CMAKE_PARSE_IMPLICIT_LINK_INFO to detect link lines should not match lines that happen to have ".../ld.../..." in them. A linker name should match only as the last component of a path. See issue #9666. --- Modules/CMakeParseImplicitLinkInfo.cmake | 4 +++- Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Modules/CMakeParseImplicitLinkInfo.cmake b/Modules/CMakeParseImplicitLinkInfo.cmake index 1251f8611..b8a681f56 100644 --- a/Modules/CMakeParseImplicitLinkInfo.cmake +++ b/Modules/CMakeParseImplicitLinkInfo.cmake @@ -26,7 +26,9 @@ function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var log_var) if(CMAKE_LINKER) get_filename_component(linker ${CMAKE_LINKER} NAME) endif() - set(linker_regex "^( *|.*/)(${linker}|ld|collect2)") + # 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)[^/\\]*( |$)") set(log "${log} link line regex: [${linker_regex}]\n") string(REGEX REPLACE "\r?\n" ";" output_lines "${text}") foreach(line IN LISTS output_lines) diff --git a/Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in b/Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in index eba98a2b7..8231990a1 100644 --- a/Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in +++ b/Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in @@ -77,6 +77,14 @@ set(linux64_pgf90_libs "pgf90;pgf90_rpm1;pgf902;pgf90rtl;pgftnrtl;nspgc;pgc;rt;p set(linux64_pgf90_dirs "/opt/compiler/pgi/linux86-64/8.0-3/lib;/usr/lib64;/usr/lib64/gcc/x86_64-suse-linux/4.1.2") list(APPEND platforms linux64_pgf90) +# gcc dummy.c -v # in strange path +set(linux64_test1_text " +/this/might/match/as/a/linker/ld/but/it/is/not because the ld is not the last path component +${linux64_gcc_text}") +set(linux64_test1_libs "${linux64_gcc_libs}") +set(linux64_test1_dirs "${linux64_gcc_dirs}") +list(APPEND platforms linux64_test1) + #----------------------------------------------------------------------------- # Sun