···11+# - Removes duplicate entries and non-directories from a provided list
22+#
33+# clean_directory_list(<listvar> [<additional list items>...])
44+#
55+# Requires CMake 2.6 or newer (uses the 'function' command)
66+#
77+# Original Author:
88+# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
99+# http://academic.cleardefinition.com
1010+# Iowa State University HCI Graduate Program/VRAC
1111+#
1212+# Copyright Iowa State University 2009-2010.
1313+# Distributed under the Boost Software License, Version 1.0.
1414+# (See accompanying file LICENSE_1_0.txt or copy at
1515+# http://www.boost.org/LICENSE_1_0.txt)
1616+1717+if(__clean_directory_list)
1818+ return()
1919+endif()
2020+set(__clean_directory_list YES)
2121+2222+function(clean_directory_list _var)
2323+ # combine variable's current value with additional list items
2424+ set(_in ${${_var}} ${ARGN})
2525+2626+ if(_in)
2727+ # Initial list cleaning
2828+ list(REMOVE_DUPLICATES _in)
2929+3030+ # Grab the absolute path of each actual directory
3131+ set(_out)
3232+ foreach(_dir ${_in})
3333+ if(IS_DIRECTORY "${_dir}")
3434+ get_filename_component(_dir "${_dir}" ABSOLUTE)
3535+ file(TO_CMAKE_PATH "${_dir}" _dir)
3636+ list(APPEND _out "${_dir}")
3737+ endif()
3838+ endforeach()
3939+4040+ if(_out)
4141+ # Clean up the output list now
4242+ list(REMOVE_DUPLICATES _out)
4343+ endif()
4444+4545+ # return _out
4646+ set(${_var} "${_out}" PARENT_SCOPE)
4747+ endif()
4848+endfunction()
+36
cmake/PrefixListGlob.cmake
···11+# - For each given prefix in a list, glob using the prefix+pattern
22+#
33+#
44+# Original Author:
55+# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
66+# http://academic.cleardefinition.com
77+# Iowa State University HCI Graduate Program/VRAC
88+#
99+# Copyright Iowa State University 2009-2010.
1010+# Distributed under the Boost Software License, Version 1.0.
1111+# (See accompanying file LICENSE_1_0.txt or copy at
1212+# http://www.boost.org/LICENSE_1_0.txt)
1313+1414+if(__prefix_list_glob)
1515+ return()
1616+endif()
1717+set(__prefix_list_glob YES)
1818+1919+function(prefix_list_glob var pattern)
2020+ set(_out)
2121+ set(_result)
2222+ foreach(prefix ${ARGN})
2323+ file(GLOB _globbed ${prefix}${pattern})
2424+ if(_globbed)
2525+ list(SORT _globbed)
2626+ list(REVERSE _globbed)
2727+ list(APPEND _out ${_globbed})
2828+ endif()
2929+ endforeach()
3030+ foreach(_name ${_out})
3131+ get_filename_component(_name "${_name}" ABSOLUTE)
3232+ list(APPEND _result "${_name}")
3333+ endforeach()
3434+3535+ set(${var} "${_result}" PARENT_SCOPE)
3636+endfunction()
+85
cmake/ProgramFilesGlob.cmake
···11+# - Find bit-appropriate program files directories matching a given pattern
22+#
33+# Requires these CMake modules:
44+# CleanDirectoryList
55+# PrefixListGlob
66+#
77+# Original Author:
88+# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
99+# http://academic.cleardefinition.com
1010+# Iowa State University HCI Graduate Program/VRAC
1111+#
1212+# Copyright Iowa State University 2009-2010.
1313+# Distributed under the Boost Software License, Version 1.0.
1414+# (See accompanying file LICENSE_1_0.txt or copy at
1515+# http://www.boost.org/LICENSE_1_0.txt)
1616+1717+include(PrefixListGlob)
1818+include(CleanDirectoryList)
1919+2020+if(__program_files_glob)
2121+ return()
2222+endif()
2323+set(__program_files_glob YES)
2424+2525+macro(_program_files_glob_var_prep)
2626+ # caution - ENV{ProgramFiles} on Win64 is adjusted to point to the arch
2727+ # of the running executable which, since CMake is 32-bit on Windows as
2828+ # I write this, will always be = $ENV{ProgramFiles(x86)}.
2929+ # Thus, we only use this environment variable if we are on a 32 machine
3030+3131+ # 32-bit dir on win32, useless to us on win64
3232+ file(TO_CMAKE_PATH "$ENV{ProgramFiles}" _PROG_FILES)
3333+3434+ # 32-bit dir: only set on win64
3535+ set(_PF86 "ProgramFiles(x86)")
3636+ file(TO_CMAKE_PATH "$ENV{${_PF86}}" _PROG_FILES_X86)
3737+3838+ # 64-bit dir: only set on win64
3939+ file(TO_CMAKE_PATH "$ENV{ProgramW6432}" _PROG_FILES_W6432)
4040+endmacro()
4141+4242+function(program_files_glob var pattern)
4343+ _program_files_glob_var_prep()
4444+ if(CMAKE_SIZEOF_VOID_P MATCHES "8")
4545+ # 64-bit build on win64
4646+ set(_PROGFILESDIRS "${_PROG_FILES_W6432}")
4747+ else()
4848+ if(_PROG_FILES_W6432)
4949+ # 32-bit build on win64
5050+ set(_PROGFILESDIRS "${_PROG_FILES_X86}")
5151+ else()
5252+ # 32-bit build on win32
5353+ set(_PROGFILESDIRS "${_PROG_FILES}")
5454+ endif()
5555+ endif()
5656+5757+ prefix_list_glob(_prefixed "${pattern}" ${_PROGFILESDIRS})
5858+ clean_directory_list(_prefixed)
5959+ set(${var} ${_prefixed} PARENT_SCOPE)
6060+endfunction()
6161+6262+function(program_files_fallback_glob var pattern)
6363+ _program_files_glob_var_prep()
6464+ if(CMAKE_SIZEOF_VOID_P MATCHES "8")
6565+ # 64-bit build on win64
6666+ # look in the "32 bit" (c:\program files (x86)\) directory as a
6767+ # fallback in case of weird/poorly written installers, like those
6868+ # that put both 64- and 32-bit libs in the same program files directory
6969+ set(_PROGFILESDIRS "${_PROG_FILES_W6432}" "${_PROG_FILES_X86}")
7070+ else()
7171+ if(_PROG_FILES_W6432)
7272+ # 32-bit build on win64
7373+ # look in the "64 bit" (c:\program files\) directory as a fallback
7474+ # in case of old/weird/poorly written installers
7575+ set(_PROGFILESDIRS "${_PROG_FILES_X86}" "${_PROG_FILES_W6432}")
7676+ else()
7777+ # 32-bit build on win32
7878+ set(_PROGFILESDIRS "${_PROG_FILES}")
7979+ endif()
8080+ endif()
8181+8282+ prefix_list_glob(_prefixed "${pattern}" ${_PROGFILESDIRS})
8383+ clean_directory_list(_prefixed)
8484+ set(${var} ${_prefixed} PARENT_SCOPE)
8585+endfunction()