1# - Returns a list of the parent directories of all files passed
2#
3#  get_directory_list(<listvar> <file path> [<additional file paths>...])
4#
5# Requires CMake 2.6 or newer (uses the 'function' command)
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
17if(__get_directory_list)
18	return()
19endif()
20set(__get_directory_list YES)
21
22function(get_directory_list _var)
23	# combine variable's current value with additional list items
24	set(_in ${ARGN})
25
26	if(_in)
27		# Initial list cleaning
28		list(REMOVE_DUPLICATES _in)
29
30		# Grab the absolute path of each actual directory
31		set(_out)
32		foreach(_file ${_in})
33			get_filename_component(_dir "${_file}" PATH)
34			if(IS_DIRECTORY "${_dir}")
35				get_filename_component(_dir "${_dir}" ABSOLUTE)
36				file(TO_CMAKE_PATH "${_dir}" _dir)
37				list(APPEND _out "${_dir}")
38			endif()
39		endforeach()
40
41		if(_out)
42			# Clean up the output list now
43			list(REMOVE_DUPLICATES _out)
44		endif()
45
46		# return _out
47		set(${_var} "${_out}" PARENT_SCOPE)
48	endif()
49endfunction()
50