summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: eb4016f5b2a591e2f0cfdec12ca8a0afcb8845ce (plain)
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# Ousía
# Copyright (C) 2014  Benjamin Paaßen, Andreas Stöckel
#
# This program 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.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

################################################################################
# Basic Project Definitions and Dependencies                                   #
################################################################################

PROJECT(ousia)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9)

# Option for enabling testing. Turn on with 'cmake -DTEST=ON'.
# TODO: Automatically activate tests if gtest is available
OPTION(TEST "Build all tests." OFF) # Makes boolean 'test' available.

# Option for building the documentation.
FIND_PACKAGE(Doxygen)
OPTION(BUILD_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" ${DOXYGEN_FOUND})

# Enable C++11 and all warnings
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic-errors -std=c++11")

# Include expat and mozjs-24 via PkgConfig
FIND_PACKAGE(PkgConfig REQUIRED)
PKG_CHECK_MODULES(MOZJS REQUIRED mozjs-24)
PKG_CHECK_MODULES(EXPAT REQUIRED expat)

# Include required Boost components using the Boost cmake package
FIND_PACKAGE(Boost COMPONENTS system filesystem program_options REQUIRED)

# Set utf8cpp include path
SET(UTF8CPP_INCLUDE_DIR "lib/utf8cpp")

################################################################################
# Check the gcc version                                                        #
################################################################################

IF(CMAKE_COMPILER_IS_GNUCC)
	EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -dumpversion
		OUTPUT_VARIABLE GCC_VERSION)
	IF(GCC_VERSION VERSION_LESS 4.8)
		ERROR("This projects requires at last GCC 4.8 or newer to be built")
	ENDIF()
ENDIF()

################################################################################
# Inclusion of doxygen                                                         #
################################################################################

IF(BUILD_DOCUMENTATION)
	IF(NOT DOXYGEN_FOUND)
		MESSAGE(FATAL_ERROR "Doxygen is needed to build the documentation.")
	ENDIF()

	SET(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
	SET(DOXYFILE ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

	CONFIGURE_FILE(${DOXYFILE_IN} ${DOXYFILE} @ONLY)

	ADD_CUSTOM_TARGET(doc
		COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
		WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
		COMMENT "Generating API documentation with Doxygen"
		VERBATIM)
ENDIF()


################################################################################
# Inclusion of gtest                                                           #
################################################################################

# Unit test handling
IF(TEST)
	# Compile gtest
	ADD_SUBDIRECTORY(lib/gtest-1.7.0)

	# Enable testing and declare some variables used for compiling the test cases
	ENABLE_TESTING()
	SET(GTEST_INCLUDE_DIRS ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
	SET(GTEST_LIBRARIES gtest gtest_main)
ENDIF()

################################################################################
# Commands for assembling and including the configuration file                 #
################################################################################

CONFIGURE_FILE(
	"${PROJECT_SOURCE_DIR}/config.h.in"
	"${PROJECT_BINARY_DIR}/config.h"
)

# Adapt the include path for finding the configuration file
INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}")

################################################################################
# Commands for building Ousía                                                  #
################################################################################

# Include directories
INCLUDE_DIRECTORIES(
	src/
	${MOZJS_INCLUDE_DIRS}
	${EXPAT_INCLUDE_DIRS}
	${Boost_INCLUDE_DIR}
	${UTF8CPP_INCLUDE_DIR}
)

# Link directories
LINK_DIRECTORIES(
	${MOZJS_LIBRARY_DIRS}
)

ADD_DEFINITIONS(
	${MOZJS_CFLAGS_OTHER}
)

ADD_LIBRARY(ousia_core
	src/core/Registry
	src/core/XML
	src/core/RangeSet
	src/core/common/Argument
	src/core/common/CharReader
	src/core/common/Exceptions
	src/core/common/Function
	src/core/common/Logger
	src/core/common/Location
	src/core/common/Number
	src/core/common/Property
	src/core/common/Rtti
	src/core/common/RttiBuilder
	src/core/common/SourceContextReader
	src/core/common/Utils
	src/core/common/Variant
	src/core/common/VariantConverter
	src/core/common/VariantReader
	src/core/common/VariantWriter
	src/core/frontend/Terminal
	src/core/frontend/TerminalLogger
	src/core/managed/Events
	src/core/managed/Managed
	src/core/managed/Manager
	src/core/model/Document
	src/core/model/Domain
	src/core/model/Index
	src/core/model/Node
	src/core/model/Project
	src/core/model/RootNode
	src/core/model/Style
	src/core/model/Typesystem
	src/core/parser/Parser
	src/core/parser/ParserContext
	src/core/parser/ParserScope
	src/core/parser/stack/Callbacks
	src/core/parser/stack/DocumentHandler
	src/core/parser/stack/DomainHandler
	src/core/parser/stack/GenericParserStates
	src/core/parser/stack/Handler
	src/core/parser/stack/ImportIncludeHandler
	src/core/parser/stack/State
	src/core/parser/stack/Stack
	src/core/parser/stack/TypesystemHandler
	src/core/parser/utils/Tokenizer
	src/core/parser/utils/TokenTrie
	src/core/resource/Resource
	src/core/resource/ResourceLocator
	src/core/resource/ResourceManager
	src/core/resource/ResourceRequest
#	src/core/script/ScriptEngine
)

# Format libraries

#ADD_LIBRARY(ousia_css
#	src/plugins/css/CodeTokenizer
#	src/plugins/css/Tokenizer
#	src/plugins/css/CSSParser
#)

#TARGET_LINK_LIBRARIES(ousia_css
#	ousia_core
#)

ADD_LIBRARY(ousia_osml
	src/formats/osml/OsmlStreamParser
)

TARGET_LINK_LIBRARIES(ousia_osml
	ousia_core
)

ADD_LIBRARY(ousia_osxml
	src/formats/osxml/OsxmlAttributeLocator
	src/formats/osxml/OsxmlEventParser
	src/formats/osxml/OsxmlParser
)

TARGET_LINK_LIBRARIES(ousia_osxml
	ousia_core
	${EXPAT_LIBRARIES}
)

# Resource locators

ADD_LIBRARY(ousia_filesystem
	src/plugins/filesystem/FileLocator
	src/plugins/filesystem/SpecialPaths
)

TARGET_LINK_LIBRARIES(ousia_filesystem
	ousia_core
	${Boost_LIBRARIES}
)

# Output libraries

ADD_LIBRARY(ousia_html
	src/plugins/html/DemoOutput
)

TARGET_LINK_LIBRARIES(ousia_html
	ousia_core
)

ADD_LIBRARY(ousia_xml
	src/plugins/xml/XmlOutput
)

TARGET_LINK_LIBRARIES(ousia_xml
	ousia_core
)

#ADD_LIBRARY(ousia_mozjs
#	src/plugins/mozjs/MozJsScriptEngine
#)
#
#TARGET_LINK_LIBRARIES(ousia_mozjs
#	ousia_core
#	${MOZJS_LIBRARIES}
#)

# Command line interface

ADD_EXECUTABLE(ousia
	src/cli/Main
)

TARGET_LINK_LIBRARIES(ousia
	ousia_core
	ousia_filesystem
	ousia_html
	ousia_xml
	ousia_osml
	ousia_osxml
	${Boost_LIBRARIES}
)

# If testing is enabled, build the unit tests
IF(TEST)

	INCLUDE_DIRECTORIES(
		${GTEST_INCLUDE_DIRS}
		test/
	)

	ADD_EXECUTABLE(ousia_test_core
		test/core/RangeSetTest
		test/core/RegistryTest
		test/core/XMLTest
		test/core/common/ArgumentTest
		test/core/common/CharReaderTest
		test/core/common/FunctionTest
		test/core/common/LoggerTest
		test/core/common/PropertyTest
		test/core/common/RttiTest
		test/core/common/SourceContextReaderTest
		test/core/common/VariantConverterTest
		test/core/common/VariantReaderTest
		test/core/common/VariantWriterTest
		test/core/common/VariantTest
		test/core/common/UtilsTest
		test/core/frontend/TerminalLoggerTest
		test/core/managed/ManagedContainerTest
		test/core/managed/ManagedTest
		test/core/managed/ManagerTest
		test/core/managed/VariantObjectTest
		test/core/model/DomainTest
		test/core/model/DocumentTest
		test/core/model/IndexTest
		test/core/model/NodeTest
		test/core/model/StyleTest
		test/core/model/TypesystemTest
		test/core/parser/ParserScopeTest
		test/core/parser/stack/StackTest
		test/core/parser/stack/StateTest
		test/core/parser/utils/TokenizerTest
		test/core/parser/utils/TokenTrieTest
		test/core/resource/ResourceLocatorTest
		test/core/resource/ResourceRequestTest
#		test/core/script/FunctionTest
#		test/core/script/ObjectTest
#		test/core/script/VariantTest
	)

	TARGET_LINK_LIBRARIES(ousia_test_core
		${GTEST_LIBRARIES}
		ousia_core
	)

	ADD_EXECUTABLE(ousia_test_filesystem
		test/plugins/filesystem/FileLocatorTest
	)

	TARGET_LINK_LIBRARIES(ousia_test_filesystem
		${GTEST_LIBRARIES}
		ousia_core
		ousia_filesystem
	)

#	ADD_EXECUTABLE(ousia_test_css
#		test/plugins/css/Tokenizer
#		test/plugins/css/CodeTokenizerTest
#		test/plugins/css/CSSParserTest
#	)

#	TARGET_LINK_LIBRARIES(ousia_test_css
#		${GTEST_LIBRARIES}
#		ousia_core
#		ousia_css
#	)

	ADD_EXECUTABLE(ousia_test_html
		test/plugins/html/DemoOutputTest
	)

	TARGET_LINK_LIBRARIES(ousia_test_html
		${GTEST_LIBRARIES}
		ousia_core
		ousia_html
	)

	ADD_EXECUTABLE(ousia_test_osml
		test/formats/osml/OsmlStreamParserTest
	)

	TARGET_LINK_LIBRARIES(ousia_test_osml
		${GTEST_LIBRARIES}
		ousia_core
		ousia_osml
	)

	ADD_EXECUTABLE(ousia_test_osxml
		test/formats/osxml/OsxmlEventParserTest
		test/formats/osxml/OsxmlParserTest
	)

	TARGET_LINK_LIBRARIES(ousia_test_osxml
		${GTEST_LIBRARIES}
		ousia_core
		ousia_osxml
		ousia_filesystem
	)

#	ADD_EXECUTABLE(ousia_test_mozjs
#		test/plugins/mozjs/MozJsScriptEngineTest
#	)

#	TARGET_LINK_LIBRARIES(ousia_test_mozjs
#		${GTEST_LIBRARIES}
#		ousia_core
#		ousia_mozjs
#	)

	# Register the unit tests
	ADD_TEST(ousia_test_core ousia_test_core)
	ADD_TEST(ousia_test_filesystem ousia_test_filesystem)
#	ADD_TEST(ousia_test_css ousia_test_css)
	ADD_TEST(ousia_test_html ousia_test_html)
	ADD_TEST(ousia_test_osml ousia_test_osml)
	ADD_TEST(ousia_test_osxml ousia_test_osxml)
#	ADD_TEST(ousia_test_mozjs ousia_test_mozjs)
ENDIF()

################################################################################
# Commands for installing                                                      #
################################################################################

INSTALL(DIRECTORY data/ DESTINATION share/ousia
		FILE_PERMISSIONS
				OWNER_READ GROUP_READ WORLD_READ
				OWNER_WRITE
		DIRECTORY_PERMISSIONS
				OWNER_READ GROUP_READ WORLD_READ
				OWNER_WRITE
				OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE
)

#INSTALL(TARGETS ousia
#		RUNTIME DESTINATION bin
#)