Set version to 5.99.FFRC3
[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.FFRC3")
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
41 set(AGL_DEVEL OFF CACHE BOOL "Activates developping features")
42 set(INCLUDE_MONITORING OFF CACHE BOOL "Activates installation of monitoring")
43 set(INCLUDE_SUPERVISOR OFF CACHE BOOL "Activates installation of supervisor")
44 set(INCLUDE_DBUS_TRANSPARENCY OFF CACHE BOOL "Allows API transparency over DBUS")
45 set(INCLUDE_LEGACY_BINDING_V1 OFF CACHE BOOL "Includes the legacy Binding API version 1")
46 set(INCLUDE_LEGACY_BINDING_VDYN OFF CACHE BOOL "Includes the legacy Binding API version dynamic")
47 set(AFS_SUPERVISION_SOCKET "@urn:AGL:afs:supervision:socket" CACHE STRING "Internal socket for supervision")
48 set(AFS_SUPERVISOR_PORT 1619 CACHE STRING "Port of service for the supervisor")
49 set(AFS_SUPERVISOR_TOKEN HELLO CACHE STRING "Secret token for the supervisor")
50 set(UNITDIR_SYSTEM ${CMAKE_INSTALL_LIBDIR}/systemd/system CACHE STRING "Path to systemd system unit files")
51
52 ###########################################################################
53
54 link_libraries(-Wl,--as-needed -Wl,--gc-sections -Wl,--no-undefined)
55
56 add_compile_options(-Wall -Wextra -Wconversion)
57 add_compile_options(-Wno-unused-parameter) # frankly not using a parameter does it care?
58 add_compile_options(-Wno-sign-compare -Wno-sign-conversion)
59 add_compile_options(-Werror=maybe-uninitialized)
60 add_compile_options(-Werror=implicit-function-declaration)
61 add_compile_options(-ffunction-sections -fdata-sections)
62 add_compile_options(-fPIC)
63 add_compile_options(-g)
64 set (CMAKE_CXX_STANDARD 14)
65
66 set(CMAKE_C_FLAGS_PROFILING    "-g -O2 -pg -Wp,-U_FORTIFY_SOURCE")
67 set(CMAKE_C_FLAGS_DEBUG        "-g -ggdb -Wp,-U_FORTIFY_SOURCE")
68 set(CMAKE_C_FLAGS_RELEASE      "-g -O2")
69 set(CMAKE_C_FLAGS_CCOV         "-g -O2 --coverage")
70
71 ###########################################################################
72
73 INCLUDE(FindThreads)
74 FIND_PACKAGE(Threads)
75
76 PKG_CHECK_MODULES(json-c REQUIRED json-c)
77
78 CHECK_INCLUDE_FILES(magic.h HAVE_MAGIC_H)
79 CHECK_LIBRARY_EXISTS(magic magic_load "" HAVE_LIBMAGIC_SO)
80 IF(HAVE_MAGIC_H)
81   IF(HAVE_LIBMAGIC_SO)
82     SET(HAVE_LIBMAGIC "1")
83     SET(LIBMAGIC_LDFLAGS -lmagic)
84   ENDIF(HAVE_LIBMAGIC_SO)
85 ENDIF(HAVE_MAGIC_H)
86
87 PKG_CHECK_MODULES(libsystemd libsystemd>=222)
88 PKG_CHECK_MODULES(libmicrohttpd libmicrohttpd>=0.9.55)
89 PKG_CHECK_MODULES(openssl openssl)
90 PKG_CHECK_MODULES(uuid uuid)
91 PKG_CHECK_MODULES(cynara cynara-client)
92
93 ADD_DEFINITIONS("-DAFS_SUPERVISION_SOCKET=\"${AFS_SUPERVISION_SOCKET}\"")
94 ADD_DEFINITIONS("-DAFS_SUPERVISOR_TOKEN=\"${AFS_SUPERVISOR_TOKEN}\"")
95 ADD_DEFINITIONS("-DAFS_SUPERVISOR_PORT=${AFS_SUPERVISOR_PORT}")
96
97 IF(AGL_DEVEL)
98         ADD_DEFINITIONS(-DAGL_DEVEL)
99 ENDIF()
100
101 IF(cynara_FOUND)
102         ADD_DEFINITIONS(-DBACKEND_PERMISSION_IS_CYNARA)
103 ENDIF(cynara_FOUND)
104
105 IF(HAVE_LIBMAGIC AND libsystemd_FOUND AND libmicrohttpd_FOUND AND openssl_FOUND AND uuid_FOUND)
106   ADD_DEFINITIONS(-DUSE_MAGIC_MIME_TYPE)
107 ELSE()
108   IF(NOT HAVE_LIBMAGIC)
109     MESSAGE(WARNING "\"magic.h\" or \"libmagic.so\" missing.
110     Please install the \"file-devel\" or \"libmagic-dev\" package !")
111   ENDIF(NOT HAVE_LIBMAGIC)
112   IF(NOT libsystemd_FOUND)
113     MESSAGE(WARNING "Dependency to 'libsystemd' is missing")
114   ENDIF()
115   IF(NOT libmicrohttpd_FOUND)
116     MESSAGE(WARNING "Dependency to 'libmicrohttpd' is missing")
117   ENDIF()
118   IF(NOT openssl_FOUND)
119     MESSAGE(WARNING "Dependency to 'openssl' is missing")
120   ENDIF()
121   IF(NOT uuid_FOUND)
122     MESSAGE(WARNING "Dependency to 'uuid' is missing")
123   ENDIF()
124   IF(NOT ONLY_DEVTOOLS)
125     MESSAGE(FATAL_ERROR "Can't compile the binder, either define ONLY_DEVTOOLS or install dependencies")
126   ENDIF()
127 ENDIF()
128
129 ADD_DEFINITIONS(-DAFB_VERSION="${PROJECT_VERSION}")
130
131 INCLUDE_DIRECTORIES(
132         ${INCLUDE_DIRS}
133         ${CMAKE_SOURCE_DIR}/include
134         ${json-c_INCLUDE_DIRS}
135         ${libsystemd_INCLUDE_DIRS}
136         ${libmicrohttpd_INCLUDE_DIRS}
137         ${uuid_INCLUDE_DIRS}
138         ${openssl_INCLUDE_DIRS}
139         ${cynara_INCLUDE_DIRS}
140 )
141
142 SET(link_libraries
143         ${CMAKE_THREAD_LIBS_INIT}
144         ${json-c_LDFLAGS}
145         ${libsystemd_LDFLAGS}
146         ${libmicrohttpd_LDFLAGS}
147         ${uuid_LDFLAGS}
148         ${openssl_LDFLAGS}
149         ${cynara_LDFLAGS}
150         ${LIBMAGIC_LDFLAGS}
151         -ldl
152         -lrt
153         )
154
155 ADD_SUBDIRECTORY(src/devtools)
156
157 IF(ONLY_DEVTOOLS)
158         MESSAGE(WARNING "Only DEVTOOLS are compiled, not the binder!")
159 ELSE()
160         SET(binding_install_dir ${CMAKE_INSTALL_FULL_LIBDIR}/afb)
161
162         ###########################################################################
163         # activates the monitoring by default
164         if(INCLUDE_MONITORING AND NOT ONLY_DEVTOOLS)
165                 add_definitions(-DWITH_MONITORING_OPTION)
166                 INSTALL(DIRECTORY
167                         ${CMAKE_CURRENT_SOURCE_DIR}/test/monitoring
168                         DESTINATION
169                         ${binding_install_dir}
170                 )
171         endif()
172
173         ###########################################################################
174
175         ADD_SUBDIRECTORY(src)
176         ADD_SUBDIRECTORY(src/tests)
177         ADD_SUBDIRECTORY(include)
178         ADD_SUBDIRECTORY(bindings)
179
180         ############################################################
181         # installs the pkgconfig files
182         CONFIGURE_FILE(afb-daemon.pc.in afb-daemon.pc @ONLY)
183         CONFIGURE_FILE(libafbwsc.pc.in libafbwsc.pc @ONLY)
184
185         INSTALL(FILES
186             ${CMAKE_CURRENT_BINARY_DIR}/afb-daemon.pc
187             ${CMAKE_CURRENT_BINARY_DIR}/libafbwsc.pc
188             DESTINATION
189             ${CMAKE_INSTALL_LIBDIR}/pkgconfig
190         )
191
192 ENDIF()
193
194 IF(INCLUDE_SUPERVISOR)
195         CONFIGURE_FILE(afs-supervisor.service.in afs-supervisor.service @ONLY)
196         INSTALL(FILES
197             ${CMAKE_CURRENT_BINARY_DIR}/afs-supervisor.service
198             DESTINATION
199             ${UNITDIR_SYSTEM}
200         )
201 ENDIF()
202