File: EmscriptenCompressZip.cmake

package info (click to toggle)
warzone2100 4.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 660,320 kB
  • sloc: cpp: 676,209; ansic: 391,201; javascript: 78,238; python: 16,632; php: 4,294; sh: 4,094; makefile: 2,629; lisp: 1,492; cs: 489; xml: 404; perl: 224; ruby: 156; java: 89
file content (155 lines) | stat: -rw-r--r-- 5,745 bytes parent folder | download
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#
# Provides a function COMPRESS_ZIP that is compatible with the function in FindZIP.cmake, but just copies the files to a folder
#
#
# Copyright © 2018-2024 pastdue ( https://github.com/past-due/ ) and contributors
# License: MIT License ( https://opensource.org/licenses/MIT )
#
# Script Version: 2025-07-23a
#

cmake_minimum_required(VERSION 3.16...3.31)

set(_THIS_MODULE_BASE_DIR "${CMAKE_CURRENT_LIST_DIR}")

# COMPRESS_ZIP(OUTPUT outputFile
#			   [COMPRESSION_LEVEL <0 | 1 | 3 | 5 | 7 | 9>]
#			   PATHS [files...] [WORKING_DIRECTORY dir]
#			   [PATHS [files...] [WORKING_DIRECTORY dir]]
#			   [DEPENDS [depends...]]
#			   [BUILD_ALWAYS_TARGET [target name]]
#			   [IGNORE_GIT]
#			   [QUIET])
#
# Compress a list of files / folders into a ZIP file, named <outputFile>.
# Any directories specified will cause the directory's contents to be recursively included.
#
# If COMPRESSION_LEVEL is specified, the ZIP compression level setting will be passed
# through to the ZIP_EXECUTABLE. A compression level of "0" means no compression.
#
# If WORKING_DIRECTORY is specified, the WORKING_DIRECTORY will be set for the execution of
# the ZIP_EXECUTABLE.
#
# Each set of PATHS may also optionally specify an associated WORKING_DIRECTORY.
#
# DEPENDS may be used to specify additional dependencies, which are appended to the
# auto-generated list of dependencies used for the internal call to `add_custom_command`.
#
# If BUILD_ALWAYS_TARGET is specified, uses add_custom_target to create a target that is always built.
#
# QUIET attempts to suppress (most) output from the ZIP_EXECUTABLE that is used.
# (This option may have no effect, if unsupported by the ZIP_EXECUTABLE.)
#
function(COMPRESS_ZIP)

	set(_options ALL IGNORE_GIT QUIET)
	set(_oneValueArgs OUTPUT COMPRESSION_LEVEL BUILD_ALWAYS_TARGET) #WORKING_DIRECTORY)
	set(_multiValueArgs DEPENDS)

	CMAKE_PARSE_ARGUMENTS(_parsedArguments "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})

	# Check that OUTPUT was provided
	if(NOT _parsedArguments_OUTPUT)
		message( FATAL_ERROR "Missing required OUTPUT parameter" )
	endif()

	# Check arguments "unparsed" by CMAKE_PARSE_ARGUMENTS for PATHS sets
	set(_COMMAND_LIST)
	set(_depends_PATHS)
	set(_inPATHSet FALSE)
	set(_expecting_WORKINGDIR FALSE)
	unset(_currentPATHSet_PATHS)
	unset(_currentPATHSet_WORKINGDIR)
	foreach(currentArg ${_parsedArguments_UNPARSED_ARGUMENTS})
		if("${currentArg}" STREQUAL "PATHS")
			if(_expecting_WORKINGDIR)
				# Provided "WORKING_DIRECTORY" keyword, but no variable after it
				message( FATAL_ERROR "WORKING_DIRECTORY keyword provided, but missing variable afterwards" )
			endif()
			if(_inPATHSet AND DEFINED _currentPATHSet_PATHS)
				# Ending one non-empty PATH set, beginning another
				if(NOT DEFINED _currentPATHSet_WORKINGDIR)
					set(_currentPATHSet_WORKINGDIR "${CMAKE_CURRENT_SOURCE_DIR}")
				endif()
				foreach (_path ${_currentPATHSet_PATHS})
					list(APPEND _COMMAND_LIST
						COMMAND
						${CMAKE_COMMAND} -E chdir ${_currentPATHSet_WORKINGDIR}
						${CMAKE_COMMAND} -DSOURCE=${_path} -DDEST_DIR=${_parsedArguments_OUTPUT} -P ${_THIS_MODULE_BASE_DIR}/EmscriptenCompressZipCopy.cmake
					)
					set(_dependPath "${_currentPATHSet_WORKINGDIR}/${_path}")
#					list(APPEND _COMMAND_LIST
#						COMMAND
#						${CMAKE_COMMAND} -DSOURCE=${_dependPath} -DDEST_DIR=${_parsedArguments_OUTPUT} -P ${_THIS_MODULE_BASE_DIR}/EmscriptenCompressZipCopy.cmake
#					)
					list(APPEND _depends_PATHS "${_dependPath}")
				endforeach()
			endif()
			set(_inPATHSet TRUE)
			unset(_currentPATHSet_PATHS)
			unset(_currentPATHSet_WORKINGDIR)
		elseif("${currentArg}" STREQUAL "WORKING_DIRECTORY")
			if(NOT _inPATHSet)
				message( FATAL_ERROR "WORKING_DIRECTORY must be specified at end of PATHS set" )
			endif()
			if(_expecting_WORKINGDIR)
				message( FATAL_ERROR "Duplicate WORKING_DIRECTORY keyword" )
			endif()
			if(DEFINED _currentPATHSet_WORKINGDIR)
				message( FATAL_ERROR "PATHS set has more than one WORKING_DIRECTORY keyword" )
			endif()
			set(_expecting_WORKINGDIR TRUE)
		elseif(_expecting_WORKINGDIR)
			set(_currentPATHSet_WORKINGDIR "${currentArg}")
			set(_expecting_WORKINGDIR FALSE)
		elseif(_inPATHSet)
			# Treat argument as a PATH
			list(APPEND _currentPATHSet_PATHS "${currentArg}")
		else()
			# Unexpected argument
			message( FATAL_ERROR "Unexpected argument: ${currentArg}" )
		endif()
	endforeach()
	if(_expecting_WORKINGDIR)
		# Provided "WORKING_DIRECTORY" keyword, but no variable after it
		message( FATAL_ERROR "WORKING_DIRECTORY keyword provided, but missing variable afterwards" )
	endif()
	if(_inPATHSet AND DEFINED _currentPATHSet_PATHS)
		# Ending one non-empty PATH set
		if(NOT DEFINED _currentPATHSet_WORKINGDIR)
			set(_currentPATHSet_WORKINGDIR "${CMAKE_CURRENT_SOURCE_DIR}")
		endif()
		foreach (_path ${_currentPATHSet_PATHS})
			set(_dependPath "${_currentPATHSet_WORKINGDIR}/${_path}")
			list(APPEND _COMMAND_LIST
				COMMAND
				${CMAKE_COMMAND} -E chdir ${_currentPATHSet_WORKINGDIR}
				${CMAKE_COMMAND} -DSOURCE=${_path} -DDEST_DIR=${_parsedArguments_OUTPUT} -P ${_THIS_MODULE_BASE_DIR}/EmscriptenCompressZipCopy.cmake
			)
			list(APPEND _depends_PATHS "${_dependPath}")
		endforeach()
	endif()

	if(_parsedArguments_DEPENDS)
		list(APPEND _depends_PATHS ${_parsedArguments_DEPENDS})
	endif()

	if(NOT _parsedArguments_BUILD_ALWAYS_TARGET)
		add_custom_command(
			OUTPUT "${_parsedArguments_OUTPUT}"
			${_COMMAND_LIST}
			DEPENDS ${_depends_PATHS}
			WORKING_DIRECTORY "${_workingDirectory}"
			VERBATIM
		)
	else()
		add_custom_target(
			${_parsedArguments_BUILD_ALWAYS_TARGET} ALL
			${_COMMAND_LIST}
			DEPENDS ${_depends_PATHS}
			WORKING_DIRECTORY "${_workingDirectory}"
			VERBATIM
		)
	endif()

endfunction()