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