File: CMakeLists.txt

package info (click to toggle)
chrome-gnome-shell 10.1-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,440 kB
  • sloc: python: 444; sh: 18; makefile: 11
file content (305 lines) | stat: -rw-r--r-- 12,788 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# GNOME Shell integration for Chrome build script

cmake_minimum_required (VERSION 2.8)
project (chrome-gnome-shell NONE)

# Suppress warning
if(NOT DEFINED CMAKE_SIZEOF_VOID_P)
	set(CMAKE_SIZEOF_VOID_P 8)
endif(NOT DEFINED CMAKE_SIZEOF_VOID_P)

# Variables
set(PROJECT_VERSION "10.1")

set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${PROJECT_VERSION})
set(ARCHIVE_FULL_NAME ${ARCHIVE_NAME}.tar.xz)
set(ARCHIVE_DEB_NAME ${CMAKE_PROJECT_NAME}_${PROJECT_VERSION}.orig.tar.xz)
set(DEB_DIR ${CMAKE_CURRENT_BINARY_DIR}/deb)

set(EXTENSION_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/extension)
set(EXTENSION_BUILD_DIR ${CMAKE_BINARY_DIR}/extension)
set(CHROME_BUILD_DIR ${EXTENSION_BUILD_DIR}/chrome)
set(OPERA_BUILD_DIR ${EXTENSION_BUILD_DIR}/opera)
set(FIREFOX_BUILD_DIR ${EXTENSION_BUILD_DIR}/firefox)

# Options
option(BUILD_EXTENSION		"Build extension zip package"	TRUE)
option(BUILD_CONNECTOR		"Build native messaging host"	TRUE)
option(BUILD_SOURCE_PACKAGE	"Build source package"		FALSE)
option(BUILD_DEB		"Build debian package"		FALSE)
option(BUILD_MESSAGES		"Update translation strings"	FALSE)
option(USE_DEBIAN_LAYOUT	"Use --install-layout=deb distutils parameter"	FALSE)

# Default extension key for Chrome web store
if(NOT DEFINED CHROME_EXTENSION_KEY)
	set(CHROME_EXTENSION_KEY "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlig8TAPPQZinMkJnptC0ldizx6fG9jSjZDJ9c8GuLcXeGRH+NMlQuPC9bR5IQlT7+4VY/1tm1+IZ4xvITx1wXCNTR+KXzZv3VNc2D+logehK7oIRTRj0fLhixrx4NLSNK7L7HgV2xcIoW6QV0jOdFcTPL0mWXodXSzZePrvXuflF7qpwNxLzYVi04Vh3xu2oR2Pc9SwfZ4SNbyCaunH/p8n5AYmDuogI2Ah++RZw0ctnqn7mmHrGXteBu/vkpcHZu3B3eW9PFSrv69rRs8duybYR9C91hJm6yzRqZqIpindIU3k2HnNWeCFWkRVpZPhaNVoxcBUO7wWUUwdIflW2JwIDAQAB")
endif(NOT DEFINED CHROME_EXTENSION_KEY)

# Default extension key for Opera addons
if(NOT DEFINED OPERA_EXTENSION_KEY)
	set(OPERA_EXTENSION_KEY "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1QBzvBFxSTBP1Z3u+B3GnxOhZiT/LLGJ9R3Mu3R5ap1YgvbHNqSj0CmrWE+MvJUYA+AxHSRP6ctKfPBZl/kdGYGLPgvagGBEEbutCerj9www7T2LAsFNc5gIgDXaU0P74Yik8MjLZIXOC3Q91Kien5Jbtit382HNVHl2nRbhgGZ9LZ+6UJnzSseW9NHw0/XRRnT0kv0Ih7lgC55xWfP7guam1uaT5DPxC7W5cy9V1z7mljBf50OxgnbEmf7Xvfz4QpQfDyQWE5hqKlBuPc8W/8bvYmWN+FDBqhls/FCml3icAElNMBg0YryFEDzu6xCTzgHqDKYu5SN49u+m6tyamQIDAQAB")
endif(NOT DEFINED OPERA_EXTENSION_KEY)

# Debian variables
if(NOT DEFINED DEBIAN_VERSION)
	set(DEBIAN_VERSION "0ubuntu1")
endif(NOT DEFINED DEBIAN_VERSION)

if(NOT DEFINED DEBIAN_DISTRO)
	set(DEBIAN_DISTRO "trusty")
endif(NOT DEFINED DEBIAN_DISTRO)

macro(find_program_ex)
	string(TOUPPER ${ARGV0} _PROGRAM_UPPER)

	set(_NAMES ${ARGV})
	math(EXPR _NAMES_LAST_INDEX "${ARGC}-1")
	list(GET _NAMES ${_NAMES_LAST_INDEX} _MESSAGE_STATUS)
	list(REMOVE_AT _NAMES ${_NAMES_LAST_INDEX})

	find_program(${_PROGRAM_UPPER}_EXECUTABLE NAMES ${_NAMES})

	if(${_PROGRAM_UPPER}_EXECUTABLE)
		message(STATUS "Found ${ARGV0}: ${${_PROGRAM_UPPER}_EXECUTABLE}")
		set(${_PROGRAM_UPPER}_FOUND TRUE)
	else(${_PROGRAM_UPPER}_EXECUTABLE)
		message(${_MESSAGE_STATUS} "Could NOT find ${ARGV0}.")
	endif(${_PROGRAM_UPPER}_EXECUTABLE)
endmacro(find_program_ex)

include(GNUInstallDirs)

# Options validating
if(NOT BUILD_EXTENSION AND NOT BUILD_CONNECTOR AND NOT BUILD_MESSAGES)
	message(FATAL_ERROR "No build options selected")
endif(NOT BUILD_EXTENSION AND NOT BUILD_CONNECTOR AND NOT BUILD_MESSAGES)

if(BUILD_DEB AND NOT BUILD_SOURCE_PACKAGE)
	message(STATUS "Building of debian package enabled. Turning on building source package.")
	set(BUILD_SOURCE_PACKAGE TRUE)
endif(BUILD_DEB AND NOT BUILD_SOURCE_PACKAGE)

if(BUILD_SOURCE_PACKAGE AND NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/)
	message(FATAL_ERROR "Unable to build source package outside of git repository.")
endif(BUILD_SOURCE_PACKAGE AND NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/)

if(BUILD_MESSAGES AND NOT DEFINED GETTEXT_REPORT_EMAIL)
	message(FATAL_ERROR "GETTEXT_REPORT_EMAIL must be specified to generate po template.")
endif(BUILD_MESSAGES AND NOT DEFINED GETTEXT_REPORT_EMAIL)

if(BUILD_EXTENSION OR BUILD_CONNECTOR)
	find_program_ex(base64 gbase64 FATAL_ERROR)
	find_program_ex(sha256sum gsha256sum FATAL_ERROR)
	find_program_ex(head ghead FATAL_ERROR)
	find_program_ex(tr gtr FATAL_ERROR)
	find_program_ex(jq FATAL_ERROR)

	# https://github.com/adobe/chromium/blob/master/chrome/common/extensions/extension.cc#L696
	# http://stackoverflow.com/questions/23873623/obtaining-chrome-extension-id-for-development
	execute_process(COMMAND echo "${CHROME_EXTENSION_KEY}"
			COMMAND ${BASE64_EXECUTABLE} -d
			COMMAND ${SHA256SUM_EXECUTABLE}
			COMMAND ${HEAD_EXECUTABLE} -c32
			COMMAND ${TR_EXECUTABLE} 0-9a-f a-p
			OUTPUT_VARIABLE CHROME_EXTENSION_ID)
	message(STATUS "Calculated Chrome extension id: ${CHROME_EXTENSION_ID}")

	execute_process(COMMAND echo "${OPERA_EXTENSION_KEY}"
			COMMAND ${BASE64_EXECUTABLE} -d
			COMMAND ${SHA256SUM_EXECUTABLE}
			COMMAND ${HEAD_EXECUTABLE} -c32
			COMMAND ${TR_EXECUTABLE} 0-9a-f a-p
			OUTPUT_VARIABLE OPERA_EXTENSION_ID)
	message(STATUS "Calculated Opera extension id: ${OPERA_EXTENSION_ID}")
endif(BUILD_EXTENSION OR BUILD_CONNECTOR)

# Options handling
if(BUILD_EXTENSION)
	find_program_ex(7z FATAL_ERROR)

	file(COPY "${EXTENSION_SOURCES}/" DESTINATION "${CHROME_BUILD_DIR}"
		PATTERN "manifest*.json" EXCLUDE)

	file(COPY "${EXTENSION_SOURCES}/" DESTINATION "${OPERA_BUILD_DIR}"
		PATTERN "manifest*.json" EXCLUDE)

	file(COPY "${EXTENSION_SOURCES}/" DESTINATION "${FIREFOX_BUILD_DIR}"
		PATTERN "manifest*.json" EXCLUDE)

	set(PUBLIC_KEY ${CHROME_EXTENSION_KEY})
	configure_file("${EXTENSION_SOURCES}/manifest.json" "${CHROME_BUILD_DIR}/")

	set(PUBLIC_KEY ${OPERA_EXTENSION_KEY})
	configure_file("${EXTENSION_SOURCES}/manifest.json" "${OPERA_BUILD_DIR}/")

	unset(PUBLIC_KEY)

	add_custom_target(chrome-extension ALL
		COMMAND "${7Z_EXECUTABLE}" a -tzip "${CMAKE_BINARY_DIR}/extension-chrome.zip" ./
		WORKING_DIRECTORY "${CHROME_BUILD_DIR}")
	add_custom_target(opera-extension ALL
		COMMAND "${7Z_EXECUTABLE}" a -tzip "${CMAKE_BINARY_DIR}/extension-opera.zip" ./
		WORKING_DIRECTORY "${OPERA_BUILD_DIR}")
	add_custom_target(firefox-extension ALL
		COMMAND "${JQ_EXECUTABLE}" -s "'add|del(.key)'"
				'${EXTENSION_SOURCES}/manifest.json' '${EXTENSION_SOURCES}/manifest.firefox.json'
				> "${FIREFOX_BUILD_DIR}/manifest.json"
		COMMAND "${7Z_EXECUTABLE}" a -tzip "${CMAKE_BINARY_DIR}/extension-firefox.zip" ./
		WORKING_DIRECTORY "${FIREFOX_BUILD_DIR}")
endif(BUILD_EXTENSION)

if(BUILD_CONNECTOR)
	find_package(PythonInterp REQUIRED)

	set(CONNECTOR_SETUP "${CMAKE_CURRENT_SOURCE_DIR}/connector/setup.py")
	add_custom_target(build-connector ALL
                       COMMAND ${PYTHON_EXECUTABLE} ${CONNECTOR_SETUP} build)

	configure_file("${CMAKE_CURRENT_SOURCE_DIR}/connector/org.gnome.chrome_gnome_shell.json"
			"${CMAKE_BINARY_DIR}/")
	configure_file("${CMAKE_CURRENT_SOURCE_DIR}/connector/org.gnome.ChromeGnomeShell.service.in"
			"${CMAKE_BINARY_DIR}/org.gnome.ChromeGnomeShell.service")

	add_custom_target(firefox-native-manifest ALL
			COMMAND "${JQ_EXECUTABLE}" -s "'add|del(.allowed_origins)'"
				"${CMAKE_BINARY_DIR}/org.gnome.chrome_gnome_shell.json"
				"${CMAKE_CURRENT_SOURCE_DIR}/connector/org.gnome.chrome_gnome_shell.firefox.json"
				> "${CMAKE_BINARY_DIR}/org.gnome.chrome_gnome_shell.firefox.json")

	if(USE_DEBIAN_LAYOUT)
		set(DISTUTILS_EXTRA_ARGS "--install-layout=deb")
	else()
		set(DISTUTILS_EXTRA_ARGS "")
	endif(USE_DEBIAN_LAYOUT)

	install(CODE "
		if(DEFINED ENV{DESTDIR})
			set(DESTDIR \"\$ENV{DESTDIR}\")
		else(DEFINED ENV{DESTDIR})
			set(DESTDIR \"/\")
		endif(DEFINED ENV{DESTDIR})

		execute_process(COMMAND ${PYTHON_EXECUTABLE} ${CONNECTOR_SETUP}
					install ${DISTUTILS_EXTRA_ARGS}
						--root \"\${DESTDIR}\"
						--prefix \"${CMAKE_INSTALL_PREFIX}\")")

	if(NOT CMAKE_SYSTEM_NAME MATCHES "DragonFly.*|FreeBSD")
		install(FILES "${CMAKE_BINARY_DIR}/org.gnome.chrome_gnome_shell.json" DESTINATION "/etc/chromium/native-messaging-hosts/")
		install(FILES "${CMAKE_BINARY_DIR}/org.gnome.chrome_gnome_shell.json" DESTINATION "/etc/opt/chrome/native-messaging-hosts/")
	else(NOT CMAKE_SYSTEM_NAME MATCHES "DragonFly.*|FreeBSD")
		# FreeBSD uses patch that forces Chromium to look into undocumented
		# "/usr/local/etc/chrome/native-messaging-hosts" folder for native messaging host manifest.
		# https://github.com/freebsd/freebsd-ports/blob/master/www/chromium/files/patch-chrome_common_chrome__paths.cc
		install(FILES "${CMAKE_BINARY_DIR}/org.gnome.chrome_gnome_shell.json" DESTINATION "/usr/local/etc/chrome/native-messaging-hosts/")
	endif(NOT CMAKE_SYSTEM_NAME MATCHES "DragonFly.*|FreeBSD")

	install(FILES "${CMAKE_BINARY_DIR}/org.gnome.chrome_gnome_shell.firefox.json"
			DESTINATION "${CMAKE_INSTALL_LIBDIR}/mozilla/native-messaging-hosts/"
			RENAME "org.gnome.chrome_gnome_shell.json")

	install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/connector/org.gnome.ChromeGnomeShell.desktop" DESTINATION "${CMAKE_INSTALL_DATADIR}/applications/")
	install(FILES "${CMAKE_BINARY_DIR}/org.gnome.ChromeGnomeShell.service" DESTINATION "${CMAKE_INSTALL_DATADIR}/dbus-1/services/")

	install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/extension/icons/GnomeLogo-16.png"
		DESTINATION "${CMAKE_INSTALL_DATADIR}/icons/gnome/16x16/apps/"
		RENAME org.gnome.ChromeGnomeShell.png)
	install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/extension/icons/GnomeLogo-48.png"
		DESTINATION "${CMAKE_INSTALL_DATADIR}/icons/gnome/48x48/apps/"
		RENAME org.gnome.ChromeGnomeShell.png)
	install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/extension/icons/GnomeLogo-128.png"
		DESTINATION "${CMAKE_INSTALL_DATADIR}/icons/gnome/128x128/apps/"
		RENAME org.gnome.ChromeGnomeShell.png)
endif(BUILD_CONNECTOR)

if(BUILD_SOURCE_PACKAGE)
	set(MESSAGE_NO_DIST "Unable to generate dist target. Dependencies missing.")

	find_program_ex(xz WARNING)
	find_package(Git)

	if(GIT_FOUND AND XZ_FOUND)
		# http://agateau.com/2009/cmake-and-make-dist-the-simple-version/
		add_custom_target(dist
			COMMAND ${GIT_EXECUTABLE} archive --prefix=${ARCHIVE_NAME}/ HEAD | ${XZ_EXECUTABLE} -z > ${CMAKE_BINARY_DIR}/${ARCHIVE_FULL_NAME}
			WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
	else(GIT_FOUND AND XZ_FOUND)
		if(BUILD_DEB)
			message(FATAL_ERROR ${MESSAGE_NO_DIST})
		else(BUILD_DEB)
			message(WARNING ${MESSAGE_NO_DIST})
		endif(BUILD_DEB)
	endif(GIT_FOUND AND XZ_FOUND)

	if(BUILD_DEB)
		find_program_ex(debuild FATAL_ERROR)
		find_program_ex(tar FATAL_ERROR)

		if(GPG_KEY)
			message(STATUS "Using GPG key ${GPG_KEY}")
			set(DEBUILD_KEY "-k${GPG_KEY}")
		else(GPG_KEY)
			message(STATUS "GPG_KEY not set. Using default GPG key")
		endif(GPG_KEY)

		configure_file("${CMAKE_CURRENT_SOURCE_DIR}/contrib/ubuntu/changelog"
				"${CMAKE_BINARY_DIR}/debian_changelog")

		add_custom_target(deb_prepare
			DEPENDS dist
			COMMAND ${CMAKE_COMMAND} -E make_directory "${DEB_DIR}/${ARCHIVE_NAME}"
			COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/${ARCHIVE_FULL_NAME}" "${DEB_DIR}/${ARCHIVE_DEB_NAME}"
			COMMAND ${TAR_EXECUTABLE} -xvf "${DEB_DIR}/${ARCHIVE_DEB_NAME}" -C "${DEB_DIR}/${ARCHIVE_NAME}" --strip-components=1)

		add_custom_target(deb ALL
			DEPENDS deb_prepare
			COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/contrib/ubuntu" "${DEB_DIR}/${ARCHIVE_NAME}/debian"
			COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/debian_changelog" "${DEB_DIR}/${ARCHIVE_NAME}/debian/changelog"
			COMMAND ${DEBUILD_EXECUTABLE} -S ${DEBUILD_KEY}
			WORKING_DIRECTORY ${DEB_DIR}/${ARCHIVE_NAME})
	endif(BUILD_DEB)
endif(BUILD_SOURCE_PACKAGE)

if(BUILD_MESSAGES)
	find_package(Gettext)
	if(NOT GETTEXT_FOUND)
		message(FATAL_ERROR "Gettext not found")
	endif(NOT GETTEXT_FOUND)

	add_custom_target(generate-pot
		COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/contrib/chrome-messages2po.py
			--email ${GETTEXT_REPORT_EMAIL}
			--reference-lang en
			--write-pot
			${CMAKE_CURRENT_SOURCE_DIR}/contrib/chrome-web-store/
			${CMAKE_CURRENT_SOURCE_DIR}/extension/_locales/
			${CMAKE_CURRENT_SOURCE_DIR}/po/)

	add_custom_target(update-po
		DEPENDS generate-pot)

	file(GLOB PO_FILES
		LIST_DIRECTORIES false
		RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/po/
		${CMAKE_CURRENT_SOURCE_DIR}/po/*.po)

	foreach(PO ${PO_FILES})
		add_custom_command(TARGET update-po
			COMMENT "Updating ${PO}"
			WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/po
			COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} -q --update
				${PO}
				${CMAKE_CURRENT_SOURCE_DIR}/po/template.pot)
	endforeach()

	add_custom_command(TARGET update-po
		COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_SOURCE_DIR}/po/*.po~)

	add_custom_target(build-messages ALL
		DEPENDS update-po
		COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/contrib/po2chrome-messages.py
			--reference-lang en
			${CMAKE_CURRENT_SOURCE_DIR}/contrib/chrome-web-store/
			${CMAKE_CURRENT_SOURCE_DIR}/extension/_locales/
			${CMAKE_CURRENT_SOURCE_DIR}/po/)
endif(BUILD_MESSAGES)