APPLINK-6507. Add sending OnHMIStatus after policy check on app activation.
[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 #Jenkins integration section
32 #dont modify this section if you dont know details about integration with Jenkins!!!
33 set (HMI "web" CACHE STRING "HMI type")
34 option(HMI2 "Use Qt HMI" OFF)
35 option(EXTENDED_MEDIA_MODE "Turn on and off extended Madia Manager features relates to PulseAudio A2DP and GSteamer" OFF)
36 option(BUILD_SHARED_LIBS "Build all libraries as shared (if ON) or static (if OFF)" OFF)
37 option(BUILD_BT_SUPPORT "Bluetooth support" ON)
38 option(BUILD_USB_SUPPORT "libusb support" ON)
39 option(BUILD_AVAHI_SUPPORT "libavahi support" ON)
40 option(BUILD_RWLOCK_SUPPORT "rwlocks support" OFF)
41 option(BUILD_BACKTRACE_SUPPORT "backtrace support" ON)
42 option(BUILD_TESTS "Possibility to build and run tests" OFF)
43 option(BUILD_TESTS_WITH_HMI "Possibility to build and run HMI tests" OFF)
44 option(ENABLE_LOG "Logging feature" ON)
45
46 set(OS_TYPE_OPTION      "$ENV{OS_TYPE}")
47 set(DEBUG_OPTION        "$ENV{DEBUG}")
48 set(HMI_TYPE_OPTION     "$ENV{HMI_TYPE}")
49 set(TARGET_OPTION       "$ENV{TARGET}")
50 set(MEDIA_MODE_OPTION   "$ENV{MEDIA_MODE}")
51 set(HMI_ADAPTER_OPTION  "$ENV{HMI_ADAPTER}")
52
53 if (OS_TYPE_OPTION)
54   if (${OS_TYPE_OPTION} STREQUAL "QNX")
55     message(STATUS "Jenkins integration: set build process for QNX")
56     INCLUDE("./qnx_6.5.0_linux_x86.cmake")
57     #tests are not supported yet for QNX build
58     set (BUILD_TESTS OFF)
59   endif()
60 endif()
61
62 if (HMI_TYPE_OPTION)
63   if (${HMI_TYPE_OPTION} STREQUAL "HTML5")
64     message(STATUS "Jenkins integration: select HTML5 HMI")
65     set (HMI "web")
66   elseif (${HMI_TYPE_OPTION} STREQUAL "NONE")
67     message(STATUS "Jenkins integration: select HMI none")
68     set (HMI "no")
69   else ()
70     message(STATUS "Jenkins integration: select QML HMI none")
71     set (HMI "qt")
72   endif()
73 endif()
74
75 if (MEDIA_MODE_OPTION)
76   if (${MEDIA_MODE_OPTION} STREQUAL "EXTENDED_MEDIA")
77     message(STATUS "Jenkins integration: select extended media mode")
78     set (EXTENDED_MEDIA_MODE ON)
79   endif()
80 endif()
81
82 if (DEBUG_OPTION)
83   if (${DEBUG_OPTION} STREQUAL "DBG_OFF")
84     message(STATUS "Jenkins integration: build release version")
85     set (CMAKE_BUILD_TYPE Release)
86   endif()
87 endif()
88
89 if (HMI_ADAPTER_OPTION)
90   if (${HMI_ADAPTER_OPTION} STREQUAL "MESSAGEBROKER")
91     message(STATUS "Jenkins integration: selected HMI adapter MESSAGEBROKER")
92     set (HMIADAPTER "messagebroker")
93   elseif (${HMI_ADAPTER_OPTION} STREQUAL "DBUS")
94     message(STATUS "Jenkins integration: selected HMI adapter DBUS")
95     set (HMIADAPTER "dbus")
96   elseif (${HMI_ADAPTER_OPTION} STREQUAL "MQUEUE")
97     message(STATUS "Jenkins integration: selected HMI adapter MQUEUE")
98     set (HMIADAPTER "mqueue")
99   endif()
100 endif()
101
102 #Jenkins integration section end
103
104
105 cmake_minimum_required(VERSION 2.8.0)
106
107 set (PROJECT smartDeviceLinkCore)
108 project (${PROJECT})
109
110 #ADD_DEPENDENCIES(${PROJECT} Policy)
111
112 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
113
114 # Please do not change compiler/linker flags if You do not know how particular
115 # flag is handled by CMake
116 set(CMAKE_INSTALL_PREFIX .)
117 set(ARCHIVE_OUTPUT_DIRECTORY ./bin)
118 set(CMAKE_CXX_FLAGS "-g3 -ggdb3 -std=gnu++0x -Werror=return-type -Wuninitialized --coverage")
119 set(CMAKE_CXX_FLAGS_RELEASE "-s -O2") #It will be appended to CMAKE_CXX_FLAGS in release
120
121 if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
122   add_definitions(-DOS_LINUX)
123 elseif(CMAKE_SYSTEM_NAME STREQUAL "QNX")
124   add_definitions(-DOS_QNX)
125   SET(BUILD_BT_SUPPORT OFF)
126   SET(BUILD_AVAHI_SUPPORT OFF)
127   SET(BUILD_BACKTRACE_SUPPORT OFF)
128   SET(EXTENDED_MEDIA_MODE OFF)
129 endif()
130
131 if (BUILD_USB_SUPPORT)
132   add_definitions(-DUSB_SUPPORT)
133 endif()
134
135 if (BUILD_BT_SUPPORT)
136   add_definitions(-DBLUETOOTH_SUPPORT)
137 endif()
138
139 if (BUILD_AVAHI_SUPPORT)
140   add_definitions(-DAVAHI_SUPPORT)
141 # --- Check libavahi-common, libavahi-client availability
142   find_package(Libavahi)
143 endif()
144
145 if (BUILD_RWLOCK_SUPPORT)
146   add_definitions(-DRWLOCK_SUPPORT)
147 endif()
148
149 if (BUILD_BACKTRACE_SUPPORT)
150   add_definitions(-DBACKTRACE_SUPPORT)
151 endif()
152
153 if (ENABLE_LOG)
154   add_definitions(-DENABLE_LOG)
155 endif()
156
157 # TODO(AK): check current OS here
158 add_definitions(-DOS_POSIX)
159
160 # FIXME(DC): weird logic
161 IF(CMAKE_C_FLAGS_DEBUG)
162     SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG" )
163     add_definitions(-DDEBUG)
164 ELSE (CMAKE_C_FLAGS_DEBUG)
165     SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DRELEASE" )
166     add_definitions(-DRELEASE)
167 ENDIF(CMAKE_C_FLAGS_DEBUG)
168
169
170 if (EXTENDED_MEDIA_MODE)
171 add_definitions(-DEXTENDED_MEDIA_MODE)
172 # required to find 'glibconfig.h'
173 find_package(PkgConfig)
174 pkg_check_modules(GLIB2 REQUIRED glib-2.0)
175 add_definitions(${GLIB2_CFLAGS})
176 endif()
177
178 # --- Interface generator
179
180 find_package(PythonInterp)
181 if(NOT PYTHONINTERP_FOUND)
182     message(ERROR "Python interpreter is not found")
183     message(ERROR "To install it type in the command line:")
184     message(ERROR "sudo apt-get install python")
185 endif(NOT PYTHONINTERP_FOUND)
186
187 if (HMI STREQUAL "qt")
188     cmake_minimum_required(VERSION 2.8.11)
189     if (CMAKE_SYSTEM_NAME STREQUAL "QNX")
190         set(qt_version "4.8.5")
191     else ()
192         set(qt_version "5.1.0")
193     endif ()
194
195     execute_process(
196         COMMAND ${CMAKE_SOURCE_DIR}/FindQt.sh -v ${qt_version}
197             OUTPUT_VARIABLE qt_bin_dir
198     )
199     message(STATUS "Binary directory Qt ${qt_version} is ${qt_bin_dir}")
200     set(ENV{PATH} ${qt_bin_dir}:$ENV{PATH})
201
202     if (CMAKE_SYSTEM_NAME STREQUAL "QNX")
203         find_package(Qt4 ${qt_version} REQUIRED QtCore QtGui QtDBus QtDeclarative)
204     else ()
205         find_package(Qt5Core REQUIRED)
206         find_package(Qt5DBus REQUIRED)
207         find_package(Qt5Qml REQUIRED)
208         find_package(Qt5Quick REQUIRED)
209         set(qmlplugindump_binary ${qt_bin_dir}/qmlplugindump)
210     endif ()
211 endif()
212
213 set(INTEFRACE_GENERATOR "${PROJECT_SOURCE_DIR}/tools/InterfaceGenerator/Generator.py")
214 set(INTEFRACE_GENERATOR_CMD ${PYTHON_EXECUTABLE} -B ${INTEFRACE_GENERATOR})
215 file(GLOB_RECURSE INTERFACE_GENERATOR_DEPENDENCIES "${PROJECT_SOURCE_DIR}/tools/InterfaceGenerator/*.*")
216
217 macro (GenerateInterface arg_xml_name arg_namespace parser_type)
218     string(REGEX MATCH "^[a-zA-Z_0-9]*[^.]" file_name ${arg_xml_name})     # TODO: make expression more robust
219
220     set(hpp_file
221       "${CMAKE_CURRENT_BINARY_DIR}/${file_name}.h"
222       "${CMAKE_CURRENT_BINARY_DIR}/${file_name}_schema.h"
223     )
224
225     set(cpp_file "${CMAKE_CURRENT_BINARY_DIR}/${file_name}_schema.cc")
226     set(full_xml_name "${CMAKE_CURRENT_SOURCE_DIR}/${arg_xml_name}")
227
228     add_custom_command( OUTPUT ${hpp_file} ${cpp_file}
229                         COMMAND ${INTEFRACE_GENERATOR_CMD} ${full_xml_name} ${arg_namespace} ${CMAKE_CURRENT_BINARY_DIR} "--parser-type" "${parser_type}"
230                         DEPENDS ${INTERFACE_GENERATOR_DEPENDENCIES} ${full_xml_name}
231                         COMMENT "Generating files:\n   ${hpp_file}\n   ${cpp_file}\nfrom:\n   ${arg_xml_name} ..."
232                         VERBATIM
233                        )
234
235     include_directories (
236         ../../../src/components/smart_objects/include
237         ../../../src/components/formatters/include/
238         ${CMAKE_SOURCE_DIR}/src/components/formatters/include/
239         ${CMAKE_BINARY_DIR}
240     )
241
242     add_library("${file_name}" ${cpp_file})
243 endmacro(GenerateInterface)
244
245 # --- Useful macro
246 macro(create_test NAME SOURCES LIBS)
247     add_executable("${NAME}" ${SOURCES})
248     target_link_libraries("${NAME}" ${LIBS})
249     if(CMAKE_SYSTEM_NAME STREQUAL "QNX")
250         add_test(${NAME} ${CMAKE_SOURCE_DIR}/qnx/remote_run_test.sh ${NAME})
251     else()
252         add_test(${NAME} ${NAME})
253     endif()
254 endmacro(create_test)
255
256 # Building application
257
258 # --- Type HMI
259 if (HMI STREQUAL "qt")
260     set(QT_HMI ON)
261     add_definitions(-DQT_HMI)
262 elseif (HMI STREQUAL "web")
263     set(WEB_HMI ON)
264     add_definitions(-DWEB_HMI)
265 else ()
266     set(HMI "no")
267     add_definitions(-DNO_HMI)
268 endif ()
269
270 if (HMI STREQUAL "qt" AND NOT DEFINED HMIADAPTER)
271     set(HMIADAPTER "dbus")
272 endif()
273 if (HMI STREQUAL "web" AND NOT DEFINED HMIADAPTER)
274     set(HMIADAPTER "messagebroker")
275 endif()
276 if (HMI STREQUAL "no" AND NOT DEFINED HMIADAPTER)
277     set(HMIADAPTER "mqueue")
278 endif()
279
280 if (HMIADAPTER STREQUAL "dbus")
281     set(HMI_DBUS_API ON)
282     add_definitions(-DDBUS_HMIADAPTER)
283     add_definitions(-DHMI_DBUS_API)
284 endif()
285 if (HMIADAPTER STREQUAL "messagebroker")
286     set(HMI_JSON_API ON)
287     add_definitions(-DMESSAGEBROKER_HMIADAPTER)
288     add_definitions(-DHMI_JSON_API)
289 endif()
290 if (HMIADAPTER STREQUAL "mqueue")
291     set(HMI_JSON_API ON)
292     add_definitions(-DMQUEUE_HMIADAPTER)
293     add_definitions(-DHMI_JSON_API)
294 endif()
295
296 # --- ThirdPartyLibs
297 add_subdirectory(./src/thirdPartyLibs)
298
299 # --- Tools
300 add_subdirectory(./tools)
301
302 # --- Components
303 add_subdirectory(./src/components)
304
305 # --- Main application
306 add_subdirectory(./src/appMain)
307
308 # Building tests
309 if(BUILD_TESTS)
310     if(BUILD_TESTS_WITH_HMI)
311       add_definitions(-DTESTS_WITH_HMI)
312     endif()
313     enable_testing()
314     include(Dart)
315     # Framework GoogleTest is also integrated together gmock
316     # and must not be added separately
317     add_subdirectory(./src/thirdPartyLibs/gmock-1.6.0)
318     add_subdirectory(./test)
319 endif()
320
321 # Building documentation
322
323 # At first creating directory for generated documentation. Unfortunately doxygen
324 # cannot generate it byself
325 FIND_PACKAGE(Doxygen)
326   IF(DOXYGEN_FOUND)
327     option(DOXYGEN_ENABLE_DIAGRAMS "Enable graphical diagram generation" ON)
328
329     if(DOXYGEN_ENABLE_DIAGRAMS)
330       set(DOXYGEN_ENABLE_DIAGRAMS_PARAM "YES")
331     else(DOXYGEN_ENABLE_DIAGRAMS)
332       set(DOXYGEN_ENABLE_DIAGRAMS_PARAM "NO")
333     endif()
334     configure_file("${PROJECT_SOURCE_DIR}/Doxyfile" "${PROJECT_BINARY_DIR}/Doxyfile")
335     file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/doc/doxygen")
336     ADD_CUSTOM_TARGET(doxygen COMMAND ${DOXYGEN_EXECUTABLE} "${PROJECT_BINARY_DIR}/Doxyfile")
337   ELSE(DOXYGEN_FOUND)
338     MESSAGE(STATUS "Doxygen not found. Documentation will not be generated")
339     MESSAGE(STATUS "To enable documentation generation please install doxygen and graphviz packages")
340     MESSAGE(STATUS "sudo apt-get install doxygen graphviz")
341     MESSAGE(STATUS "To enable processing of MscGen comments please install mscgen")
342     MESSAGE(STATUS "sudo apt-get install mscgen")
343 ENDIF(DOXYGEN_FOUND)
344
345