File: BundleResources.cmake

package info (click to toggle)
peg-e 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,204 kB
  • sloc: cpp: 1,015; sh: 167; xml: 149; makefile: 5
file content (52 lines) | stat: -rw-r--r-- 1,531 bytes parent folder | download | duplicates (13)
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
# SPDX-FileCopyrightText: 2022 Graeme Gott <graeme@gottcode.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later

# Add files to a macOS bundle.
function(bundle_data target source destination)
	if(IS_DIRECTORY ${source})
		# Recursively find files under source
		file(GLOB_RECURSE files RELATIVE ${source} ${source}/*)
		set(parent ${source})
	else()
		# Handle single file
		get_filename_component(files ${source} NAME)
		get_filename_component(parent ${source} DIRECTORY)
	endif()

	# Set each file to be located under destination
	foreach(resource ${files})
		get_filename_component(path ${resource} DIRECTORY)
		set_property(
			SOURCE ${parent}/${resource}
			PROPERTY
			MACOSX_PACKAGE_LOCATION ${destination}/${path}
		)
	endforeach()

	# Make target depend on resources
	list(TRANSFORM files PREPEND "${parent}/")
	target_sources(${target} PRIVATE ${files})
endfunction()

# Add translations to a macOS bundle.
function(bundle_translations target translations)
	foreach(file ${translations})
		# Set each translation to be located under Resources
		set_property(
			SOURCE ${file}
			PROPERTY
			MACOSX_PACKAGE_LOCATION Resources/translations
		)

		# Inform macOS about translation for native dialogs
		get_filename_component(resource ${file} NAME)
		string(REGEX REPLACE "[^_]*_([^\\.]*)\\..*" "\\1.lproj" lang ${resource})
		add_custom_command(
			TARGET ${target}
			POST_BUILD
			COMMAND ${CMAKE_COMMAND}
			ARGS -E make_directory $<TARGET_BUNDLE_CONTENT_DIR:${target}>/Resources/${lang}
		)
	endforeach()
endfunction()