summaryrefslogtreecommitdiffstats
path: root/third-party/cmake/CopyResourcesToBuildTree.cmake
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--third-party/cmake/CopyResourcesToBuildTree.cmake83
1 files changed, 83 insertions, 0 deletions
diff --git a/third-party/cmake/CopyResourcesToBuildTree.cmake b/third-party/cmake/CopyResourcesToBuildTree.cmake
new file mode 100644
index 0000000..3512cc4
--- /dev/null
+++ b/third-party/cmake/CopyResourcesToBuildTree.cmake
@@ -0,0 +1,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()