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