File: LuaTargets.cmake

package info (click to toggle)
freespace2 24.0.2%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 43,188 kB
  • sloc: cpp: 583,107; ansic: 21,729; python: 1,174; sh: 464; makefile: 248; xml: 181
file content (108 lines) | stat: -rw-r--r-- 2,999 bytes parent folder | download | duplicates (7)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# - Copy/parse lua source files as a custom target
#
#  include(LuaTargets)
#  add_lua_target(<target_name> <directory to copy to> [<luafile> <luafile>])
#    Relative paths for the destination directory are considered with
#    with respect to CMAKE_CURRENT_BINARY_DIR
#
#  install_lua_target(<target_name> [arguments to INSTALL(PROGRAMS ...) ])
#
# Set this variable to specify location of luac, if it is not a target:
#  LUA_TARGET_LUAC_EXECUTABLE
#
# 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(__add_lua)
	return()
endif()
set(__add_lua YES)

include(FileCopyTargets)

function(add_lua_target _target _dest)

	if(NOT ARGN)
		message(WARNING
			"In add_lua_target call for target ${_target}, no source files were specified!")
		return()
	endif()

	if(NOT LUA_TARGET_LUAC_EXECUTABLE)
		if(TARGET luac)
			set(LUA_TARGET_LUAC_EXECUTABLE luac)
			mark_as_advanced(LUA_TARGET_LUAC_EXECUTABLE)
		else()
			find_program(LUA_TARGET_LUAC_EXECUTABLE NAMES luac)
		endif()
	endif()

	if(NOT LUA_TARGET_LUAC_EXECUTABLE)
		message(FATAL_ERROR
			"Can't find luac: please give LUA_TARGET_LUAC_EXECUTABLE a useful value - currently ${LUA_TARGET_LUAC_EXECUTABLE}")
	endif()
	mark_as_advanced(LUA_TARGET_LUAC_EXECUTABLE)

	set(ALLFILES)
	set(SOURCES)
	foreach(fn ${ARGN})
		# Produce an absolute path to the input file
		if(IS_ABSOLUTE "${fn}")
			get_filename_component(fullpath "${fn}" ABSOLUTE)
			get_filename_component(fn "${fn}" NAME)
		else()
			get_filename_component(fullpath
				"${CMAKE_CURRENT_SOURCE_DIR}/${fn}"
				ABSOLUTE)
		endif()

		# Clean up output file name
		get_filename_component(absout "${_dest}/${fn}" ABSOLUTE)

		add_custom_command(OUTPUT "${absout}"
			COMMAND
			${CMAKE_COMMAND}
			ARGS -E make_directory "${_dest}"
			COMMAND
			${CMAKE_COMMAND}
			ARGS -E copy "${fullpath}" "${_dest}"
			COMMAND
			"${LUA_TARGET_LUAC_EXECUTABLE}"
			ARGS -p "${fullpath}"
			MAIN_DEPENDENCY "${fullpath}"
			VERBATIM
			COMMENT "Copying ${fn} to ${absout} and parsing...")
		list(APPEND SOURCES "${fullpath}")
		list(APPEND ALLFILES "${absout}")
	endforeach()

	# Custom target depending on all the file copy commands
	add_custom_target(${_target}
		SOURCES ${SOURCES}
		DEPENDS ${ALLFILES})
	if(TARGET "${LUA_TARGET_LUAC_EXECUTABLE}")
		get_property(_luac_imported
			TARGET
			"${LUA_TARGET_LUAC_EXECUTABLE}"
			PROPERTY
			IMPORTED)
		if(NOT _luac_imported)
			add_dependencies(${_target} ${LUA_TARGET_LUAC_EXECUTABLE})
		endif()
	endif()

	set_property(TARGET ${_target} PROPERTY FILE_COPY_TARGET YES)
endfunction()

function(install_lua_target)
	install_file_copy_target(${ARGN})
endfunction()