Remove apple related flags
[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 if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
139   add_definitions(-DOS_LINUX)
140 elseif(CMAKE_SYSTEM_NAME STREQUAL "QNX")
141   add_definitions(-DOS_QNX)
142   SET(BUILD_BT_SUPPORT OFF)
143   SET(BUILD_AVAHI_SUPPORT OFF)
144   SET(BUILD_BACKTRACE_SUPPORT OFF)
145   SET(EXTENDED_MEDIA_MODE OFF)
146 endif()
147
148 if (BUILD_USB_SUPPORT)
149   add_definitions(-DUSB_SUPPORT)
150 endif()
151
152 if (BUILD_BT_SUPPORT)
153   add_definitions(-DBLUETOOTH_SUPPORT)
154 endif()
155
156 if (BUILD_MME_SUPPORT)
157   add_definitions(-DMME_SUPPORT)
158   if (MME_MQ)
159     add_definitions(-DMME_MQ)
160   endif(MME_MQ)
161 endif(BUILD_MME_SUPPORT)
162
163 if (BUILD_AVAHI_SUPPORT)
164   add_definitions(-DAVAHI_SUPPORT)
165 # --- Check libavahi-common, libavahi-client availability
166   find_package(Libavahi)
167 endif()
168
169 if (BUILD_RWLOCK_SUPPORT)
170   add_definitions(-DRWLOCK_SUPPORT)
171 endif()
172
173 if (BUILD_BACKTRACE_SUPPORT)
174   add_definitions(-DBACKTRACE_SUPPORT)
175 endif()
176
177 if(ENABLE_LOG)
178   add_definitions(-DENABLE_LOG)
179 endif()
180
181 if (TIME_TESTER)
182     add_definitions(-DTIME_TESTER)
183 endif()
184
185 # TODO(AK): check current OS here
186 add_definitions(-DOS_POSIX)
187
188 # FIXME(DC): weird logic
189 IF(CMAKE_C_FLAGS_DEBUG)
190     SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG" )
191     add_definitions(-DDEBUG)
192 ELSE (CMAKE_C_FLAGS_DEBUG)
193     SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DRELEASE" )
194     add_definitions(-DRELEASE)
195 ENDIF(CMAKE_C_FLAGS_DEBUG)
196
197
198 if (EXTENDED_MEDIA_MODE)
199 add_definitions(-DEXTENDED_MEDIA_MODE)
200 # required to find 'glibconfig.h'
201 find_package(PkgConfig)
202 pkg_check_modules(GLIB2 REQUIRED glib-2.0)
203 add_definitions(${GLIB2_CFLAGS})
204 endif()
205
206 # --- Interface generator
207
208 find_package(PythonInterp)
209 if(NOT PYTHONINTERP_FOUND)
210     message(ERROR "Python interpreter is not found")
211     message(ERROR "To install it type in the command line:")
212     message(ERROR "sudo apt-get install python")
213 endif(NOT PYTHONINTERP_FOUND)
214
215 if (HMI STREQUAL "qt")
216     cmake_minimum_required(VERSION 2.8.11)
217     if (CMAKE_SYSTEM_NAME STREQUAL "QNX")
218         set(qt_version "4.8.5")
219     else ()
220         set(qt_version "5.1.0")
221     endif ()
222
223     execute_process(
224         COMMAND ${CMAKE_SOURCE_DIR}/FindQt.sh -v ${qt_version}
225             OUTPUT_VARIABLE qt_bin_dir
226     )
227     message(STATUS "Binary directory Qt ${qt_version} is ${qt_bin_dir}")
228     set(ENV{PATH} ${qt_bin_dir}:$ENV{PATH})
229
230     if (CMAKE_SYSTEM_NAME STREQUAL "QNX")
231         find_package(Qt4 ${qt_version} REQUIRED QtCore QtGui QtDBus QtDeclarative)
232     else ()
233         find_package(Qt5Core REQUIRED)
234         find_package(Qt5DBus REQUIRED)
235         find_package(Qt5Qml REQUIRED)
236         find_package(Qt5Quick REQUIRED)
237         set(qmlplugindump_binary ${qt_bin_dir}/qmlplugindump)
238     endif ()
239 endif()
240
241 set(INTEFRACE_GENERATOR "${PROJECT_SOURCE_DIR}/tools/InterfaceGenerator/Generator.py")
242 set(INTEFRACE_GENERATOR_CMD ${PYTHON_EXECUTABLE} -B ${INTEFRACE_GENERATOR})
243 file(GLOB_RECURSE INTERFACE_GENERATOR_DEPENDENCIES "${PROJECT_SOURCE_DIR}/tools/InterfaceGenerator/*.*")
244
245 macro (GenerateInterface arg_xml_name arg_namespace parser_type)
246     string(REGEX MATCH "^[a-zA-Z_0-9]*[^.]" file_name ${arg_xml_name})     # TODO: make expression more robust
247
248     set(hpp_file
249       "${CMAKE_CURRENT_BINARY_DIR}/${file_name}.h"
250       "${CMAKE_CURRENT_BINARY_DIR}/${file_name}_schema.h"
251     )
252
253     set(cpp_file "${CMAKE_CURRENT_BINARY_DIR}/${file_name}_schema.cc")
254     set(full_xml_name "${CMAKE_CURRENT_SOURCE_DIR}/${arg_xml_name}")
255
256     add_custom_command( OUTPUT ${hpp_file} ${cpp_file}
257                         COMMAND ${INTEFRACE_GENERATOR_CMD} ${full_xml_name} ${arg_namespace} ${CMAKE_CURRENT_BINARY_DIR} "--parser-type" "${parser_type}"
258                         DEPENDS ${INTERFACE_GENERATOR_DEPENDENCIES} ${full_xml_name}
259                         COMMENT "Generating files:\n   ${hpp_file}\n   ${cpp_file}\nfrom:\n   ${arg_xml_name} ..."
260                         VERBATIM
261                        )
262
263     include_directories (
264         ../../../src/components/smart_objects/include
265         ../../../src/components/formatters/include/
266         ${CMAKE_SOURCE_DIR}/src/components/formatters/include/
267         ${CMAKE_BINARY_DIR}
268     )
269
270     add_library("${file_name}" ${cpp_file})
271 endmacro(GenerateInterface)
272
273 # --- Useful macro
274 macro(create_test NAME SOURCES LIBS)
275     add_executable("${NAME}" ${SOURCES})
276     target_link_libraries("${NAME}" ${LIBS})
277     if(CMAKE_SYSTEM_NAME STREQUAL "QNX")
278         add_test(${NAME} ${CMAKE_SOURCE_DIR}/qnx/remote_run_test.sh ${NAME})
279     else()
280         add_test(${NAME} ${NAME})
281     endif()
282 endmacro(create_test)
283
284 # Building application
285
286 # --- Type HMI
287 if (HMI STREQUAL "qt")
288     set(QT_HMI ON)
289     add_definitions(-DQT_HMI)
290 elseif (HMI STREQUAL "web")
291     set(WEB_HMI ON)
292     add_definitions(-DWEB_HMI)
293 else ()
294     set(HMI "no")
295     add_definitions(-DNO_HMI)
296 endif ()
297
298 if (HMI STREQUAL "qt" AND NOT DEFINED HMIADAPTER)
299     set(HMIADAPTER "dbus")
300 endif()
301 if (HMI STREQUAL "web" AND NOT DEFINED HMIADAPTER)
302     set(HMIADAPTER "messagebroker")
303 endif()
304 if (HMI STREQUAL "no" AND NOT DEFINED HMIADAPTER)
305     set(HMIADAPTER "mqueue")
306 endif()
307
308 if (HMIADAPTER STREQUAL "dbus")
309     set(HMI_DBUS_API ON)
310     add_definitions(-DDBUS_HMIADAPTER)
311     add_definitions(-DHMI_DBUS_API)
312 endif()
313 if (HMIADAPTER STREQUAL "messagebroker")
314     set(HMI_JSON_API ON)
315     add_definitions(-DMESSAGEBROKER_HMIADAPTER)
316     add_definitions(-DHMI_JSON_API)
317 endif()
318 if (HMIADAPTER STREQUAL "mqueue")
319     set(HMI_JSON_API ON)
320     add_definitions(-DMQUEUE_HMIADAPTER)
321     add_definitions(-DHMI_JSON_API)
322 endif()
323
324 # --- ThirdPartyLibs
325 add_subdirectory(./src/thirdPartyLibs)
326
327 # --- Tools
328 add_subdirectory(./tools)
329
330 # --- Components
331 add_subdirectory(./src/components)
332
333 # --- Main application
334 add_subdirectory(./src/appMain)
335
336 # Building tests
337 if(BUILD_TESTS)
338     if(BUILD_TESTS_WITH_HMI)
339       add_definitions(-DTESTS_WITH_HMI)
340     endif()
341     enable_testing()
342     include(Dart)
343     # Framework GoogleTest is also integrated together gmock
344     # and must not be added separately
345     add_subdirectory(./src/thirdPartyLibs/gmock-1.7.0)
346     add_subdirectory(./test)
347 endif()
348
349 # Building documentation
350
351 # At first creating directory for generated documentation. Unfortunately doxygen
352 # cannot generate it byself
353 FIND_PACKAGE(Doxygen)
354   IF(DOXYGEN_FOUND)
355     option(DOXYGEN_ENABLE_DIAGRAMS "Enable graphical diagram generation" ON)
356
357     if(DOXYGEN_ENABLE_DIAGRAMS)
358       set(DOXYGEN_ENABLE_DIAGRAMS_PARAM "YES")
359     else(DOXYGEN_ENABLE_DIAGRAMS)
360       set(DOXYGEN_ENABLE_DIAGRAMS_PARAM "NO")
361     endif()
362     configure_file("${PROJECT_SOURCE_DIR}/Doxyfile" "${PROJECT_BINARY_DIR}/Doxyfile")
363     file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/doc/doxygen")
364     ADD_CUSTOM_TARGET(doxygen COMMAND ${DOXYGEN_EXECUTABLE} "${PROJECT_BINARY_DIR}/Doxyfile")
365   ELSE(DOXYGEN_FOUND)
366     MESSAGE(STATUS "Doxygen not found. Documentation will not be generated")
367     MESSAGE(STATUS "To enable documentation generation please install doxygen and graphviz packages")
368     MESSAGE(STATUS "sudo apt-get install doxygen graphviz")
369     MESSAGE(STATUS "To enable processing of MscGen comments please install mscgen")
370     MESSAGE(STATUS "sudo apt-get install mscgen")
371 ENDIF(DOXYGEN_FOUND)