-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
375 lines (323 loc) · 14.4 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
#=============================================================================
# CMake integration Copyright 2015 Christian Frisson.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
project(InspectorWidgetProcessor)
cmake_minimum_required(VERSION 3.0)
# add some find scripts
list(APPEND CMAKE_MODULE_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
file(GLOB CMAKEDIRLIST ${CMAKE_CURRENT_SOURCE_DIR}/cmake/*)
foreach(CMAKEDIR ${CMAKEDIRLIST})
if(IS_DIRECTORY ${CMAKEDIR})
list(APPEND CMAKE_MODULE_PATHS "${CMAKEDIR}")
endif()
endforeach()
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATHS}")
set(InspectorWidgetProcessor_VERSION 0.1pre)
if(${PROJECT_BINARY_DIR} EQUAL ${PROJECT_SOURCE_DIR})
message(FATAL_ERROR "In-source building forbidden: create a 'Builds' subdirectory itself containing a directory describing your system and architecture.")
endif()
######################
# OPTIONS #
######################
option(BUILD_SHARED_LIBS "Build InspectorWidgetProcessor libraries as shared" ON)
option(USE_DEBUG "Use Debug" ON)
option(BUILD_CLI "Build InspectorWidgetProcessor CLI " OFF)
option(BUILD_TESTS "Build InspectorWidgetProcessor tests " OFF)
if(USE_DEBUG)
message( "\nConfigured for Debug Build")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_DEBUG -DTI_DEBUG=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_DEBUG -DTI_DEBUG=1")
if(NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif()
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_VERBOSE_MAKEFILE ON)
else(USE_DEBUG)
message( "\nConfigured for Release Build")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTI_DEBUG=0 -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_DEBUG=0 -O3")
set(CMAKE_BUILD_TYPE "MinSizeRel")#Debug|Release|RelWithDebInfo|MinSizeRel
set(CMAKE_VERBOSE_MAKEFILE ON)#CF
if(APPLE)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/release")
endif()
endif(USE_DEBUG)
#########################
# EXTERNAL DEPENDENCIES #
#########################
#Threads
find_package(Threads)
# OpenCV
if(APPLE)
set(OpenCV_MIN_VERSION "3.0.0")
else()
set(OpenCV_MIN_VERSION "2.0.0")
endif()
find_path(OpenCV_DIR NAMES opencv-config.cmake OpenCVConfig.cmake PATH_SUFFIXES lib/cmake) # for MacPorts
if(WIN32)
if(EXISTS $ENV{OPENCV_DIR})
set(OpenCV_DIR $ENV{OPENCV_DIR} )
find_path(OpenCV_DIR NAMES opencv-config.cmake OpenCVConfig.cmake)
else(EXISTS $ENV{OPENCV_DIR})
message("Please set OPENCV_DIR environnement variable to top folder containing OpenCVConfig.cmake")
endif(EXISTS $ENV{OPENCV_DIR})
endif(WIN32)
if(APPLE)
find_package(OpenCV ${OpenCV_MIN_VERSION} REQUIRED COMPONENTS core features2d imgproc imgcodecs objdetect video highgui)
else()
find_package(OpenCV ${OpenCV_MIN_VERSION} REQUIRED COMPONENTS core features2d imgproc objdetect video highgui)
endif()
if(OpenCV_FOUND)
if(OpenCV_opencv_highgui_EXTRA_DEPS_OPT AND CMAKE_TOOLCHAIN_FILE AND MINGW)
string(REGEX MATCH ".*QtCore.*" OpenCV_WITH_Qt "${OpenCV_opencv_highgui_EXTRA_DEPS_OPT}")
if(OpenCV_WITH_Qt)
message("OpenCV with Qt")
endif()
endif()
message("OpenCV found in ${OpenCV_INCLUDE_DIRS}")
foreach(OpenCV_INCLUDE_DIR ${OpenCV_INCLUDE_DIRS})
include_directories(${OpenCV_INCLUDE_DIR})
endforeach(OpenCV_INCLUDE_DIR)
if(MINGW OR WIN32)
set(OpenCV_LIBRARIES ${OpenCV_LIBS_OPT} ${OpenCV_EXTRA_LIBS_OPT})
else()
set(OpenCV_LIBRARIES ${OpenCV_LIBS})
endif()
message("Found OpenCV ${OpenCV_VERSION} libraries ${OpenCV_LIBRARIES} and headers ${OpenCV_INCLUDE_DIRS}")
#message( "OpenCV link directories: ${OpenCV_LIB_DIRECTORY}")
foreach(OpenCV_LIB_DIRECTORY ${OpenCV_LIB_DIRS})
add_linked_directory(${OpenCV_LIB_DIRECTORY})
endforeach(OpenCV_LIB_DIRECTORY)
else(OpenCV_FOUND)
message(FATAL_ERROR "OpenCV not found.")
endif(OpenCV_FOUND)
# Tesseract
find_package(Tesseract)
if(Tesseract_FOUND)
message("Tesseract found: headers in ${Tesseract_INCLUDE_DIR} and library ${Tesseract_LIBRARY}")
else()
message(FATAL_ERROR "Tesseract not found")
endif()
find_package(TBB)
if(TBB_FOUND)
message("TBB found: headers in ${TBB_INCLUDE_DIR} and library ${TBB_LIBRARY}")
else()
message("TBB not found")
endif()
# git
find_program(GIT NAMES git)
if(GIT)
set(GIT_FOUND ON CACHE STRING "git found" FORCE)
message("Found git: ${GIT}")
else()
message(FATAL_ERROR "Could not find git. Please install git.\n")
endif()
# NODE
find_program(NODE NAMES node)
if(NODE)
set(NODE_FOUND ON CACHE STRING "node found" FORCE)
message("Found node: ${NODE}")
else()
message(FATAL_ERROR "Could not find node.js. Please install node.js so that the 'node' command is available.\n")
endif()
# NPM
set(NPM_DEPENDECIES "cmake-js") #bower;grunt;http-server
find_program(NPM NAMES npm)
if(NPM)
message("Found npm: ${NPM}")
set(NPM_FOUND ON CACHE STRING "npm found" FORCE)
foreach(NPM_DEPENDENCY ${NPM_DEPENDECIES})
#message("Checking ${NPM_DEPENDENCY}")
if(NOT NPM_${NPM_DEPENDENCY}_FOUND)
#exec_program(${NPM} ARGS "list --parseable -g ${NPM_DEPENDENCY}" OUTPUT_VARIABLE NPM_DEP_OUT RESULT_VARIABLE NPM_DEP_RES)
#string(REGEX MATCH "npm ERR! code" NPM_DEP_NOT_FOUND ${NPM_DEP_OUT})
find_program(DEP_${NPM_DEPENDENCY} NAMES ${NPM_DEPENDENCY})
set(NPM_DEP_OUT ${DEP_${NPM_DEPENDENCY}})
if(NPM_DEP_OUT)#if(NOT NPM_DEP_NOT_FOUND)
set(NPM_${NPM_DEPENDENCY}_FOUND ON CACHE STRING "${NPM_DEPENDENCY} found" FORCE)
set(NPM_${NPM_DEPENDENCY} "${NPM_DEP_OUT}" CACHE STRING "${NPM_DEPENDENCY} path" FORCE)
else()
message(FATAL_ERROR "Couldn't find ${NPM_DEPENDENCY}. Please install it globally with: npm install ${NPM_DEPENDENCY} -g")
endif()
endif()
message("Found ${NPM_DEPENDENCY}: ${NPM_${NPM_DEPENDENCY}}")
endforeach()
else()
message(FATAL_ERROR "Could not find npm. Please install npm\n")
endif()
#########################
# INTERNAL DEPENDENCIES #
#########################
find_path(RAPIDJSON_DIR PATH_SUFFIXES ${CMAKE_SOURCE_DIR}/3rdparty/github-InspectorWidget-rapidjson/include)
find_path(PARTIALCSVPARSER_DIR PATH_SUFFIXES ${CMAKE_SOURCE_DIR}/3rdparty/github-InspectorWidget-PartialCsvParser/include)
find_path(LIBUIOHOOK_DIR PATH_SUFFIXES ${CMAKE_SOURCE_DIR}/3rdparty/github-InspectorWidget-libuiohook/include)
find_path(PEGTL_DIR PATH_SUFFIXES ${CMAKE_SOURCE_DIR}/3rdparty/github-InspectorWidget-PEGTL)
if(NOT RAPIDJSON_DIR OR NOT PARTIALCSVPARSER_DIR OR NOT LIBUIOHOOK_DIR OR NOT PEGTL_DIR)
execute_process(COMMAND ${GIT} submodule update --init ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE GIT_OUT RESULT_VARIABLE GIT_RES)
endif()
set(RAPIDJSON_BUILD_DOC OFF CACHE BOOL "" FORCE)
set(RAPIDJSON_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(RAPIDJSON_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(RAPIDJSON_BUILD_THIRDPARTY_GTEST OFF CACHE BOOL "" FORCE)
add_subdirectory(3rdparty/github-InspectorWidget-rapidjson)
include_directories(${CMAKE_SOURCE_DIR}/3rdparty/github-InspectorWidget-rapidjson/include)
include_directories(${CMAKE_SOURCE_DIR}/3rdparty/github-InspectorWidget-PartialCsvParser/include)
set(BUILD_APPS OFF CACHE BOOL "" FORCE)
add_subdirectory(3rdparty/github-InspectorWidget-libuiohook)
include_directories(${CMAKE_SOURCE_DIR}/3rdparty/github-InspectorWidget-libuiohook/include)
add_subdirectory(3rdparty/github-InspectorWidget-PEGTL)
include_directories(${CMAKE_SOURCE_DIR}/3rdparty/github-InspectorWidget-PEGTL)
add_subdirectory(3rdparty/github-InspectorWidget-pugixml)
include_directories(${CMAKE_SOURCE_DIR}/3rdparty/github-InspectorWidget-pugixml/src)
######################
# INTERNAL LIBRARIES #
######################
include_directories(lib)
add_subdirectory(lib)
######################
# INTERNAL LIBRARIES #
######################
if(BUILD_CLI)
include_directories(cli)
add_subdirectory(cli)
endif()
######################
# NODEJS ADDON #
######################
if(APPLE)
set(CMAKE_MACOSX_RPATH TRUE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
list(APPEND CMAKE_INSTALL_RPATH "@loader_path/" "@executable_path/")
endif()
# Get and apply the cmake-js flags by executing it
execute_process(COMMAND ${NODE} ${NPM_cmake-js} print-configure -d ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE PC_OUT RESULT_VARIABLE PC_RES)
#message("${NPM_cmake-js} print-configure -d ${CMAKE_CURRENT_SOURCE_DIR}: ${PC_OUT} // ${PC_RES}")
string(REGEX REPLACE ";" "§" PC_OUT "${PC_OUT}") # hack to handle lists passed as flags
string(REGEX MATCHALL " -D[A-Z_]+=\"[^\"]+\"" FLAGS "${PC_OUT}")
foreach(FLAG ${FLAGS})
string(REGEX REPLACE "§" ";" FLAG "${FLAG}") # hack to handle lists passed as flags
string(REGEX REPLACE "^ -D" "" FLAG "${FLAG}") # remove the CMake flag prefix
string(REGEX MATCH "^[^=]+" CMAKE_FLAG_NAME "${FLAG}") # split the flag name
string(REGEX MATCH "=.+$" CMAKE_FLAG_VALUE "${FLAG}") # split the flag value
string(REGEX MATCH "[^=\"]+.+[^\"]" CMAKE_FLAG_VALUE "${CMAKE_FLAG_VALUE}") # remove inverted commas and equal sign
string(FIND ${CMAKE_FLAG_NAME} "COMPILER" COMPILER) # check if the flag regards the compiler
if(COMPILER GREATER "-1" OR CMAKE_FLAG_NAME STREQUAL "CMAKE_LIBRARY_OUTPUT_DIRECTORY")
#set(${CMAKE_FLAG_NAME} ${CMAKE_FLAG_VALUE})
else()
set(${CMAKE_FLAG_NAME} "${${CMAKE_FLAG_NAME}} ${CMAKE_FLAG_VALUE}")
endif()
endforeach()
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Release")
# Essential include files to build a node addon,
# you should add this line in every CMake.js based project.
include_directories(${CMAKE_JS_INC})
#message("CMAKE_JS_INC ${CMAKE_JS_INC}")
# Check if nodes modules are installed
string(REGEX MATCH "node_modules" CMAKE_JS_INC_NODE_MODULES "${CMAKE_JS_INC}") # split the flag name
if(NOT CMAKE_JS_INC_NODE_MODULES)
message(FATAL_ERROR "Please first run 'npm install' on the source directory")
endif()
# Declare the source files location
file(GLOB SOURCE_FILES "*.cc" "*.h")
# This line will tell CMake that we're building a shared library
# from the above source files
# named after the project's name
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
# This line will give our library file a .node extension without any "lib" prefix
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
# Essential library files to link to a node addon,
# you should add this line in every CMake.js based project.
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})
#message("CMAKE_JS_LIB ${CMAKE_JS_LIB}")
target_link_libraries(${PROJECT_NAME} InspectorWidgetProcessorLibrary)
message("[X] ${PROJECT_NAME}")
######################
# TESTS #
######################
if(BUILD_TESTS)
add_subdirectory(tests)
endif()
######################
# DOCUMENTATION #
######################
option(BUILD_DOCUMENTATION "Build documentation" OFF)
if(BUILD_DOCUMENTATION)
find_package(UnixCommands REQUIRED)
find_package(Doxygen REQUIRED)
find_package(Gnuplot REQUIRED)
find_package(HTMLHelp REQUIRED)
find_package(Perl REQUIRED)
find_package(Wget REQUIRED)
# Warning: doxygen doesn't confuse YES/NO and ON/OFF like CMake does
set(GENERATE_LATEX NO)
find_package(LATEX)
if(PDFLATEX_COMPILER)
set(GENERATE_LATEX YES)
endif()
if(DOT)
set(HAVE_DOT YES)
else()
set(HAVE_DOT NO)
message(FATAL_ERROR "Graphviz dot missing.")
endif()
set(CALL_GRAPH YES)# if set to YES, a graphical call graph is drawn for each function showing the functions that the function directly or indirectly calls.
set(CALLER_GRAPH YES)# if set to YES, a graphical caller graph is drawn for each function showing the functions that the function is directly or indirectly called by.
option(DOCUMENTATION_GRAPH_FUNCTION_CALLS "Enable graphical call/callers graphs for each function that the functions calls/are called by." ON)
if(DOCUMENTATION_GRAPH_FUNCTION_CALLS)
set(CALL_GRAPH YES)
set(CALLER_GRAPH YES)
endif()
option(DOCUMENTATION_HTML_HELP "Build the HTML Help file (CHM)." OFF)
option(DOCUMENTATION_HTML_TARZ "Build a compressed tar archive of the HTML doc." OFF)
option(BUILD_REF_DOCS_SEARCHENGINE "Enable doxygen's search engine (requires that documentation to be installed on a php enabled web server)" ON)
if(BUILD_REF_DOCS_SEARCHENGINE)
set(SEARCHENGINE YES)
else()
set(SEARCHENGINE NO)
endif()
option(BUILD_REF_DOCS_TAGFILE "Generate a tag file named ${PROJECT_NAME}.tag on the documentation web server" OFF)
if(BUILD_REF_DOCS_TAGFILE)
set(GENERATE_TAGFILE "${CMAKE_BINARY_DIR}/doc/${PROJECT_NAME}/${PROJECT_NAME}.tag")
else()
set(GENERATE_TAGFILE "")
endif()
# If html help generation was requested. DOCUMENTATION_HTML_HELP is defined by Documentation.cmake
set(GENERATE_HTMLHELP "NO")
if(DOCUMENTATION_HTML_HELP)
# on windows Documentation.cmake finds the html help workshop fi it exists. On u*ix we might have it with wine but no way to point it out
if(NOT WIN32)
set(HTML_HELP_COMPILER "" CACHE FILEPATH "Enter location of the HTML help compiler to let doxygen compile html")
mark_as_advanced(HTML_HELP_COMPILER)
endif()
# this var sets a proper value in .doxygen files when coniguring them below
set(GENERATE_HTMLHELP "YES")
endif()
# This processes our doxyfile.cmake and substitutes paths to generate
# a final Doxyfile
configure_file(${PROJECT_SOURCE_DIR}/doc/doxyfile.cmake
${PROJECT_BINARY_DIR}/doc/${PROJECT_NAME}.doxyfile
)
# copy the logo to documentations target folder
#configure_file(${PROJECT_SOURCE_DIR}/data/icons/${PROJECT_NAME}.png
# ${PROJECT_BINARY_DIR}/doc/${PROJECT_NAME}/${PROJECT_NAME}.png COPYONLY
#)
#install(FILES ${PROJECT_BINARY_DIR}/doc/${PROJECT_NAME}-${${PROJECT_NAME}_VERSION}.chm DESTINATION doc OPTIONAL COMPONENT ${PROJECT_NAME}-doc)
install(DIRECTORY ${PROJECT_BINARY_DIR}/doc/${PROJECT_NAME} DESTINATION doc COMPONENT ${PROJECT_NAME}-doc)
# This creates a new target to build documentation.
# It runs ${DOXYGEN} which is the full path and executable to
# Doxygen on your system.
# It runs the final generated Doxyfile against it.
# The DOT_PATH is substituted into the Doxyfile.
add_custom_target(doc ${DOXYGEN}
${PROJECT_BINARY_DIR}/doc/${PROJECT_NAME}.doxyfile
)
endif()