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")