Merge remote branch 'buildsau/master'
[profile/ivi/audiomanager.git] / CMakeLists.txt
1  #
2  #  Copyright (C) 2011, BMW AG 
3  # 
4  # AudioManagerDeamon
5  #
6  # @file CMakeLists.txt
7  #
8  # @date: 20.05.2011
9  # @author: Christian Müller (christian.ei.mueller@bmw.de)
10  #
11
12 cmake_minimum_required(VERSION 2.6)
13
14 execute_process(COMMAND git describe --tags WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 
15                 OUTPUT_VARIABLE DAEMONVERSION 
16                 OUTPUT_STRIP_TRAILING_WHITESPACE)
17
18 IF (DAEMON_ERROR)
19         SET( DAEMONVERSION "homebrew-${CMAKE_SOURCE_DIR}" )
20 ENDIF(DAEMON_ERROR)
21
22 message(STATUS "Build Version ${DAEMONVERSION}")
23
24 execute_process(COMMAND git log --pretty=short WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 
25                 OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG)
26
27 PROJECT(AudioManagerDeamon)
28
29 OPTION( WITH_DBUS_WRAPPER 
30         "Enable Dbus Wrapper Support" ON )
31
32 OPTION( WITH_SOCKETHANDLER_LOOP 
33         "Enable SocketHandler Support (cannot work with SimpleDBusLoop)" ON )
34
35 OPTION( WITH_SIMPLEDBUS_LOOP 
36         "Enable SimpleDBusLoop (requires DBus_Wrapper,cannot work with SocketHandler)" OFF )
37
38 OPTION( WITH_TESTS
39         "Build together with all available unitTest" ON )
40
41 OPTION( WITH_DOCUMENTATION
42         "Build together with Doxygen Documentation" OFF )
43
44 OPTION( WITH_PLUGIN_COMMAND
45         "Build command pluings" ON)
46
47 OPTION( WITH_PLUGIN_CONTROL
48         "Build control pluing" ON)
49
50 OPTION( WITH_PLUGIN_ROUTING
51         "Build routing pluings" ON)
52
53 OPTION( WITH_MAIN
54         "Build with daemon" ON)
55
56 OPTION( WITH_PPOLL
57         "libc supports ppoll" ON)
58
59 OPTION( WITH_TELNET
60         "build with Telnetserver" ON)
61         
62 OPTION ( USE_BUILD_LIBS
63         "build with default library path = build path" ON)
64         
65 OPTION ( GLIB_DBUS_TYPES_TOLERANT
66     "build dbus with tolerance towards glib 16bit/32bit handling" ON)
67
68 #Can be changed via passing -DDBUS_SERVICE_PREFIX="XXX" to cmake
69 IF(NOT DEFINED DBUS_SERVICE_PREFIX)
70         SET( DBUS_SERVICE_PREFIX "org.genivi.audiomanager\0" )
71 ENDIF(NOT DEFINED DBUS_SERVICE_PREFIX)
72
73 #Can be changed via passing -DDBUS_SERVICE_OBJECT_PATH="XXX" to cmake
74 IF(NOT DEFINED DBUS_SERVICE_OBJECT_PATH)
75         SET( DBUS_SERVICE_OBJECT_PATH "/org/genivi/audiomanager\0" )
76 ENDIF(NOT DEFINED DBUS_SERVICE_OBJECT_PATH)
77
78 #Can be changed via passing -DDEFAULT_TELNETPORT="XXX" to cmake
79 IF(NOT DEFINED DEFAULT_TELNETPORT)
80         SET( DEFAULT_TELNETPORT 6060 )
81 ENDIF(NOT DEFINED DEFAULT_TELNETPORT)
82
83 #Can be changed via passing -DMAX_TELNETCONNECTIONS="XXX" to cmake
84 IF(NOT DEFINED MAX_TELNETCONNECTIONS)
85         SET( MAX_TELNETCONNECTIONS 3 )
86 ENDIF(NOT DEFINED MAX_TELNETCONNECTIONS)
87
88 SET(DLT_CONTEXT AudioManager)
89 SET(PLUGINS_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin/plugins)
90 SET(LIB_INSTALL_SUFFIX "audioManager")
91
92 if(USE_BUILD_LIBS)
93         SET(DEFAULT_PLUGIN_COMMAND_DIR "${PLUGINS_OUTPUT_PATH}/command")
94         SET(DEFAULT_PLUGIN_ROUTING_DIR "${PLUGINS_OUTPUT_PATH}/routing")
95         SET(CONTROLLER_PLUGIN "${PLUGINS_OUTPUT_PATH}/control/libPluginControlInterface.so")
96 else(USE_BUILD_LIBS)
97         SET(DEFAULT_PLUGIN_COMMAND_DIR "${CMAKE_INSTALL_PREFIX}/lib/${LIB_INSTALL_SUFFIX}/command")
98         SET(DEFAULT_PLUGIN_ROUTING_DIR "${CMAKE_INSTALL_PREFIX}/lib/${LIB_INSTALL_SUFFIX}/routing")
99         SET(CONTROLLER_PLUGIN "${CMAKE_INSTALL_PREFIX}/lib/${LIB_INSTALL_SUFFIX}/control/libPluginControlInterface.so")
100 endif(USE_BUILD_LIBS)
101
102 SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
103 SET(AUDIO_INCLUDES_FOLDER ${CMAKE_SOURCE_DIR}/includes)
104 SET(DOC_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/doc)
105 SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
106 SET(TEST_EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin/test)
107 SET(DOXY_FILE ${CMAKE_SOURCE_DIR}/cmake/DoxyFile.in)
108 SET(INTROSPECTION_COMMAND_XML_FILE "${AUDIO_INCLUDES_FOLDER}/dbus/CommandInterface.xml")
109
110 CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/cmake/config.cmake ${CMAKE_SOURCE_DIR}/includes/config.h )
111
112 FIND_PACKAGE(PkgConfig)
113 pkg_check_modules(DLT REQUIRED automotive-dlt)
114
115 IF(WITH_DOCUMENTATION)
116         find_package(Doxygen)
117         configure_file(${DOXY_FILE}  ${DOC_OUTPUT_PATH}/Doxyfile  @ONLY IMMEDIATE)
118         add_custom_target (AudioManangerDoku ALL 
119                 COMMAND ${DOXYGEN_EXECUTABLE} ${DOC_OUTPUT_PATH}/Doxyfile WORKING_DIRECTORY ${DOC_OUTPUT_PATH}
120                 SOURCES ${CMAKE_SOURCE_DIR} ${DOC_OUTPUT_PATH}/Doxyfile
121         )
122 ENDIF(WITH_DOCUMENTATION)
123
124 ##global build flags set(CPACK_RPM_COMPONENT_INSTALL ON)
125 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -std=c++98 -D_GNU_SOURCE -pedantic -Wno-variadic-macros")
126 #set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -std=c++98 -D_GNU_SOURCE")
127
128 if(WITH_PLUGIN_COMMAND)
129         add_subdirectory (PluginCommandInterfaceDbus)
130 endif(WITH_PLUGIN_COMMAND)
131
132 if(WITH_PLUGIN_ROUTING)
133         add_subdirectory (PluginRoutingInterfaceDbus)
134         add_subdirectory (PluginRoutingInterfaceAsync)
135 endif(WITH_PLUGIN_ROUTING)
136
137 if(WITH_PLUGIN_CONTROL)
138         add_subdirectory (PluginControlInterface)
139 endif(WITH_PLUGIN_CONTROL)
140
141 if(WITH_MAIN)
142         add_subdirectory (AudioManagerDaemon)
143 endif(WITH_MAIN)
144
145 # uninstall target
146 configure_file(
147     "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
148     "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
149     IMMEDIATE @ONLY)
150
151 add_custom_target(uninstall
152     COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
153
154 # Here starts package creation
155 SET(CPACK_SET_DESTDIR ON)
156 SET(CPACK_OUTPUT_FILE_PREFIX ${CMAKE_SOURCE_DIR}/packages)
157 SET(CPACK_GENERATOR "DEB")
158 SET(CPACK_PACKAGE_NAME "AudioManager")
159 SET(CPACK_PACKAGE_VENDOR "GENIVI")
160 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "AudioManager: This component manages audio in the GENIVI context")
161 SET(CPACK_PACKAGE_VERSION "${DAEMONVERSION}")
162 SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENCE)
163 SET(CPACK_RESOURCE_FILE_README ${CMAKE_SOURCE_DIR}/README)
164 SET(CPACK_PACKAGE_CONTACT "Christian Mueller (BMW) christian.ei.mueller@bmw.de")
165 SET(CPACK_PACKAGE_INSTALL_DIRECTORY "genivi")
166 SET(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
167 SET(CPACK_DEBIAN_PACKAGE_DEPENDS "*")
168 SET(CPACK_STRIP_FILES TRUE)
169 SET(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_SOURCE_DIR}/README)
170 SET(CPACK_SOURCE_GENERATOR "TGZ")
171 SET(CPACK_SOURCE_IGNORE_FILES ".settings*" ".cproject" ".project" "/\\\\.metadata" "\\\\.#" "/#" ".*~" "/\\\\.git" "${CMAKE_CURRENT_BINARY_DIR}" "bin/" "packages/" "config.h") 
172
173 #evaluate the properties
174 if(WITH_MAIN)
175 get_property(ADD_DEPEND GLOBAL PROPERTY bin_prop)
176 list(REMOVE_DUPLICATES ADD_DEPEND)
177 set(ALL_DEPEND ${ADD_DEPEND})
178 FOREACH (dep ${ADD_DEPEND})
179         SET(bin_DEPENDENCIES "${dep} ,${bin_DEPENDENCIES}")
180 ENDFOREACH(dep)
181 STRING(REGEX REPLACE ".$" "" bin_DEPENDENCIES ${bin_DEPENDENCIES})
182 endif(WITH_MAIN)
183
184 get_property(ADD_DEPEND GLOBAL PROPERTY sampleplugins_prop)
185 list(REMOVE_DUPLICATES ADD_DEPEND)
186 list(APPEND ALL_DEPEND ${ADD_DEPEND})
187 FOREACH (dep ${ADD_DEPEND})
188         SET(sampleplugins_DEPENDENCIES "${dep} ,${sampleplugins_DEPENDENCIES}")
189 ENDFOREACH(dep)
190 STRING(REGEX REPLACE ".$" "" sampleplugins_DEPENDENCIES ${sampleplugins_DEPENDENCIES})
191
192 if(WITH_TESTS)
193 get_property(ADD_DEPEND GLOBAL PROPERTY tests_prop)
194 list(REMOVE_DUPLICATES ADD_DEPEND)
195 list(APPEND ALL_DEPEND ${ADD_DEPEND})
196 FOREACH (dep ${ADD_DEPEND})     
197         SET(tests_DEPENDENCIES "${dep} ,${tests_DEPENDENCIES}")
198 ENDFOREACH(dep)
199 STRING(REGEX REPLACE ".$" "" tests_DEPENDENCIES ${tests_DEPENDENCIES})
200 endif(WITH_TESTS)
201
202 get_property(ADD_DEPEND GLOBAL PROPERTY dev_prop)
203 list(REMOVE_DUPLICATES ADD_DEPEND)
204 list(APPEND ALL_DEPEND ${ADD_DEPEND})
205 FOREACH (dep ${ADD_DEPEND})
206         SET(dev_DEPENDENCIES "${dep} ,${dev_DEPENDENCIES}")
207 ENDFOREACH(dep)
208 STRING(REGEX REPLACE ".$" "" dev_DEPENDENCIES ${dev_DEPENDENCIES})
209
210 list(REMOVE_DUPLICATES ALL_DEPEND)
211 list(REMOVE_ITEM ALL_DEPEND "audiomanager-bin")
212 FOREACH (dep ${ALL_DEPEND})
213         SET(all_DEPENDENCIES "${dep} ,${all_DEPENDENCIES}")
214 ENDFOREACH(dep)
215 STRING(REGEX REPLACE ".$" "" all_DEPENDENCIES ${all_DEPENDENCIES})
216 execute_process(COMMAND cp ${CMAKE_MODULE_PATH}/add_package_dependencies.sh ${CMAKE_CURRENT_BINARY_DIR})
217
218 #component based dep package generation is only supported above 2.8.5
219 IF (${CMAKE_VERSION} VERSION_GREATER 2.9.4)
220
221         SET(CPACK_COMPONENTS_ALL bin sampleplugins tests dev)
222         SET(CPACK_COMPONENTS_IGNORE_GROUPS 1)
223         SET(CPACK_DEB_COMPONENT_INSTALL ON)
224         ADD_CUSTOM_TARGET(genivi_package 
225                 COMMAND ${CMAKE_COMMAND} ${CMAKE_BINARY_DIR} -DUSE_BUILD_LIBS=ON
226                 COMMAND make package
227                 COMMAND ${CMAKE_CURRENT_BINARY_DIR}/add_package_dependencies.sh ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Linux-bin.deb ${CPACK_OUTPUT_FILE_PREFIX} \"${bin_DEPENDENCIES}\"
228                 COMMAND ${CMAKE_CURRENT_BINARY_DIR}/add_package_dependencies.sh ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Linux-sampleplugins.deb ${CPACK_OUTPUT_FILE_PREFIX} \"${sampleplugins_DEPENDENCIES}\"
229                 COMMAND ${CMAKE_CURRENT_BINARY_DIR}/add_package_dependencies.sh ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Linux-tests.deb ${CPACK_OUTPUT_FILE_PREFIX} \"${tests_DEPENDENCIES}\"
230                 COMMAND ${CMAKE_CURRENT_BINARY_DIR}/add_package_dependencies.sh ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Linux-dev.deb ${CPACK_OUTPUT_FILE_PREFIX} \"${dev_DEPENDENCIES}\"
231         ) 
232 ELSE (${CMAKE_VERSION} VERSION_GREATER 2.9.4)
233         IF(${CMAKE_VERSION} VERSION_GREATER 2.8.3)
234                 ADD_CUSTOM_TARGET(genivi_package 
235                         COMMAND ${CMAKE_COMMAND} ${CMAKE_BINARY_DIR} -DUSE_BUILD_LIBS=ON
236                         COMMAND make package
237                         COMMAND ${CMAKE_CURRENT_BINARY_DIR}/add_package_dependencies.sh ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Linux.deb ${CPACK_OUTPUT_FILE_PREFIX} \"${all_DEPENDENCIES}\"
238                 )
239         ELSE(${CMAKE_VERSION} VERSION_GREATER 2.8.3)
240                 ADD_CUSTOM_TARGET(genivi_package 
241                         COMMAND ${CMAKE_COMMAND} ${CMAKE_BINARY_DIR} -DUSE_BUILD_LIBS=ON
242                         COMMAND make package
243                         COMMAND mkdir -p ../${CPACK_OUTPUT_FILE_PREFIX}
244                         COMMAND mv ${CMAKE_CURRENT_BINARY_DIR}/${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Linux.deb ${CPACK_OUTPUT_FILE_PREFIX}
245                         COMMAND ${CMAKE_CURRENT_BINARY_DIR}/add_package_dependencies.sh ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Linux.deb ${CPACK_OUTPUT_FILE_PREFIX} \"${all_DEPENDENCIES}\"
246                 )
247         ENDIF(${CMAKE_VERSION} VERSION_GREATER 2.8.3)
248 ENDIF (${CMAKE_VERSION} VERSION_GREATER 2.9.4)
249
250 INCLUDE(CPack)
251
252