Package SmartDeviceLink 3.5.
[profile/ivi/smartdevicelink.git] / CMakeLists.txt
1 # Copyright (c) 2013, Ford Motor Company
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
6 #
7 # Redistributions of source code must retain the above copyright notice, this
8 # list of conditions and the following disclaimer.
9 #
10 # Redistributions in binary form must reproduce the above copyright notice,
11 # this list of conditions and the following
12 # disclaimer in the documentation and/or other materials provided with the
13 # distribution.
14 #
15 # Neither the name of the Ford Motor Company nor the names of its contributors
16 # may be used to endorse or promote products derived from this software
17 # without specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30
31 cmake_minimum_required(VERSION 2.8.0)
32
33 set (PROJECT smartDeviceLinkCore)
34
35 #Jenkins integration section
36 #dont modify this section if you dont know details about integration with Jenkins!!!
37 set (HMI "web" CACHE STRING "HMI type")
38 option(HMI2 "Use Qt HMI" OFF)
39 option(EXTENDED_MEDIA_MODE "Turn on and off extended Madia Manager features relates to PulseAudio A2DP and GStreamer" OFF)
40 option(BUILD_SHARED_LIBS "Build all libraries as shared (if ON) or static (if OFF)" OFF)
41 option(BUILD_BT_SUPPORT "Bluetooth support" ON)
42 option(BUILD_USB_SUPPORT "libusb support" ON)
43 option(BUILD_AVAHI_SUPPORT "libavahi support" ON)
44 option(BUILD_RWLOCK_SUPPORT "rwlocks support" OFF)
45 option(BUILD_BACKTRACE_SUPPORT "backtrace support" ON)
46 option(BUILD_TESTS "Possibility to build and run tests" OFF)
47 option(TIME_TESTER "Enable profiling time test util" ON)
48 option(BUILD_TESTS_WITH_HMI "Possibility to build and run HMI tests" OFF)
49 option(ENABLE_LOG "Logging feature" ON)
50 option(ENABLE_GCOV "gcov code coverage feature" OFF)
51 option(EXTENDED_POLICY_FLAG "Build with specific features and extended functionality" OFF)
52
53 set(OS_TYPE_OPTION      "$ENV{OS_TYPE}")
54 set(DEBUG_OPTION        "$ENV{DEBUG}")
55 set(HMI_TYPE_OPTION     "$ENV{HMI_TYPE}")
56 set(TARGET_OPTION       "$ENV{TARGET}")
57 set(MEDIA_MODE_OPTION   "$ENV{MEDIA_MODE}")
58 set(HMI_ADAPTER_OPTION  "$ENV{HMI_ADAPTER}")
59 set(ENABLE_LOG_OPTION   "$ENV{ENABLE_LOG}")
60
61 if (OS_TYPE_OPTION)
62   if (${OS_TYPE_OPTION} STREQUAL "QNX")
63     message(STATUS "Jenkins integration: set build process for QNX")
64     #do not use include after project() command.
65     #Such usecase results in infinite cycle of reinitialization of compiler and other variables
66     INCLUDE("./qnx_6.5.0_linux_x86.cmake")
67     #tests are not supported yet for QNX build
68     set (BUILD_TESTS OFF)
69   endif()
70 endif()
71
72 if (HMI_TYPE_OPTION)
73   if (${HMI_TYPE_OPTION} STREQUAL "HTML5")
74     message(STATUS "Jenkins integration: select HTML5 HMI")
75     set (HMI "web")
76   elseif (${HMI_TYPE_OPTION} STREQUAL "NONE")
77     message(STATUS "Jenkins integration: select HMI none")
78     set (HMI "no")
79   else ()
80     message(STATUS "Jenkins integration: select QML HMI none")
81     set (HMI "qt")
82   endif()
83 endif()
84
85 if (MEDIA_MODE_OPTION)
86   if (${MEDIA_MODE_OPTION} STREQUAL "EXTENDED_MEDIA")
87     message(STATUS "Jenkins integration: select extended media mode")
88     set (EXTENDED_MEDIA_MODE ON)
89   endif()
90 endif()
91
92 if (DEBUG_OPTION)
93   if (${DEBUG_OPTION} STREQUAL "DBG_OFF")
94     message(STATUS "Jenkins integration: build release version")
95     set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
96   endif()
97 endif()
98
99 if (HMI_ADAPTER_OPTION)
100   if (${HMI_ADAPTER_OPTION} STREQUAL "MESSAGEBROKER")
101     message(STATUS "Jenkins integration: selected HMI adapter MESSAGEBROKER")
102     set (HMIADAPTER "messagebroker")
103   elseif (${HMI_ADAPTER_OPTION} STREQUAL "DBUS")
104     message(STATUS "Jenkins integration: selected HMI adapter DBUS")
105     set (HMIADAPTER "dbus")
106   elseif (${HMI_ADAPTER_OPTION} STREQUAL "MQUEUE")
107     message(STATUS "Jenkins integration: selected HMI adapter MQUEUE")
108     set (HMIADAPTER "mqueue")
109   endif()
110 endif()
111
112 if (ENABLE_LOG_OPTION)
113   if (${ENABLE_LOG_OPTION} STREQUAL "LOG_OFF")
114     message(STATUS "Jenkins integration: Log is turned off")
115     set (ENABLE_LOG OFF)
116   endif()
117 endif()
118
119 #Jenkins integration section end
120
121 project (${PROJECT})
122
123 #ADD_DEPENDENCIES(${PROJECT} Policy)
124
125 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
126
127 # Please do not change compiler/linker flags if You do not know how particular
128 # flag is handled by CMake
129 set(CMAKE_INSTALL_PREFIX .)
130 set(ARCHIVE_OUTPUT_DIRECTORY ./bin)
131 set(CMAKE_CXX_FLAGS "-fPIC -g3 -ggdb3 -std=gnu++0x -Werror=return-type -Wuninitialized")
132 if (ENABLE_GCOV)
133   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
134   add_definitions(-DGCOV_ENABLED)
135 endif()
136 set(CMAKE_CXX_FLAGS_RELEASE "-fPIC -s -O2") #It will be appended to CMAKE_CXX_FLAGS in release
137
138 add_definitions(-DSDL_LOG4CXX_PROPERTIES_FILE="/etc/smartdevicelink/log4cxx.properties")
139 add_definitions(-DSDL_HMI_LINK_FILE="/etc/smartdevicelink/hmi_link")
140 add_definitions(-DSDL_CONFIG_FILE="/etc/smartdevicelink/smartDeviceLink.ini")
141 add_definitions(-DSDL_HMI_BROWSER_PATH="/usr/bin/xwalk-launcher" -DSDL_HMI_BROWSER_ARG0="xwalk-launcher")
142
143 if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
144   add_definitions(-DOS_LINUX)
145 elseif(CMAKE_SYSTEM_NAME STREQUAL "QNX")
146   add_definitions(-DOS_QNX)
147   SET(BUILD_BT_SUPPORT OFF)
148   SET(BUILD_AVAHI_SUPPORT OFF)
149   SET(BUILD_BACKTRACE_SUPPORT OFF)
150   SET(EXTENDED_MEDIA_MODE OFF)
151 endif()
152
153 if (BUILD_USB_SUPPORT)
154   add_definitions(-DUSB_SUPPORT)
155 endif()
156
157 if (BUILD_BT_SUPPORT)
158   add_definitions(-DBLUETOOTH_SUPPORT)
159 endif()
160
161 if (BUILD_MME_SUPPORT)
162   add_definitions(-DMME_SUPPORT)
163   if (MME_MQ)
164     add_definitions(-DMME_MQ)
165   endif(MME_MQ)
166 endif(BUILD_MME_SUPPORT)
167
168 if (BUILD_AVAHI_SUPPORT)
169   add_definitions(-DAVAHI_SUPPORT)
170 # --- Check libavahi-common, libavahi-client availability
171   find_package(Libavahi)
172 endif()
173
174 if (BUILD_RWLOCK_SUPPORT)
175   add_definitions(-DRWLOCK_SUPPORT)
176 endif()
177
178 if (BUILD_BACKTRACE_SUPPORT)
179   add_definitions(-DBACKTRACE_SUPPORT)
180 endif()
181
182 if(ENABLE_LOG)
183   add_definitions(-DENABLE_LOG)
184 endif()
185
186 if (TIME_TESTER)
187     add_definitions(-DTIME_TESTER)
188 endif()
189
190 # TODO(AK): check current OS here
191 add_definitions(-DOS_POSIX)
192
193 # FIXME(DC): weird logic
194 IF(CMAKE_C_FLAGS_DEBUG)
195     SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG" )
196     add_definitions(-DDEBUG)
197 ELSE (CMAKE_C_FLAGS_DEBUG)
198     SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DRELEASE" )
199     add_definitions(-DRELEASE)
200 ENDIF(CMAKE_C_FLAGS_DEBUG)
201
202
203 if (EXTENDED_MEDIA_MODE)
204 add_definitions(-DEXTENDED_MEDIA_MODE)
205 # required to find 'glibconfig.h'
206 find_package(PkgConfig)
207 pkg_check_modules(GLIB2 REQUIRED glib-2.0)
208 add_definitions(${GLIB2_CFLAGS})
209 endif()
210
211 # --- Interface generator
212
213 find_package(PythonInterp)
214 if(NOT PYTHONINTERP_FOUND)
215     message(ERROR "Python interpreter is not found")
216     message(ERROR "To install it type in the command line:")
217     message(ERROR "sudo apt-get install python")
218 endif(NOT PYTHONINTERP_FOUND)
219
220 if (HMI STREQUAL "qt")
221     cmake_minimum_required(VERSION 2.8.11)
222     if (CMAKE_SYSTEM_NAME STREQUAL "QNX")
223         set(qt_version "4.8.5")
224     else ()
225         set(qt_version "5.1.0")
226     endif ()
227
228     execute_process(
229         COMMAND ${CMAKE_SOURCE_DIR}/FindQt.sh -v ${qt_version}
230             OUTPUT_VARIABLE qt_bin_dir
231     )
232     message(STATUS "Binary directory Qt ${qt_version} is ${qt_bin_dir}")
233     set(ENV{PATH} ${qt_bin_dir}:$ENV{PATH})
234
235     if (CMAKE_SYSTEM_NAME STREQUAL "QNX")
236         find_package(Qt4 ${qt_version} REQUIRED QtCore QtGui QtDBus QtDeclarative)
237     else ()
238         find_package(Qt5Core REQUIRED)
239         find_package(Qt5DBus REQUIRED)
240         find_package(Qt5Qml REQUIRED)
241         find_package(Qt5Quick REQUIRED)
242         set(qmlplugindump_binary ${qt_bin_dir}/qmlplugindump)
243     endif ()
244 endif()
245
246 set(INTEFRACE_GENERATOR "${PROJECT_SOURCE_DIR}/tools/InterfaceGenerator/Generator.py")
247 set(INTEFRACE_GENERATOR_CMD ${PYTHON_EXECUTABLE} -B ${INTEFRACE_GENERATOR})
248 file(GLOB_RECURSE INTERFACE_GENERATOR_DEPENDENCIES "${PROJECT_SOURCE_DIR}/tools/InterfaceGenerator/*.*")
249
250 macro (GenerateInterface arg_xml_name arg_namespace parser_type)
251     string(REGEX MATCH "^[a-zA-Z_0-9]*[^.]" file_name ${arg_xml_name})     # TODO: make expression more robust
252
253     set(hpp_file
254       "${CMAKE_CURRENT_BINARY_DIR}/${file_name}.h"
255       "${CMAKE_CURRENT_BINARY_DIR}/${file_name}_schema.h"
256     )
257
258     set(cpp_file "${CMAKE_CURRENT_BINARY_DIR}/${file_name}_schema.cc")
259     set(full_xml_name "${CMAKE_CURRENT_SOURCE_DIR}/${arg_xml_name}")
260
261     add_custom_command( OUTPUT ${hpp_file} ${cpp_file}
262                         COMMAND ${INTEFRACE_GENERATOR_CMD} ${full_xml_name} ${arg_namespace} ${CMAKE_CURRENT_BINARY_DIR} "--parser-type" "${parser_type}"
263                         DEPENDS ${INTERFACE_GENERATOR_DEPENDENCIES} ${full_xml_name}
264                         COMMENT "Generating files:\n   ${hpp_file}\n   ${cpp_file}\nfrom:\n   ${arg_xml_name} ..."
265                         VERBATIM
266                        )
267
268     include_directories (
269         ../../../src/components/smart_objects/include
270         ../../../src/components/formatters/include/
271         ${CMAKE_SOURCE_DIR}/src/components/formatters/include/
272         ${CMAKE_BINARY_DIR}
273     )
274
275     add_library("${file_name}" ${cpp_file})
276 endmacro(GenerateInterface)
277
278 # --- Useful macro
279 macro(create_test NAME SOURCES LIBS)
280     add_executable("${NAME}" ${SOURCES})
281     target_link_libraries("${NAME}" ${LIBS})
282     if(CMAKE_SYSTEM_NAME STREQUAL "QNX")
283         add_test(${NAME} ${CMAKE_SOURCE_DIR}/qnx/remote_run_test.sh ${NAME})
284     else()
285         add_test(${NAME} ${NAME})
286     endif()
287 endmacro(create_test)
288
289 # Building application
290
291 # --- Type HMI
292 if (HMI STREQUAL "qt")
293     set(QT_HMI ON)
294     add_definitions(-DQT_HMI)
295 elseif (HMI STREQUAL "web")
296     set(WEB_HMI ON)
297     add_definitions(-DWEB_HMI)
298 else ()
299     set(HMI "no")
300     add_definitions(-DNO_HMI)
301 endif ()
302
303 if (HMI STREQUAL "qt" AND NOT DEFINED HMIADAPTER)
304     set(HMIADAPTER "dbus")
305 endif()
306 if (HMI STREQUAL "web" AND NOT DEFINED HMIADAPTER)
307     set(HMIADAPTER "messagebroker")
308 endif()
309 if (HMI STREQUAL "no" AND NOT DEFINED HMIADAPTER)
310     set(HMIADAPTER "mqueue")
311 endif()
312
313 if (HMIADAPTER STREQUAL "dbus")
314     set(HMI_DBUS_API ON)
315     add_definitions(-DDBUS_HMIADAPTER)
316     add_definitions(-DHMI_DBUS_API)
317 endif()
318 if (HMIADAPTER STREQUAL "messagebroker")
319     set(HMI_JSON_API ON)
320     add_definitions(-DMESSAGEBROKER_HMIADAPTER)
321     add_definitions(-DHMI_JSON_API)
322 endif()
323 if (HMIADAPTER STREQUAL "mqueue")
324     set(HMI_JSON_API ON)
325     add_definitions(-DMQUEUE_HMIADAPTER)
326     add_definitions(-DHMI_JSON_API)
327 endif()
328
329 # --- ThirdPartyLibs
330 add_subdirectory(./src/thirdPartyLibs)
331
332 # --- Tools
333 add_subdirectory(./tools)
334
335 # --- Components
336 add_subdirectory(./src/components)
337
338 # --- Main application
339 add_subdirectory(./src/appMain)
340
341 # Building tests
342 if(BUILD_TESTS)
343     if(BUILD_TESTS_WITH_HMI)
344       add_definitions(-DTESTS_WITH_HMI)
345     endif()
346     enable_testing()
347     include(Dart)
348     # Framework GoogleTest is also integrated together gmock
349     # and must not be added separately
350     add_subdirectory(./src/thirdPartyLibs/gmock-1.7.0)
351     add_subdirectory(./test)
352 endif()
353
354 # Building documentation
355
356 # At first creating directory for generated documentation. Unfortunately doxygen
357 # cannot generate it byself
358 FIND_PACKAGE(Doxygen)
359   IF(DOXYGEN_FOUND)
360     option(DOXYGEN_ENABLE_DIAGRAMS "Enable graphical diagram generation" ON)
361
362     if(DOXYGEN_ENABLE_DIAGRAMS)
363       set(DOXYGEN_ENABLE_DIAGRAMS_PARAM "YES")
364     else(DOXYGEN_ENABLE_DIAGRAMS)
365       set(DOXYGEN_ENABLE_DIAGRAMS_PARAM "NO")
366     endif()
367     configure_file("${PROJECT_SOURCE_DIR}/Doxyfile" "${PROJECT_BINARY_DIR}/Doxyfile")
368     file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/doc/doxygen")
369     ADD_CUSTOM_TARGET(doxygen COMMAND ${DOXYGEN_EXECUTABLE} "${PROJECT_BINARY_DIR}/Doxyfile")
370   ELSE(DOXYGEN_FOUND)
371     MESSAGE(STATUS "Doxygen not found. Documentation will not be generated")
372     MESSAGE(STATUS "To enable documentation generation please install doxygen and graphviz packages")
373     MESSAGE(STATUS "sudo apt-get install doxygen graphviz")
374     MESSAGE(STATUS "To enable processing of MscGen comments please install mscgen")
375     MESSAGE(STATUS "sudo apt-get install mscgen")
376 ENDIF(DOXYGEN_FOUND)