summaryrefslogtreecommitdiff
path: root/Modules/Platform/WindowsPaths.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-01-15 14:04:19 -0500
committerBrad King <brad.king@kitware.com>2016-01-15 14:07:22 -0500
commit09b2f1c3f5819a5a3ec03069e7c2811172ac3591 (patch)
tree6be49fc940d521d2e0f3dc8a27be942ad7f5fa73 /Modules/Platform/WindowsPaths.cmake
parentb8d002af1aeefb435a9560b056f081e5d8dff734 (diff)
downloadcmake-09b2f1c3f5819a5a3ec03069e7c2811172ac3591.tar.gz
Windows: Find Program Files directories more robustly from environment
In Modules/Platform/WindowsPaths.cmake our previously recorded environment variable combinations no longer seem to be correct. For example, a 64-bit cmake binary may see ProgramW6432 in the environment and end up not considering the "ProgramFiles(x86)" variable. Instead check for all possible environment variables in the preferred order and then remove duplicates. Reported-by: Shawn Waldon <shawn.waldon@kitware.com>
Diffstat (limited to 'Modules/Platform/WindowsPaths.cmake')
-rw-r--r--Modules/Platform/WindowsPaths.cmake52
1 files changed, 19 insertions, 33 deletions
diff --git a/Modules/Platform/WindowsPaths.cmake b/Modules/Platform/WindowsPaths.cmake
index 658de3bf5e..eafa8fa1d8 100644
--- a/Modules/Platform/WindowsPaths.cmake
+++ b/Modules/Platform/WindowsPaths.cmake
@@ -28,46 +28,32 @@ set(__WINDOWS_PATHS_INCLUDED 1)
# Windows 64-bit Binary:
# ENV{ProgramFiles(x86)} = [C:\Program Files (x86)]
# ENV{ProgramFiles} = [C:\Program Files]
-# ENV{ProgramW6432} = <not set>
-# (executed from cygwin):
-# ENV{ProgramFiles(x86)} = <not set>
-# ENV{ProgramFiles} = [C:\Program Files]
-# ENV{ProgramW6432} = <not set>
+# ENV{ProgramW6432} = [C:\Program Files] or <not set>
#
-# Windows 32-bit Binary:
+# Windows 32-bit Binary on 64-bit Windows:
# ENV{ProgramFiles(x86)} = [C:\Program Files (x86)]
# ENV{ProgramFiles} = [C:\Program Files (x86)]
# ENV{ProgramW6432} = [C:\Program Files]
-# (executed from cygwin):
-# ENV{ProgramFiles(x86)} = <not set>
-# ENV{ProgramFiles} = [C:\Program Files (x86)]
-# ENV{ProgramW6432} = [C:\Program Files]
-if(DEFINED "ENV{ProgramW6432}")
- # 32-bit binary on 64-bit windows.
- # The 64-bit program files are in ProgramW6432.
- list(APPEND CMAKE_SYSTEM_PREFIX_PATH "$ENV{ProgramW6432}")
-
- # The 32-bit program files are in ProgramFiles.
- if(DEFINED "ENV{ProgramFiles}")
- list(APPEND CMAKE_SYSTEM_PREFIX_PATH "$ENV{ProgramFiles}")
+set(_programfiles "")
+foreach(v "ProgramW6432" "ProgramFiles" "ProgramFiles(x86)")
+ if(DEFINED "ENV{${v}}")
+ file(TO_CMAKE_PATH "$ENV{${v}}" _env_programfiles)
+ list(APPEND _programfiles "${_env_programfiles}")
+ unset(_env_programfiles)
endif()
-else()
- # 64-bit binary, or 32-bit binary on 32-bit windows.
- if(DEFINED "ENV{ProgramFiles}")
- list(APPEND CMAKE_SYSTEM_PREFIX_PATH "$ENV{ProgramFiles}")
- endif()
- set(programfilesx86 "ProgramFiles(x86)")
- if(DEFINED "ENV{${programfilesx86}}")
- # 64-bit binary. 32-bit program files are in ProgramFiles(x86).
- list(APPEND CMAKE_SYSTEM_PREFIX_PATH "$ENV{${programfilesx86}}")
- elseif(DEFINED "ENV{SystemDrive}")
- # Guess the 32-bit program files location.
- if(EXISTS "$ENV{SystemDrive}/Program Files (x86)")
- list(APPEND CMAKE_SYSTEM_PREFIX_PATH
- "$ENV{SystemDrive}/Program Files (x86)")
+endforeach()
+if(DEFINED "ENV{SystemDrive}")
+ foreach(d "Program Files" "Program Files (x86)")
+ if(EXISTS "$ENV{SystemDrive}/${d}")
+ list(APPEND _programfiles "$ENV{SystemDrive}/${d}")
endif()
- endif()
+ endforeach()
+endif()
+if(_programfiles)
+ list(REMOVE_DUPLICATES _programfiles)
+ list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${_programfiles})
endif()
+unset(_programfiles)
# Add the CMake install location.
get_filename_component(_CMAKE_INSTALL_DIR "${CMAKE_ROOT}" PATH)