summaryrefslogtreecommitdiffstats
path: root/third-party/cmake/CopyResourcesToBuildTree.cmake
blob: 3512cc48445b0a2f3ab1c9422edd1fbd3ffff3d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# - Copy the resources your app needs to the build tree.
#
#  copy_resources_to_build_tree(<target_name>)
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

if(__copy_resources_to_build_tree)
	return()
endif()
set(__copy_resources_to_build_tree YES)

function(copy_resources_to_build_tree _target)
	get_target_property(_resources ${_target} RESOURCE)
	if(NOT _resources)
		# Bail if no resources
		message(STATUS
			"Told to copy resources for target ${_target}, but "
			"no resources are set!")
		return()
	endif()

	get_target_property(_path ${_target} LOCATION)
	get_filename_component(_path "${_path}" PATH)

	if(NOT MSVC AND NOT "${CMAKE_GENERATOR}" MATCHES "Makefiles")
		foreach(_config ${CMAKE_CONFIGURATION_TYPES})
			get_target_property(_path${_config} ${_target} LOCATION_${_config})
			get_filename_component(_path${_config} "${_path${_config}}" PATH)
			add_custom_command(TARGET ${_target}
						POST_BUILD
						COMMAND
						${CMAKE_COMMAND}
						ARGS -E make_directory "${_path${_config}}/"
						COMMENT "Creating directory ${_path${_config}}/")
		endforeach()
	endif()

	foreach(_res ${_resources})
		if(NOT IS_ABSOLUTE "${_res}")
			get_filename_component(_res "${_res}" ABSOLUTE)
		endif()
		get_filename_component(_name "${_res}" NAME)

		if(MSVC)
			# Working dir is solution file dir, not exe file dir.
			add_custom_command(TARGET ${_target}
				POST_BUILD
				COMMAND
				${CMAKE_COMMAND}
				ARGS -E copy "${_res}" "${CMAKE_BINARY_DIR}/"
				COMMENT "Copying ${_name} to ${CMAKE_BINARY_DIR}/ for MSVC")
		else()
			if("${CMAKE_GENERATOR}" MATCHES "Makefiles")
				add_custom_command(TARGET ${_target}
					POST_BUILD
					COMMAND
					${CMAKE_COMMAND}
					ARGS -E copy "${_res}" "${_path}/"
					COMMENT "Copying ${_name} to ${_path}/")
			else()
				foreach(_config ${CMAKE_CONFIGURATION_TYPES})
					add_custom_command(TARGET ${_target}
						POST_BUILD
						COMMAND
						${CMAKE_COMMAND}
						ARGS -E copy "${_res}" "${_path${_config}}"
						COMMENT "Copying ${_name} to ${_path${_config}}")
				endforeach()

			endif()
		endif()
	endforeach()
endfunction()