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