File: CMakeLists.txt

package info (click to toggle)
openorienteering-mapper 0.9.5-3.1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 61,788 kB
  • sloc: cpp: 112,248; ansic: 1,448; sh: 408; java: 240; xml: 97; sed: 64; makefile: 28
file content (286 lines) | stat: -rw-r--r-- 9,237 bytes parent folder | download | duplicates (2)
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
#
#    Copyright 2012, 2013, 2014 Thomas Schöps
#    Copyright 2012-2019 Kai Pastor
#    
#    This file is part of OpenOrienteering.
# 
#    OpenOrienteering is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
# 
#    OpenOrienteering is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
# 
#    You should have received a copy of the GNU General Public License
#    along with OpenOrienteering.  If not, see <http://www.gnu.org/licenses/>.


message(STATUS "Configuring ${PROJECT_NAME} user manual")


set(Mapper_MANUAL_QTHELP_default ON)
if(ANDROID)
	set(Mapper_MANUAL_QTHELP_default OFF)
endif()
option(Mapper_MANUAL_QTHELP
  "Provide the manual as Qt Help collection"
  ${Mapper_MANUAL_QTHELP_default}
)


set(Mapper_MANUAL_PDF_default OFF)
option(Mapper_MANUAL_PDF
  "Provide the manual as PDF file"
  ${Mapper_MANUAL_PDF_default}
)



#
# General target
#
add_custom_target(Mapper-manual ALL)



#
# Creating doxygen input for HTML generation
#

file(GLOB pages "${CMAKE_CURRENT_SOURCE_DIR}/pages/*.md")
configure_file(preprocess-markdown-html.cmake.in preprocess-markdown-html.cmake @ONLY)
add_custom_command(
  OUTPUT    "preprocess-markdown-html.stamp"
  COMMAND   "${CMAKE_COMMAND}" -P preprocess-markdown-html.cmake
  DEPENDS   "preprocess-markdown-html.cmake"
            ${pages}
  COMMENT   "Preprocessing Markdown for HTML output"
)
add_custom_target(Mapper-manual-markdown-html
  DEPENDS   "preprocess-markdown-html.stamp"
  SOURCES   "preprocess-markdown-html.cmake.in"
)



#
# Doxygen HTML generation; creating input for optional Qt Help generation
#

find_program(DOXYGEN_EXECUTABLE
  NAMES doxygen
  DOC "The path of the doxygen executable"
)
if(NOT DOXYGEN_EXECUTABLE)
	message(FATAL_ERROR "doxygen executable not found.")
endif()

set(Mapper_COMPRESSED_HELP "Mapper ${Mapper_VERSION_FILESYSTEM} Manual.qch")
set(Mapper_HELP_COLLECTION "Mapper ${Mapper_VERSION_FILESYSTEM} Manual.qhc")
set(Mapper_HELP_NAMESPACE "openorienteering.mapper-${Mapper_VERSION}.help"
  CACHE INTERNAL "The namespace where the current version's help will be located."
)
if(NOT MANUAL_SECTIONS)
	if(ANDROID)
		set(MANUAL_SECTIONS_DEFAULT ANDROID)
	elseif(APPLE)
		set(MANUAL_SECTIONS_DEFAULT MACOS)
	elseif(UNIX)
		set(MANUAL_SECTIONS_DEFAULT LINUX)
	elseif(WIN32)
		set(MANUAL_SECTIONS_DEFAULT WINDOWS)
	else()
		set(MANUAL_SECTIONS_DEFAULT OTHER)
	endif()
	set(MANUAL_SECTIONS "${MANUAL_SECTIONS_DEFAULT}" CACHE STRING
	  "Conditional manual sections to be enabled")
endif()
message(STATUS "Conditional manual sections: ${MANUAL_SECTIONS}")

set(DOXYFILE_HTML_EXTRA )
if(ANDROID)
	set(DOXYFILE_HTML_EXTRA "
FILE_PATTERNS          = android* toolbar* touch-mode*
USE_MDFILE_AS_MAINPAGE = android-app.md
")
endif()

configure_file(Doxyfile-html.in Doxyfile-html @ONLY)
configure_file(postprocess-qhp.cmake.in postprocess-qhp.cmake @ONLY)
add_custom_command(
  OUTPUT    "html/index.qhp"
  COMMAND   "${CMAKE_COMMAND}" -E remove_directory html
  COMMAND   "${DOXYGEN_EXECUTABLE}" Doxyfile-html
  COMMAND   "${CMAKE_COMMAND}" -P postprocess-qhp.cmake
  DEPENDS   preprocess-markdown-html.stamp
            "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile-html"
            "${CMAKE_CURRENT_BINARY_DIR}/postprocess-qhp.cmake"
            "${DOXYGEN_EXECUTABLE}"
            header.html
            footer.html
            style.css
  COMMENT   "Running doxygen for HTML output"
)
add_custom_target(Mapper-manual-HTML
  DEPENDS   "html/index.qhp"
  # Sources to be listed in Qt Creator
  SOURCES   Doxyfile-html.in
            header.html
            footer.html
            install-html.cmake.in
            postprocess-qhp.cmake.in
            style.css
)
add_dependencies(Mapper-manual-HTML Mapper-manual-markdown-html)



if(Mapper_MANUAL_QTHELP)
	#
	# Qt Help generation
	#
	
	find_package(Qt5Core REQUIRED)
	if (Qt5Core_VERSION VERSION_LESS 5.12)
		set(qcollectiongenerator_name qcollectiongenerator)
	else()
		set(qcollectiongenerator_name qhelpgenerator)
	endif()
	
	# Qt provides a broken Qt5::qcollectiongenerator when crosscompiling.
	if (CMAKE_CROSSCOMPILING AND NOT TARGET Qt5::qcollectiongenerator)
		find_program(Qt5Help_QCOLLECTIONGENERATOR_EXECUTABLE
		  NAMES ${qcollectiongenerator_name}-qt5 ${qcollectiongenerator_name}
		  DOC "The path of the Qt Help collection generator executable"
		)
		add_executable(Qt5::${qcollectiongenerator_name} IMPORTED)
		set_target_properties(Qt5::${qcollectiongenerator_name} PROPERTIES
		  IMPORTED_LOCATION ${Qt5Help_QCOLLECTIONGENERATOR_EXECUTABLE}
		)
	elseif(NOT Qt5Help_QCOLLECTIONGENERATOR_EXECUTABLE)
		find_package(Qt5Help REQUIRED)
		set(Qt5Help_QCOLLECTIONGENERATOR_EXECUTABLE Qt5::${qcollectiongenerator_name})
	endif()
	
	# Reproducible builds need a modification to the help collection file.
	set(source_date_commands )
	find_program(SQLITE3_EXECUTABLE NAMES sqlite3
	  DOC "The path of the sqlite3 executable"
	)
	if (DEFINED ENV{SOURCE_DATE_EPOCH} AND SQLITE3_EXECUTABLE)
		if(Qt5Core_VERSION VERSION_LESS 5.12.0)
			file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/timestamp.sql"
			  "UPDATE 'SettingsTable' SET Value='$ENV{SOURCE_DATE_EPOCH}' where Key='CreationTime';\n"
			  "DELETE FROM 'SettingsTable' WHERE Key='LastRegisterTime';\n"
			)
		else()
			file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/timestamp.sql"
			  "UPDATE TimeStampTable SET TimeStamp=strftime('%Y-%m-%dT%H:%M:%S',datetime($ENV{SOURCE_DATE_EPOCH},'unixepoch'));\n"
			)
		endif()
		set(source_date_commands
	      COMMAND ${SQLITE3_EXECUTABLE} "${Mapper_HELP_COLLECTION}" < "timestamp.sql"
		)
	elseif(DEFINED ENV{SOURCE_DATE_EPOCH})
		message(FATAL_ERROR
		  "By setting SOURCE_DATE_EPOCH, a reproducible build was requested. "
		  "sqlite3 is needed for reproducible builds but cannot be found."
		)
	endif()
	
	configure_file(Manual.qhcp.in Manual.qhcp @ONLY)
	add_custom_command( 
	  OUTPUT    "${Mapper_HELP_COLLECTION}"
	            "${Mapper_COMPRESSED_HELP}"
	  COMMAND   "${Qt5Help_QCOLLECTIONGENERATOR_EXECUTABLE}" Manual.qhcp
	            -o "${Mapper_HELP_COLLECTION}"
	  ${source_date_commands}
	  MAIN_DEPENDENCY "html/index.qhp"
	  DEPENDS   "${CMAKE_CURRENT_BINARY_DIR}/Manual.qhcp"
	  WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
	  COMMENT   "Running qcollectiongenerator for Qt Help output"
	)
	add_custom_target(Mapper-manual-Qt-Help
	  DEPENDS   "${Mapper_HELP_COLLECTION}"
	  SOURCES   Manual.qhcp.in
	)
	add_dependencies(Mapper-manual-Qt-Help  Mapper-manual-HTML)
	add_dependencies(Mapper-manual  Mapper-manual-Qt-Help)
	
	install(
	  FILES "${CMAKE_CURRENT_BINARY_DIR}/${Mapper_HELP_COLLECTION}" 
	        "${CMAKE_CURRENT_BINARY_DIR}/${Mapper_COMPRESSED_HELP}" 
	  DESTINATION "${MAPPER_ABOUT_DESTINATION}"
	)
else()
	#
	# Direct installation of manual HTML files
	#
	
	add_dependencies(Mapper-manual Mapper-manual-HTML)
	
	configure_file(install-html.cmake.in install-html.cmake @ONLY)
	install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/install-html.cmake")
endif()


if(Mapper_MANUAL_PDF)
	#
	# PDF file generation
	#
	
	find_program(PDFLATEX_EXECUTABLE
	  NAMES pdflatex
	  DOC "The path of the pdflatex executable"
	)
	if(PDFLATEX_EXECUTABLE)
		find_program(MAKE_EXECUTABLE
		  NAMES make
		  DOC "The path of the make executable"
		)
		if(NOT MAKE_EXECUTABLE AND CMAKE_HOST_WIN32)
			set(MAKE_EXECUTABLE make.bat)
		endif()
	endif()
	
	set(Mapper_PDF_manual "OpenOrienteering-Mapper-${Mapper_VERSION_FILESYSTEM}-Manual.pdf")
	
	configure_file(Doxyfile-pdflatex.in Doxyfile-pdflatex @ONLY)
	configure_file(preprocess-markdown-pdflatex.cmake.in preprocess-markdown-pdflatex.cmake @ONLY)
	configure_file(postprocess-pdflatex.cmake.in postprocess-pdflatex.cmake @ONLY)
	add_custom_command(
	  OUTPUT    "preprocess-markdown-pdflatex.stamp"
	            "Doxyfile-pdflatex-input.txt"
	  COMMAND   "${CMAKE_COMMAND}" -P preprocess-markdown-pdflatex.cmake
	  DEPENDS   "${CMAKE_CURRENT_BINARY_DIR}/preprocess-markdown-pdflatex.cmake"
	            ${pages}
	  COMMENT   "Preprocessing Markdown for pdflatex output"
	)
	add_custom_command( 
	  OUTPUT    "${Mapper_PDF_manual}"
	  COMMAND   "${DOXYGEN_EXECUTABLE}" Doxyfile-pdflatex
	  COMMAND   "${CMAKE_COMMAND}" -P postprocess-pdflatex.cmake
	  COMMAND   "${MAKE_EXECUTABLE}" -C pdflatex
	  COMMAND   "${CMAKE_COMMAND}" -E copy_if_different "pdflatex/refman.pdf" "${Mapper_PDF_manual}"
	  COMMAND   "${CMAKE_COMMAND}" -E remove "pdflatex/refman.pdf"
	  MAIN_DEPENDENCY preprocess-markdown-pdflatex.stamp
	  DEPENDS   postprocess-pdflatex.cmake
	  WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
	  COMMENT   "Running pdflatex for PDF output"
	)
	add_custom_target(Mapper-manual-PDF
	  DEPENDS   "${Mapper_PDF_manual}"
	  SOURCES   Doxyfile-pdflatex.in
	            postprocess-pdflatex.cmake.in
	)
	add_dependencies(Mapper-manual Mapper-manual-PDF)
	
	install(
	  FILES "${CMAKE_CURRENT_BINARY_DIR}/${Mapper_PDF_manual}" 
	  DESTINATION "${MAPPER_ABOUT_DESTINATION}"
	)
endif()