forked from knowrob/knowrob
-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
executable file
·454 lines (420 loc) · 16 KB
/
CMakeLists.txt
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
cmake_minimum_required(VERSION 3.5.0)
set(CMAKE_CXX_FLAGS "-Wswitch -std=c++0x -O2 -pthread ${CMAKE_CXX_FLAGS} -Wno-undef -Wnon-virtual-dtor -Wextra")
set(CMAKE_CXX_STANDARD 17)
if (POLICY CMP0148)
cmake_policy(SET CMP0148 OLD)
endif ()
option(CATKIN "Build as a catkin project." ON)
if (NOT PYTHON_MODULE_LIBDIR)
# On non-debian systems, use "site-packages" instead.
set(PYTHON_MODULE_LIBDIR "dist-packages")
endif ()
# Read version from the package.xml file.
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/package.xml package_xml_str)
if(NOT package_xml_str MATCHES "<version>([0-9]+.[0-9]+.[0-9]+)</version>")
message(FATAL_ERROR "Could not parse project version from package.xml. Aborting.")
endif()
set(PROJECT_NAME "knowrob")
set(PROJECT_VERSION ${CMAKE_MATCH_1})
set(PROJECT_DESCRIPTION "A Knowledge Base System for Cognition-enabled Robots")
set(PROJECT_WEBSITE "https://github.com/knowrob/knowrob")
message(STATUS "KnowRob version: ${PROJECT_VERSION}")
project(knowrob
VERSION ${PROJECT_VERSION}
DESCRIPTION ${PROJECT_DESCRIPTION}
HOMEPAGE_URL "https://github.com/knowrob/knowrob"
)
IF (NOT WIN32)
INCLUDE(FindPkgConfig)
ENDIF ()
set(SOMA_VERSION "2.1.0")
# include additional CMake macros
include("cmake/ontologies.cmake")
find_package(Eigen3 REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(spdlog REQUIRED)
find_package(Python COMPONENTS Interpreter Development)
# Construct Boost Python component name based on Python version
set(Boost_Python_VERSION "python${Python_VERSION_MAJOR}${Python_VERSION_MINOR}")
set(Boost_Python_COMPONENT "Boost::${Boost_Python_VERSION}")
message(STATUS "Using Boost Python component: ${Boost_Python_COMPONENT}")
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.50 REQUIRED COMPONENTS program_options serialization ${Boost_Python_VERSION})
enable_testing()
find_package(GTest REQUIRED)
pkg_check_modules(SWIPL REQUIRED swipl)
pkg_check_modules(RAPTOR REQUIRED raptor2)
pkg_check_modules(REDLAND REQUIRED redland)
link_directories(${SWIPL_LIBRARY_DIRS})
# install ontologies hosted on http servers.
# copy them into the workspace such the we can load them
# from a local source at runtime.
install_ontology(
URL "http://www.ease-crc.org/ont/DUL.owl"
VERSION "3.34")
install_ontology(
URL "https://ease-crc.github.io/soma/owl/${SOMA_VERSION}/SOMA.owl"
VERSION "${SOMA_VERSION}")
install_ontology(
URL "https://ease-crc.github.io/soma/owl/${SOMA_VERSION}/SOMA-HOME.owl"
VERSION "${SOMA_VERSION}")
# install all ontologies and default settings files
install(DIRECTORY owl
DESTINATION share/knowrob
PATTERN "catalog-*.xml" EXCLUDE)
install(DIRECTORY settings
DESTINATION share/knowrob)
# define some constants for the compilation of source files that
# are used to load project-relative files.
add_definitions(-DKNOWROB_INSTALL_PREFIX=\"${CMAKE_INSTALL_PREFIX}\")
add_definitions(-DKNOWROB_SOURCE_DIR=\"${CMAKE_SOURCE_DIR}\")
add_definitions(-DKNOWROB_BUILD_DIR=\"${CMAKE_BINARY_DIR}\")
# ignore BOOST deprecated headers
add_definitions(-DBOOST_ALLOW_DEPRECATED_HEADERS)
add_definitions(-DBOOST_BIND_GLOBAL_PLACEHOLDERS)
# enable the implicit fmt ostream formatting
add_definitions(-DFMT_DEPRECATED_OSTREAM=1)
##############
#### MONGO DB
##############
pkg_check_modules(MONGOC REQUIRED libmongoc-1.0)
# find_package(libmongoc-1.0 1.7 REQUIRED)
link_directories(${MONGOC_LIBRARY_DIRS})
##############
########## Catkin
##############
if (CATKIN)
find_package(catkin QUIET)
if (catkin_FOUND AND CATKIN_DEVEL_PREFIX)
message(STATUS "Found catkin workspace at: ${CATKIN_DEVEL_PREFIX}")
# make catkin happy
set(spdlog_INCLUDE_DIRS "")
set(GTest_INCLUDE_DIRS "")
set(-lswipl_INCLUDE_DIRS "")
catkin_package(
INCLUDE_DIRS include
LIBRARIES knowrob
DEPENDS Boost -lswipl MONGOC RAPTOR REDLAND spdlog Python GTest EIGEN3
)
else ()
message(STATUS "No catkin workspace found.")
endif ()
endif ()
##############
#### SHARED LIBRARY
##############
set(knowrob_INCLUDE_DIRS
include
${SWIPL_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
${Boost_INCLUDE_DIRS}
${Python_INCLUDE_DIRS}
${MONGOC_INCLUDE_DIRS}
${RAPTOR_INCLUDE_DIRS}
${REDLAND_INCLUDE_DIRS})
include_directories(${knowrob_INCLUDE_DIRS})
add_library(knowrob SHARED
src/knowrob.cpp
src/ThreadPool.cpp
src/Logger.cpp
src/KnowledgeBase.cpp
src/ontologies/DataSource.cpp
src/URI.cpp
src/TimePoint.cpp
src/TimeInterval.cpp
src/terms/Term.cpp
src/terms/Variable.cpp
src/terms/ListTerm.cpp
src/terms/OptionList.cpp
src/terms/Bindings.cpp
src/terms/Unifier.cpp
src/formulas/Formula.cpp
src/formulas/CompoundFormula.cpp
src/formulas/Conjunction.cpp
src/formulas/Disjunction.cpp
src/formulas/Implication.cpp
src/formulas/Negation.cpp
src/formulas/Predicate.cpp
src/formulas/Bottom.cpp
src/formulas/Top.cpp
src/formulas/ModalFormula.cpp
src/formulas/ModalOperator.cpp
src/formulas/FirstOrderLiteral.cpp
src/queries/Answer.cpp
src/queries/TokenStream.cpp
src/queries/TokenQueue.cpp
src/queries/ConjunctiveBroadcaster.cpp
src/queries/TokenBroadcaster.cpp
src/formulas/DependencyGraph.cpp
src/queries/QueryParser.cpp
src/queries/QueryTree.cpp
src/queries/TokenBuffer.cpp
src/triples/GraphQuery.cpp
src/queries/Query.cpp
src/queries/RedundantAnswerFilter.cpp
src/queries/QueryStage.cpp
src/queries/QueryPipeline.cpp
src/queries/NegationStage.cpp
src/semweb/PrefixRegistry.cpp
src/semweb/PrefixProbe.cpp
src/semweb/xsd.cpp
src/semweb/Vocabulary.cpp
src/semweb/owl.cpp
src/semweb/rdfs.cpp
src/semweb/rdf.cpp
src/semweb/Property.cpp
src/semweb/Class.cpp
src/triples/FramedTriplePattern.cpp
src/semweb/ImportHierarchy.cpp
src/reasoner/Reasoner.cpp
src/reasoner/ReasonerManager.cpp
src/PropertyTree.cpp
src/integration/prolog/PrologEngine.cpp
src/integration/InterfaceUtils.cpp
src/reasoner/prolog/PrologReasoner.cpp
src/reasoner/prolog/PrologTests.cpp
src/integration/prolog/logging.cpp
src/integration/prolog/ext/algebra.cpp
src/reasoner/mongolog/MongologReasoner.cpp
src/reasoner/mongolog/mongo_kb.cpp
src/reasoner/mongolog/bson_pl.cpp
src/reasoner/swrl/SWRLReasoner.cpp
src/reasoner/esg/ESGReasoner.cpp
src/storage/QueryableStorage.cpp
src/storage/StorageManager.cpp
src/ontologies/DataSourceHandler.cpp
src/ontologies/OntologyFile.cpp
src/ontologies/OntologyParser.cpp
src/storage/Transaction.cpp
src/storage/mongo/MongoInterface.cpp
src/storage/mongo/Database.cpp
src/storage/mongo/Collection.cpp
src/storage/mongo/ChangeStream.cpp
src/storage/mongo/Cursor.cpp
src/storage/mongo/QueryWatch.cpp
src/storage/mongo/MongoKnowledgeGraph.cpp
src/storage/mongo/BulkOperation.cpp
src/storage/mongo/Pipeline.cpp
src/storage/mongo/TripleCursor.cpp
src/storage/mongo/BindingsCursor.cpp
src/storage/mongo/Connection.cpp
src/storage/mongo/bson-helper.cpp
src/queries/ModalStage.cpp
src/triples/Perspective.cpp
src/formulas/PredicateIndicator.cpp
src/queries/AnswerYes.cpp
src/queries/AnswerNo.cpp
src/queries/AnswerDontKnow.cpp
src/queries/DisjunctiveBroadcaster.cpp
src/queries/Token.cpp
src/triples/GraphSelector.cpp
src/queries/AnswerMerger.cpp
src/integration/python/utils.cpp
src/triples/FramedTriple.cpp
src/triples/TripleFormat.cpp
src/semweb/OntologyLanguage.cpp
src/reasoner/prolog/semweb.cpp
src/integration/prolog/PrologBackend.cpp
src/integration/prolog/PrologTerm.cpp
src/ontologies/SPARQLService.cpp
src/storage/redland/RaptorContainer.cpp
src/ontologies/GraphRenaming.cpp
src/ontologies/GraphRestructuring.cpp
src/storage/redland/RedlandModel.cpp
src/ontologies/GraphTransformation.cpp
src/terms/Atom.cpp
src/terms/Atomic.cpp
src/terms/Function.cpp
src/terms/XSDAtomic.cpp
src/terms/IRIAtom.cpp
src/terms/Blank.cpp
src/terms/RDFNode.cpp
src/semweb/Resource.cpp
src/terms/Numeric.cpp
src/terms/String.cpp
src/storage/Storage.cpp
src/queries/QueryContext.cpp
src/triples/SPARQLQuery.cpp
src/triples/TripleContainer.cpp
src/KnowRobError.cpp
src/integration/python/PythonError.cpp
src/storage/ReifiedTriple.cpp
src/storage/ReifiedQuery.cpp
src/storage/ReificationContainer.cpp
src/storage/UnReificationContainer.cpp
src/storage/StorageInterface.cpp
src/triples/GraphUnion.cpp
src/triples/GraphSequence.cpp
src/triples/GraphTerm.cpp
src/storage/mongo/MongoTriple.cpp
src/storage/mongo/MongoTriplePattern.cpp
src/storage/mongo/MongoTerm.cpp
src/storage/mongo/MongoTaxonomy.cpp
src/storage/SPARQLBackend.cpp
src/queries/parsers/strings.cpp
src/queries/parsers/terms.cpp
src/queries/parsers/formula.cpp
src/reasoner/GoalDrivenReasoner.cpp
src/reasoner/DataDrivenReasoner.cpp
src/reasoner/ReasonerEvent.cpp
src/ontologies/TransformedOntology.cpp
src/reasoner/Goal.cpp
src/formulas/SimpleConjunction.cpp
src/queries/ConjunctiveQuery.cpp
src/semweb/RDFIndicator.cpp
src/integration/python/converter/shared_ptr.cpp
src/triples/GraphBuiltin.cpp
src/reasoner/RDFGoal.cpp
src/reasoner/RDFGoalReasoner.cpp
src/reasoner/Computable.cpp
src/storage/Observer.cpp
src/storage/ObserverManager.cpp
src/storage/ObserverJob.cpp
src/queries/parsers/graph.cpp)
set(KNOWROB_LIBRARIES
${SWIPL_LIBRARIES}
${MONGOC_LIBRARIES}
${RAPTOR_LIBRARIES}
${REDLAND_LIBRARIES}
${Python_LIBRARIES}
spdlog::spdlog
${GTEST_LIBRARIES})
target_link_libraries(knowrob ${KNOWROB_LIBRARIES})
# install shared library and headers
install(TARGETS knowrob
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/knowrob)
install(DIRECTORY include/knowrob
DESTINATION include)
# Install Python and Prolog files into the share directory such that they can be loaded at runtime.
install(DIRECTORY src/
DESTINATION share/knowrob
FILES_MATCHING PATTERN "*.pl"
PATTERN "__pycache__" EXCLUDE)
install(DIRECTORY src/
DESTINATION share/knowrob
FILES_MATCHING PATTERN "*.py"
PATTERN "__pycache__" EXCLUDE)
# Generate a pkg-config file for the knowrob library.
foreach(LIB ${KNOWROB_LIBRARIES})
set(PRIVATE_LIBS "${PRIVATE_LIBS} -l${LIB}")
endforeach()
configure_file(knowrob.pc.in knowrob.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/knowrob.pc
DESTINATION lib/pkgconfig)
add_executable(knowrob-terminal src/terminal.cpp)
target_link_libraries(knowrob-terminal
${KNOWROB_LIBRARIES}
Boost::program_options
Boost::serialization
${Boost_Python_COMPONENT}
knowrob)
install(TARGETS knowrob-terminal RUNTIME DESTINATION bin)
##############
########## Python module
##############
# Without this, any build libraries automatically have names "lib{x}.so"
set(CMAKE_SHARED_MODULE_PREFIX "")
add_library(knowrob_py
MODULE src/integration/python/knowrob_module.cpp
)
target_include_directories(knowrob_py PRIVATE
${SWIPL_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
${Boost_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS})
target_link_libraries(knowrob_py PRIVATE
${KNOWROB_LIBRARIES}
Boost::program_options
Boost::serialization
${Boost_Python_COMPONENT}
knowrob)
# Rename the library to knowrob.so such that it can be loaded by the
# Python interpreter through the "import knowrob" statement.
# NOTE: The library needs to be copied into site-packages directory of Python, or
# the PYTHONPATH needs to be set to include the build directory.
if (CATKIN AND catkin_FOUND AND CATKIN_DEVEL_PREFIX)
add_custom_command(TARGET knowrob_py POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CATKIN_DEVEL_PREFIX}/lib/knowrob_py.so
${CMAKE_BINARY_DIR}/knowrob.so
COMMAND_EXPAND_LISTS)
# If catkin is used (e.g. in context of ROS) add library in the devel space too.
add_custom_command(TARGET knowrob_py POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CATKIN_DEVEL_PREFIX}/lib/knowrob_py.so
${CATKIN_DEVEL_PREFIX}/lib/python3/dist-packages/knowrob.so
COMMAND_EXPAND_LISTS)
else ()
add_custom_command(TARGET knowrob_py POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/knowrob_py.so
${CMAKE_BINARY_DIR}/knowrob.so
COMMAND_EXPAND_LISTS)
endif()
# install the Python module into the site-packages directory
install(FILES ${CMAKE_BINARY_DIR}/knowrob.so
DESTINATION lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/${PYTHON_MODULE_LIBDIR})
##############
########## Doxygen
##############
find_package(Doxygen)
if (DOXYGEN_FOUND)
set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/doc/doxyfile.in)
set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/doc/doxyfile)
configure_file(${doxyfile_in} ${doxyfile} @ONLY)
if (NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/doxygen-awesome.css")
message(STATUS "Downloading \"doxygen-awesome.css\" into directory \"${CMAKE_CURRENT_BINARY_DIR}\".")
file(DOWNLOAD
https://raw.githubusercontent.com/jothepro/doxygen-awesome-css/v2.3.2/doxygen-awesome.css
${CMAKE_CURRENT_BINARY_DIR}/doxygen-awesome.css)
endif ()
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
endif ()
##############
########## CPack
##############
set(CPACK_GENERATOR "DEB")
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_DESCRIPTION ${PROJECT_DESCRIPTION})
set(CPACK_PACKAGE_HOMEPAGE_URL ${PROJECT_WEBSITE})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Daniel Beßler <danielb@uni-bremen.de>")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libboost-program-options-dev, libboost-serialization-dev, libboost-python-dev, libeigen3-dev, libmongoc-dev, libraptor2-dev, librdf0-dev, libspdlog-dev, libgtest-dev, libswipl-dev, python3-dev")
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
include(CPack)
##############
########## Unit Testings
##############
# add an executable target for GTest.
# but the testing code is partly in the *knowrob* library
# where gtest won't find them without using the "--no-as-needed"
# flag for the linker.
add_executable(all_gtests
tests/gtests.cpp
tests/QueryParserTest.cpp
tests/KnowledgeBaseTest.cpp
tests/StorageTest.cpp
tests/py/test-module.cpp
tests/TokenBroadcasterTest.cpp
tests/QueryTreeTest.cpp
tests/DependencyGraphTest.cpp
tests/DataSourceTest.cpp
tests/ConjunctiveBroadcasterTest.cpp
tests/UnifierTest.cpp
tests/py/test-jupyter.cpp
tests/py/PythonTests.cpp)
add_dependencies(all_gtests knowrob_py)
target_link_libraries(all_gtests
-Wl,--whole-archive,--no-as-needed
knowrob
-Wl,--no-whole-archive
${Boost_Python_COMPONENT}
${GTEST_MAIN_LIBRARIES})