Make DBUS transparency optional (off by default)
[src/app-framework-binder.git] / CMakeLists.txt
1 ###########################################################################
2 # Copyright (C) 2015-2018 "IoT.bzh"
3 #
4 # author: José Bollo <jose.bollo@iot.bzh>
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #     http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 ###########################################################################
18
19 CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
20
21 PROJECT(afb-daemon C CXX)
22
23 SET(PROJECT_NAME "AFB Daemon")
24 SET(PROJECT_PRETTY_NAME "Application Framework Binder Daemon")
25 SET(PROJECT_DESCRIPTION "Secured binder of API for clients of the Application framework")
26 SET(PROJECT_VERSION "5.99-FFRC0")
27 set(PROJECT_URL "https://gerrit.automotivelinux.org/gerrit/gitweb?p=src/app-framework-binder.git;a=summary")
28
29 SET(LIBAFBWSC_VERSION "1.1")
30 SET(LIBAFBWSC_SOVERSION "1")
31
32 INCLUDE(FindPkgConfig)
33 INCLUDE(CheckIncludeFiles)
34 INCLUDE(CheckLibraryExists)
35 INCLUDE(GNUInstallDirs)
36 INCLUDE(CTest)
37
38 ###########################################################################
39 # possible settings
40 set(AGL_DEVEL OFF CACHE BOOL "Activates developping features")
41 set(INCLUDE_MONITORING OFF CACHE BOOL "Activates installation of monitoring")
42 set(INCLUDE_SUPERVISOR OFF CACHE BOOL "Activates installation of supervisor")
43 set(INCLUDE_DBUS_TRANSPARENCY OFF CACHE BOOL "Allows API transparency over DBUS")
44 set(AFS_SUPERVISION_SOCKET "@urn:AGL:afs:supervision:socket" CACHE STRING "Internal socket for supervision")
45 set(AFS_SUPERVISOR_PORT 1619 CACHE STRING "Port of service for the supervisor")
46 set(AFS_SUPERVISOR_TOKEN HELLO CACHE STRING "Secret token for the supervisor")
47 set(UNITDIR_SYSTEM ${CMAKE_INSTALL_LIBDIR}/systemd/system CACHE STRING "Path to systemd system unit files")
48
49 ###########################################################################
50
51 link_libraries(-Wl,--as-needed -Wl,--gc-sections -Wl,--no-undefined)
52
53 add_compile_options(-Wall -Wextra -Wconversion)
54 add_compile_options(-Wno-unused-parameter) # frankly not using a parameter does it care?
55 add_compile_options(-Wno-sign-compare -Wno-sign-conversion)
56 add_compile_options(-Werror=maybe-uninitialized)
57 add_compile_options(-Werror=implicit-function-declaration)
58 add_compile_options(-ffunction-sections -fdata-sections)
59 add_compile_options(-fPIC)
60 add_compile_options(-g)
61 set (CMAKE_CXX_STANDARD 14)
62
63 set(CMAKE_C_FLAGS_PROFILING    "-g -O2 -pg -Wp,-U_FORTIFY_SOURCE")
64 set(CMAKE_C_FLAGS_DEBUG        "-g -ggdb -Wp,-U_FORTIFY_SOURCE")
65 set(CMAKE_C_FLAGS_RELEASE      "-g -O2")
66 set(CMAKE_C_FLAGS_CCOV         "-g -O2 --coverage")
67
68 ###########################################################################
69
70 INCLUDE(FindThreads)
71 FIND_PACKAGE(Threads)
72
73 PKG_CHECK_MODULES(json-c REQUIRED json-c)
74
75 CHECK_INCLUDE_FILES(magic.h HAVE_MAGIC_H)
76 CHECK_LIBRARY_EXISTS(magic magic_load "" HAVE_LIBMAGIC_SO)
77 IF(HAVE_MAGIC_H)
78   IF(HAVE_LIBMAGIC_SO)
79     SET(HAVE_LIBMAGIC "1")
80     SET(LIBMAGIC_LDFLAGS -lmagic)
81   ENDIF(HAVE_LIBMAGIC_SO)
82 ENDIF(HAVE_MAGIC_H)
83
84 PKG_CHECK_MODULES(libsystemd libsystemd>=222)
85 PKG_CHECK_MODULES(libmicrohttpd libmicrohttpd>=0.9.55)
86 PKG_CHECK_MODULES(openssl openssl)
87 PKG_CHECK_MODULES(uuid uuid)
88 PKG_CHECK_MODULES(cynara cynara-client)
89
90 ADD_DEFINITIONS("-DAFS_SUPERVISION_SOCKET=\"${AFS_SUPERVISION_SOCKET}\"")
91 ADD_DEFINITIONS("-DAFS_SUPERVISOR_TOKEN=\"${AFS_SUPERVISOR_TOKEN}\"")
92 ADD_DEFINITIONS("-DAFS_SUPERVISOR_PORT=${AFS_SUPERVISOR_PORT}")
93
94 IF(AGL_DEVEL)
95         ADD_DEFINITIONS(-DAGL_DEVEL)
96 ENDIF()
97
98 IF(cynara_FOUND)
99         ADD_DEFINITIONS(-DBACKEND_PERMISSION_IS_CYNARA)
100 ENDIF(cynara_FOUND)
101
102 IF(HAVE_LIBMAGIC AND libsystemd_FOUND AND libmicrohttpd_FOUND AND openssl_FOUND AND uuid_FOUND)
103   ADD_DEFINITIONS(-DUSE_MAGIC_MIME_TYPE)
104 ELSE()
105   IF(NOT HAVE_LIBMAGIC)
106     MESSAGE(WARNING "\"magic.h\" or \"libmagic.so\" missing.
107     Please install the \"file-devel\" or \"libmagic-dev\" package !")
108   ENDIF(NOT HAVE_LIBMAGIC)
109   IF(NOT libsystemd_FOUND)
110     MESSAGE(WARNING "Dependency to 'libsystemd' is missing")
111   ENDIF()
112   IF(NOT libmicrohttpd_FOUND)
113     MESSAGE(WARNING "Dependency to 'libmicrohttpd' is missing")
114   ENDIF()
115   IF(NOT openssl_FOUND)
116     MESSAGE(WARNING "Dependency to 'openssl' is missing")
117   ENDIF()
118   IF(NOT uuid_FOUND)
119     MESSAGE(WARNING "Dependency to 'uuid' is missing")
120   ENDIF()
121   IF(NOT ONLY_DEVTOOLS)
122     MESSAGE(FATAL_ERROR "Can't compile the binder, either define ONLY_DEVTOOLS or install dependencies")
123   ENDIF()
124 ENDIF()
125
126 ADD_DEFINITIONS(-DAFB_VERSION="${PROJECT_VERSION}")
127
128 INCLUDE_DIRECTORIES(
129         ${INCLUDE_DIRS}
130         ${CMAKE_SOURCE_DIR}/include
131         ${json-c_INCLUDE_DIRS}
132         ${libsystemd_INCLUDE_DIRS}
133         ${libmicrohttpd_INCLUDE_DIRS}
134         ${uuid_INCLUDE_DIRS}
135         ${openssl_INCLUDE_DIRS}
136         ${cynara_INCLUDE_DIRS}
137 )
138
139 SET(link_libraries
140         ${CMAKE_THREAD_LIBS_INIT}
141         ${json-c_LDFLAGS}
142         ${libsystemd_LDFLAGS}
143         ${libmicrohttpd_LDFLAGS}
144         ${uuid_LDFLAGS}
145         ${openssl_LDFLAGS}
146         ${cynara_LDFLAGS}
147         ${LIBMAGIC_LDFLAGS}
148         -ldl
149         -lrt
150         )
151
152 ADD_SUBDIRECTORY(src/devtools)
153
154 IF(ONLY_DEVTOOLS)
155         MESSAGE(WARNING "Only DEVTOOLS are compiled, not the binder!")
156 ELSE()
157         SET(binding_install_dir ${CMAKE_INSTALL_FULL_LIBDIR}/afb)
158
159         ###########################################################################
160         # activates the monitoring by default
161         if(INCLUDE_MONITORING AND NOT ONLY_DEVTOOLS)
162                 add_definitions(-DWITH_MONITORING_OPTION)
163                 INSTALL(DIRECTORY
164                         ${CMAKE_CURRENT_SOURCE_DIR}/test/monitoring
165                         DESTINATION
166                         ${binding_install_dir}
167                 )
168         endif()
169
170         ###########################################################################
171
172         ADD_SUBDIRECTORY(src)
173         ADD_SUBDIRECTORY(src/tests)
174         ADD_SUBDIRECTORY(include)
175         ADD_SUBDIRECTORY(bindings)
176
177         ############################################################
178         # installs the pkgconfig files
179         CONFIGURE_FILE(afb-daemon.pc.in afb-daemon.pc @ONLY)
180         CONFIGURE_FILE(libafbwsc.pc.in libafbwsc.pc @ONLY)
181
182         INSTALL(FILES
183             ${CMAKE_CURRENT_BINARY_DIR}/afb-daemon.pc
184             ${CMAKE_CURRENT_BINARY_DIR}/libafbwsc.pc
185             DESTINATION
186             ${CMAKE_INSTALL_LIBDIR}/pkgconfig
187         )
188
189 ENDIF()
190
191 IF(INCLUDE_SUPERVISOR)
192         CONFIGURE_FILE(afs-supervisor.service.in afs-supervisor.service @ONLY)
193         INSTALL(FILES
194             ${CMAKE_CURRENT_BINARY_DIR}/afs-supervisor.service
195             DESTINATION
196             ${UNITDIR_SYSTEM}
197         )
198 ENDIF()
199