From be94c494eda5437bd7c026f6619d6ab040593e7a Mon Sep 17 00:00:00 2001 From: David Partyka Date: Mon, 25 Oct 2010 13:40:35 -0400 Subject: [PATCH 1/5] Fixed appending PATH to dumpbin tool from growing without bounds. IF(... MATCHES ...) used for comparing directories chokes especially in the case of C:\Program Files (x86)\ because of regex pattern matching. Switched this to use STREQUAL in a loop instead. --- Modules/GetPrerequisites.cmake | 12 ++++++++++-- Tests/CMakeTests/GetPrerequisitesTest.cmake.in | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Modules/GetPrerequisites.cmake b/Modules/GetPrerequisites.cmake index c83da4f81..e1dae46c2 100644 --- a/Modules/GetPrerequisites.cmake +++ b/Modules/GetPrerequisites.cmake @@ -587,11 +587,19 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa # get_filename_component(gp_cmd_dir "${gp_cmd}" PATH) get_filename_component(gp_cmd_dlls_dir "${gp_cmd_dir}/../../Common7/IDE" ABSOLUTE) + file(TO_NATIVE_PATH "${gp_cmd_dlls_dir}" gp_cmd_dlls_dir) if(EXISTS "${gp_cmd_dlls_dir}") # only add to the path if it is not already in the path - if(NOT "$ENV{PATH}" MATCHES "${gp_cmd_dlls_dir}") + set(gp_found_cmd_dlls_dir 0) + foreach(gp_env_path_element $ENV{PATH}) + if("${gp_env_path_element}" STREQUAL "${gp_cmd_dlls_dir}") + set(gp_found_cmd_dlls_dir 1) + endif() + endforeach(gp_env_path_element) + + if(NOT gp_found_cmd_dlls_dir) set(ENV{PATH} "$ENV{PATH};${gp_cmd_dlls_dir}") - endif(NOT "$ENV{PATH}" MATCHES "${gp_cmd_dlls_dir}") + endif() endif(EXISTS "${gp_cmd_dlls_dir}") endif("${gp_tool}" STREQUAL "dumpbin") # diff --git a/Tests/CMakeTests/GetPrerequisitesTest.cmake.in b/Tests/CMakeTests/GetPrerequisitesTest.cmake.in index e8bfb47ae..182c22332 100644 --- a/Tests/CMakeTests/GetPrerequisitesTest.cmake.in +++ b/Tests/CMakeTests/GetPrerequisitesTest.cmake.in @@ -77,6 +77,11 @@ message(STATUS "") list_prerequisites("${CMAKE_COMMAND}" 0 0 1) message(STATUS "") +message(STATUS "=============================================================================") +string(LENGTH "$ENV{PATH}" PATH_LENGTH_BEGIN) +message(STATUS "Begin PATH length is: ${PATH_LENGTH_BEGIN}") +message(STATUS "") + # Leave the code for these tests in here, but turn them off by default... they # take longer than they're worth during development... @@ -139,6 +144,15 @@ foreach(v ${vs}) endforeach(v) message(STATUS "") +message(STATUS "=============================================================================") +string(LENGTH "$ENV{PATH}" PATH_LENGTH_END) +message(STATUS "Final PATH length is: ${PATH_LENGTH_END}") + +if(PATH_LENGTH_END GREATER ${PATH_LENGTH_BEGIN}) + message(FATAL_ERROR "list_prerequisties is endlessly appending the path of gp_tool to the PATH.") +endif() +message(STATUS "") + message(STATUS "=============================================================================") message(STATUS "End of test") From 16841987064cb79d3556034384458a36c4ceecef Mon Sep 17 00:00:00 2001 From: David Partyka Date: Tue, 26 Oct 2010 10:03:21 -0400 Subject: [PATCH 2/5] Switch to CMAKE_PATH when doing PATH comparisons on Windows. Users PATH may contain elements that end with backslash. This will escape the semicolon when iterating resulting in mismatches. Fix indentation. Fix whitespace --- Modules/GetPrerequisites.cmake | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Modules/GetPrerequisites.cmake b/Modules/GetPrerequisites.cmake index e1dae46c2..40b682e22 100644 --- a/Modules/GetPrerequisites.cmake +++ b/Modules/GetPrerequisites.cmake @@ -587,11 +587,14 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa # get_filename_component(gp_cmd_dir "${gp_cmd}" PATH) get_filename_component(gp_cmd_dlls_dir "${gp_cmd_dir}/../../Common7/IDE" ABSOLUTE) - file(TO_NATIVE_PATH "${gp_cmd_dlls_dir}" gp_cmd_dlls_dir) + # Use cmake paths as a user may have a PATH element ending with a backslash. + # This will escape the list delimiter and create havoc! + file(TO_CMAKE_PATH "${gp_cmd_dlls_dir}" gp_cmd_dlls_dir) if(EXISTS "${gp_cmd_dlls_dir}") # only add to the path if it is not already in the path set(gp_found_cmd_dlls_dir 0) - foreach(gp_env_path_element $ENV{PATH}) + file(TO_CMAKE_PATH "$ENV{PATH}" env_path) + foreach(gp_env_path_element ${env_path}) if("${gp_env_path_element}" STREQUAL "${gp_cmd_dlls_dir}") set(gp_found_cmd_dlls_dir 1) endif() From 8e550ba31e6b68d85f96bcb833d65e937a7139e2 Mon Sep 17 00:00:00 2001 From: David Partyka Date: Tue, 26 Oct 2010 10:27:41 -0400 Subject: [PATCH 3/5] Remove unecessary TO_CMAKE_PATH for gp_cmd_dir. It is already using CMAKE style paths. --- Modules/GetPrerequisites.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/Modules/GetPrerequisites.cmake b/Modules/GetPrerequisites.cmake index 40b682e22..e51ab576e 100644 --- a/Modules/GetPrerequisites.cmake +++ b/Modules/GetPrerequisites.cmake @@ -589,7 +589,6 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa get_filename_component(gp_cmd_dlls_dir "${gp_cmd_dir}/../../Common7/IDE" ABSOLUTE) # Use cmake paths as a user may have a PATH element ending with a backslash. # This will escape the list delimiter and create havoc! - file(TO_CMAKE_PATH "${gp_cmd_dlls_dir}" gp_cmd_dlls_dir) if(EXISTS "${gp_cmd_dlls_dir}") # only add to the path if it is not already in the path set(gp_found_cmd_dlls_dir 0) From bee4802840607c22d9d37cda8464c17fcdf26529 Mon Sep 17 00:00:00 2001 From: David Partyka Date: Tue, 26 Oct 2010 11:12:12 -0400 Subject: [PATCH 4/5] Append the gp_tool path to the system PATH using native slashes. --- Modules/GetPrerequisites.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/GetPrerequisites.cmake b/Modules/GetPrerequisites.cmake index e51ab576e..c877308bd 100644 --- a/Modules/GetPrerequisites.cmake +++ b/Modules/GetPrerequisites.cmake @@ -600,6 +600,7 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa endforeach(gp_env_path_element) if(NOT gp_found_cmd_dlls_dir) + file(TO_NATIVE_PATH "${gp_cmd_dlls_dir}" gp_cmd_dlls_dir) set(ENV{PATH} "$ENV{PATH};${gp_cmd_dlls_dir}") endif() endif(EXISTS "${gp_cmd_dlls_dir}") From 48e80eb7246683f471f3886436020d34c784be86 Mon Sep 17 00:00:00 2001 From: David Partyka Date: Wed, 27 Oct 2010 17:23:00 -0400 Subject: [PATCH 5/5] Fixes to GetPrerequisites for cygwin Fix IF(WIN32) guards check for cygwin. Fix checking if the depenency is in a system location to use cygwin style paths on cygwin. Also change GetPrerequisites to switch gp_tool to tools that are very unlikely to be found, ie. dumpbin on Apple and otool on Windows/Unix. --- Modules/GetPrerequisites.cmake | 36 ++++++++++++++----- .../CMakeTests/GetPrerequisitesTest.cmake.in | 8 ++--- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/Modules/GetPrerequisites.cmake b/Modules/GetPrerequisites.cmake index c877308bd..853b1a1b6 100644 --- a/Modules/GetPrerequisites.cmake +++ b/Modules/GetPrerequisites.cmake @@ -146,7 +146,7 @@ function(is_file_executable file result_var) # If file name ends in .exe on Windows, *assume* executable: # - if(WIN32) + if(WIN32 AND NOT UNIX) if("${file_full_lower}" MATCHES "\\.exe$") set(${result_var} 1 PARENT_SCOPE) return() @@ -156,7 +156,7 @@ function(is_file_executable file result_var) # to determine ${result_var}. In 99%+? practical cases, the exe name # match will be sufficient... # - endif(WIN32) + endif(WIN32 AND NOT UNIX) # Use the information returned from the Unix shell command "file" to # determine if ${file_full} should be considered an executable file... @@ -335,7 +335,7 @@ function(gp_resolve_item context item exepath dirs resolved_item_var) # Using find_program on Windows will find dll files that are in the PATH. # (Converting simple file names into full path names if found.) # - if(WIN32) + if(WIN32 AND NOT UNIX) if(NOT resolved) set(ri "ri-NOTFOUND") find_program(ri "${item}" PATHS "${exepath};${dirs}" NO_DEFAULT_PATH) @@ -347,7 +347,7 @@ function(gp_resolve_item context item exepath dirs resolved_item_var) set(ri "ri-NOTFOUND") endif(ri) endif(NOT resolved) - endif(WIN32) + endif(WIN32 AND NOT UNIX) # Provide a hook so that projects can override item resolution # by whatever logic they choose: @@ -413,7 +413,7 @@ function(gp_resolved_file_type original_file file exepath dirs type_var) string(TOLOWER "${resolved_file}" lower) if(UNIX) - if(resolved_file MATCHES "^(/lib/|/lib32/|/lib64/|/usr/lib/|/usr/lib32/|/usr/lib64/|/usr/X11R6/)") + if(resolved_file MATCHES "^(/lib/|/lib32/|/lib64/|/usr/lib/|/usr/lib32/|/usr/lib64/|/usr/X11R6/|/usr/bin/)") set(is_system 1) endif() endif() @@ -434,7 +434,27 @@ function(gp_resolved_file_type original_file file exepath dirs type_var) if(lower MATCHES "^(${sysroot}/sys(tem|wow)|${windir}/sys(tem|wow)|(.*/)*msvc[^/]+dll)") set(is_system 1) endif() - endif() + + if(UNIX) + # if cygwin, we can get the properly formed windows paths from cygpath + find_program(CYGPATH_EXECUTABLE cygpath) + + if(CYGPATH_EXECUTABLE) + execute_process(COMMAND ${CYGPATH_EXECUTABLE} -W + OUTPUT_VARIABLE env_windir + OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND ${CYGPATH_EXECUTABLE} -S + OUTPUT_VARIABLE env_sysdir + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(TOLOWER "${env_windir}" windir) + string(TOLOWER "${env_sysdir}" sysroot) + + if(lower MATCHES "^(${sysroot}/sys(tem|wow)|${windir}/sys(tem|wow)|(.*/)*msvc[^/]+dll)") + set(is_system 1) + endif() + endif(CYGPATH_EXECUTABLE) + endif(UNIX) + endif(WIN32) if(NOT is_system) get_filename_component(original_path "${original_lower}" PATH) @@ -519,9 +539,9 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa if(APPLE) set(gp_tool "otool") endif(APPLE) - if(WIN32) + if(WIN32 AND NOT UNIX) # This is how to check for cygwin, har! set(gp_tool "dumpbin") - endif(WIN32) + endif(WIN32 AND NOT UNIX) endif("${gp_tool}" STREQUAL "") set(gp_tool_known 0) diff --git a/Tests/CMakeTests/GetPrerequisitesTest.cmake.in b/Tests/CMakeTests/GetPrerequisitesTest.cmake.in index 182c22332..daf467bcc 100644 --- a/Tests/CMakeTests/GetPrerequisitesTest.cmake.in +++ b/Tests/CMakeTests/GetPrerequisitesTest.cmake.in @@ -121,11 +121,11 @@ message(STATUS "") message(STATUS "=============================================================================") message(STATUS "Test overriding 'gp_tool' with value unlikely to be found") message(STATUS "") -if(WIN32 OR APPLE) - set(gp_tool "ldd") -else(WIN32 OR APPLE) +if(APPLE) + set(gp_tool "dumpbin") +else() set(gp_tool "otool") -endif(WIN32 OR APPLE) +endif() set(gp_cmd "gp_cmd-NOTFOUND") list_prerequisites("${CMAKE_COMMAND}" 0 0 0) set(gp_cmd)