summaryrefslogtreecommitdiff
path: root/cmake/modules/AddResources.cmake
blob: 227e710864537172b3b47f631c6c6de03b096f23 (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
function(add_resources RESOURCES_TARGET)
	cmake_parse_arguments(
		PARSE_ARGV 1
		RESOURCES
		""
		"PREFIX"
		"FILES"
	)
	if(NOT DEFINED RESOURCES_PREFIX)
		set(RESOURCES_PREFIX ${CMAKE_BINARY_DIR})
	endif()
	foreach(RESOURCES_SOURCE IN ITEMS ${RESOURCES_FILES})
		add_custom_command(
			OUTPUT "${RESOURCES_PREFIX}/${RESOURCES_SOURCE}"
			DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCES_SOURCE}"
			COMMAND
				${CMAKE_COMMAND} -E copy
				"${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCES_SOURCE}"
				"${RESOURCES_PREFIX}/${RESOURCES_SOURCE}"
			COMMENT "Moving ${RESOURCES_SOURCE}"
		)
		cmake_path(GET RESOURCES_SOURCE PARENT_PATH PARENT)
		install(FILES ${RESOURCES_SOURCE} DESTINATION ${PARENT})
	endforeach()
	list(TRANSFORM RESOURCES_FILES PREPEND "${RESOURCES_PREFIX}/")
	add_custom_target(
		${RESOURCES_TARGET} ALL
		DEPENDS ${RESOURCES_FILES}
	)
endfunction()