summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 6651069be9137fa09c7984daa7a64eba75b6cdae (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
# 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 boost (filesystem) expat and mozjs-24 via PkgConfig
FIND_PACKAGE(PkgConfig REQUIRED)
PKG_CHECK_MODULES(MOZJS REQUIRED mozjs-24)
PKG_CHECK_MODULES(EXPAT REQUIRED expat)
FIND_PACKAGE(Boost COMPONENTS system filesystem REQUIRED)

################################################################################
# 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)

	INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc)
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 building Ousía                                                  #
################################################################################

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

# Link directories
LINK_DIRECTORIES(
	${MOZJS_LIBRARY_DIRS}
)

ADD_DEFINITIONS(
	${MOZJS_CFLAGS_OTHER}
)

ADD_LIBRARY(ousia_core
	src/core/BufferedCharReader
	src/core/CodeTokenizer
	src/core/CSS
	src/core/Exceptions
	src/core/Logger
	src/core/Managed
	src/core/Node
	src/core/Registry
	src/core/ResourceLocator
	src/core/Tokenizer
#	src/core/Typesystem
	src/core/Utils
	src/core/parser/Parser
	src/core/parser/ParserStack
	src/core/parser/Scope
#	src/core/script/Function
#	src/core/script/Object
#	src/core/script/ScriptEngine
#	src/core/script/Variant
	src/core/utils/CharReader
	src/core/variant/Reader
	src/core/variant/Variant
)

ADD_LIBRARY(ousia_boost
	src/plugins/boost/FileLocator
)

TARGET_LINK_LIBRARIES(ousia_boost
	ousia_core
	${Boost_LIBRARIES}
)

ADD_LIBRARY(ousia_css
	src/plugins/css/CSSParser
)

TARGET_LINK_LIBRARIES(ousia_css
	ousia_core
)

ADD_LIBRARY(ousia_xml
	src/plugins/xml/XmlParser
)

TARGET_LINK_LIBRARIES(ousia_xml
	ousia_core
	${EXPAT_LIBRARIES}
)

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

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

	INCLUDE_DIRECTORIES(
		${GTEST_INCLUDE_DIRS}
	)

	ADD_EXECUTABLE(ousia_test_core
		test/core/BufferedCharReaderTest
		test/core/CodeTokenizerTest
		test/core/CSSTest
		test/core/LoggerTest
		test/core/ManagedTest
		test/core/ManagedContainersTest
		test/core/NodeTest
		test/core/RangeSetTest
		test/core/RegistryTest
		test/core/ResourceLocatorTest
		test/core/TokenizerTest
		test/core/UtilsTest
		test/core/parser/ParserStackTest
#		test/core/script/FunctionTest
#		test/core/script/ObjectTest
#		test/core/script/VariantTest
		test/core/utils/CharReaderTest
		test/core/variant/ReaderTest
		test/core/variant/VariantTest
	)

	TARGET_LINK_LIBRARIES(ousia_test_core
		${GTEST_LIBRARIES}
		ousia_core
	)

	ADD_EXECUTABLE(ousia_test_boost
		test/plugins/boost/FileLocatorTest
	)

	TARGET_LINK_LIBRARIES(ousia_test_boost
		${GTEST_LIBRARIES}
		ousia_core
		ousia_boost
	)

	ADD_EXECUTABLE(ousia_test_css
		test/plugins/css/CSSParserTest
	)

	TARGET_LINK_LIBRARIES(ousia_test_css
		${GTEST_LIBRARIES}
		ousia_core
		ousia_css
	)

	ADD_EXECUTABLE(ousia_test_xml
		test/plugins/xml/XmlParserTest
	)

	TARGET_LINK_LIBRARIES(ousia_test_xml
		${GTEST_LIBRARIES}
		ousia_core
		ousia_xml
	)

#	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_xml ousia_test_xml)
	ADD_TEST(ousia_test_css ousia_test_css)
#	ADD_TEST(ousia_test_mozjs ousia_test_mozjs)
ENDIF()