The open source OpenXR runtime
1# - Find bit-appropriate program files directories matching a given pattern
2#
3# Requires these CMake modules:
4# CleanDirectoryList
5# PrefixListGlob
6#
7# Original Author:
8# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
9# http://academic.cleardefinition.com
10# Iowa State University HCI Graduate Program/VRAC
11#
12# Copyright Iowa State University 2009-2010.
13# Distributed under the Boost Software License, Version 1.0.
14# (See accompanying file LICENSE_1_0.txt or copy at
15# http://www.boost.org/LICENSE_1_0.txt)
16# SPDX-License-Identifier: BSL-1.0
17
18include(PrefixListGlob)
19include(CleanDirectoryList)
20
21if(__program_files_glob)
22 return()
23endif()
24set(__program_files_glob YES)
25
26macro(_program_files_glob_var_prep)
27 # caution - ENV{ProgramFiles} on Win64 is adjusted to point to the arch
28 # of the running executable which, since CMake is 32-bit on Windows as
29 # I write this, will always be = $ENV{ProgramFiles(x86)}.
30 # Thus, we only use this environment variable if we are on a 32 machine
31
32 # 32-bit dir on win32, useless to us on win64
33 file(TO_CMAKE_PATH "$ENV{ProgramFiles}" _PROG_FILES)
34
35 # 32-bit dir: only set on win64
36 set(_PF86 "ProgramFiles(x86)")
37 file(TO_CMAKE_PATH "$ENV{${_PF86}}" _PROG_FILES_X86)
38
39 # 64-bit dir: only set on win64
40 file(TO_CMAKE_PATH "$ENV{ProgramW6432}" _PROG_FILES_W6432)
41endmacro()
42
43function(program_files_glob var pattern)
44 _program_files_glob_var_prep()
45 if(CMAKE_SIZEOF_VOID_P MATCHES "8")
46 # 64-bit build on win64
47 set(_PROGFILESDIRS "${_PROG_FILES_W6432}")
48 else()
49 if(_PROG_FILES_W6432)
50 # 32-bit build on win64
51 set(_PROGFILESDIRS "${_PROG_FILES_X86}")
52 else()
53 # 32-bit build on win32
54 set(_PROGFILESDIRS "${_PROG_FILES}")
55 endif()
56 endif()
57
58 prefix_list_glob(_prefixed "${pattern}" ${_PROGFILESDIRS})
59 clean_directory_list(_prefixed)
60 set(${var} ${_prefixed} PARENT_SCOPE)
61endfunction()
62
63function(program_files_fallback_glob var pattern)
64 _program_files_glob_var_prep()
65 if(CMAKE_SIZEOF_VOID_P MATCHES "8")
66 # 64-bit build on win64
67 # look in the "32 bit" (c:\program files (x86)\) directory as a
68 # fallback in case of weird/poorly written installers, like those
69 # that put both 64- and 32-bit libs in the same program files directory
70 set(_PROGFILESDIRS "${_PROG_FILES_W6432}" "${_PROG_FILES_X86}")
71 else()
72 if(_PROG_FILES_W6432)
73 # 32-bit build on win64
74 # look in the "64 bit" (c:\program files\) directory as a fallback
75 # in case of old/weird/poorly written installers
76 set(_PROGFILESDIRS "${_PROG_FILES_X86}" "${_PROG_FILES_W6432}")
77 else()
78 # 32-bit build on win32
79 set(_PROGFILESDIRS "${_PROG_FILES}")
80 endif()
81 endif()
82
83 prefix_list_glob(_prefixed "${pattern}" ${_PROGFILESDIRS})
84 clean_directory_list(_prefixed)
85 set(${var} ${_prefixed} PARENT_SCOPE)
86endfunction()