packaging: Update spec and deb packaging
[src/app-framework-binder.git] / CMakeLists.txt
1 ###########################################################################
2 # Copyright 2015, 2016, 2017 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.0.0-EE")
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
43 ###########################################################################
44
45 link_libraries(-Wl,--as-needed -Wl,--gc-sections -Wl,--no-undefined)
46
47 add_compile_options(-Wall -Wextra -Wconversion)
48 add_compile_options(-Wno-unused-parameter) # frankly not using a parameter does it care?
49 add_compile_options(-Wno-sign-compare -Wno-sign-conversion)
50 add_compile_options(-Werror=maybe-uninitialized)
51 add_compile_options(-Werror=implicit-function-declaration)
52 add_compile_options(-ffunction-sections -fdata-sections)
53 add_compile_options(-fPIC)
54 add_compile_options(-g)
55 set (CMAKE_CXX_STANDARD 14)
56
57 set(CMAKE_C_FLAGS_PROFILING    "-g -O2 -pg -Wp,-U_FORTIFY_SOURCE")
58 set(CMAKE_C_FLAGS_DEBUG        "-g -ggdb -Wp,-U_FORTIFY_SOURCE")
59 set(CMAKE_C_FLAGS_RELEASE      "-g -O2")
60 set(CMAKE_C_FLAGS_CCOV         "-g -O2 --coverage")
61
62 ###########################################################################
63
64 INCLUDE(FindThreads)
65 FIND_PACKAGE(Threads)
66
67 PKG_CHECK_MODULES(json-c REQUIRED json-c)
68
69 CHECK_INCLUDE_FILES(magic.h HAVE_MAGIC_H)
70 CHECK_LIBRARY_EXISTS(magic magic_load "" HAVE_LIBMAGIC_SO)
71 IF(HAVE_MAGIC_H)
72   IF(HAVE_LIBMAGIC_SO)
73     SET(HAVE_LIBMAGIC "1")
74     SET(LIBMAGIC_LDFLAGS -lmagic)
75   ENDIF(HAVE_LIBMAGIC_SO)
76 ENDIF(HAVE_MAGIC_H)
77
78 PKG_CHECK_MODULES(libsystemd libsystemd>=222)
79 PKG_CHECK_MODULES(libmicrohttpd libmicrohttpd>=0.9.55)
80 PKG_CHECK_MODULES(openssl openssl)
81 PKG_CHECK_MODULES(uuid uuid)
82 PKG_CHECK_MODULES(cynara cynara-client)
83
84 IF(AGL_DEVEL)
85         ADD_DEFINITIONS(-DAGL_DEVEL)
86 endif()
87
88 IF(cynara_FOUND)
89         ADD_DEFINITIONS(-DBACKEND_PERMISSION_IS_CYNARA)
90 ENDIF(cynara_FOUND)
91
92 IF(HAVE_LIBMAGIC AND libsystemd_FOUND AND libmicrohttpd_FOUND AND openssl_FOUND AND uuid_FOUND)
93   ADD_DEFINITIONS(-DUSE_MAGIC_MIME_TYPE)
94 ELSE()
95   IF(NOT HAVE_LIBMAGIC)
96     MESSAGE(WARNING "\"magic.h\" or \"libmagic.so\" missing.
97     Please install the \"file-devel\" or \"libmagic-dev\" package !")
98   ENDIF(NOT HAVE_LIBMAGIC)
99   IF(NOT libsystemd_FOUND)
100     MESSAGE(WARNING "Dependency to 'libsystemd' is missing")
101   ENDIF()
102   IF(NOT libmicrohttpd_FOUND)
103     MESSAGE(WARNING "Dependency to 'libmicrohttpd' is missing")
104   ENDIF()
105   IF(NOT openssl_FOUND)
106     MESSAGE(WARNING "Dependency to 'openssl' is missing")
107   ENDIF()
108   IF(NOT uuid_FOUND)
109     MESSAGE(WARNING "Dependency to 'uuid' is missing")
110   ENDIF()
111   IF(NOT ONLY_DEVTOOLS)
112     MESSAGE(FATAL_ERROR "Can't compile the binder, either define ONLY_DEVTOOLS or install dependencies")
113   ENDIF()
114 ENDIF()
115
116 ADD_DEFINITIONS(-DAFB_VERSION="${PROJECT_VERSION}")
117
118 INCLUDE_DIRECTORIES(
119         ${INCLUDE_DIRS}
120         ${CMAKE_SOURCE_DIR}/include
121         ${json-c_INCLUDE_DIRS}
122         ${libsystemd_INCLUDE_DIRS}
123         ${libmicrohttpd_INCLUDE_DIRS}
124         ${uuid_INCLUDE_DIRS}
125         ${openssl_INCLUDE_DIRS}
126         ${cynara_INCLUDE_DIRS}
127 )
128
129 SET(link_libraries
130         ${CMAKE_THREAD_LIBS_INIT}
131         ${json-c_LDFLAGS}
132         ${libsystemd_LDFLAGS}
133         ${libmicrohttpd_LDFLAGS}
134         ${uuid_LDFLAGS}
135         ${openssl_LDFLAGS}
136         ${cynara_LDFLAGS}
137         ${LIBMAGIC_LDFLAGS}
138         -ldl
139         -lrt
140         )
141
142 ADD_SUBDIRECTORY(src/devtools)
143
144 IF(ONLY_DEVTOOLS)
145         MESSAGE(WARNING "Only DEVTOOLS are compiled, not the binder!")
146 ELSE()
147         SET(binding_install_dir ${CMAKE_INSTALL_FULL_LIBDIR}/afb)
148
149         ###########################################################################
150         # activates the monitoring by default
151         if(INCLUDE_MONITORING AND NOT ONLY_DEVTOOLS)
152                 add_definitions(-DWITH_MONITORING_OPTION)
153                 INSTALL(DIRECTORY
154                         ${CMAKE_CURRENT_SOURCE_DIR}/test/monitoring
155                         DESTINATION
156                         ${binding_install_dir}
157                 )
158         endif()
159
160         ###########################################################################
161
162         ADD_SUBDIRECTORY(src)
163         ADD_SUBDIRECTORY(src/tests)
164         ADD_SUBDIRECTORY(include)
165         ADD_SUBDIRECTORY(bindings)
166
167         ############################################################
168         # installs the pkgconfig files
169         CONFIGURE_FILE(afb-daemon.pc.in afb-daemon.pc @ONLY)
170         CONFIGURE_FILE(libafbwsc.pc.in libafbwsc.pc @ONLY)
171
172         INSTALL(FILES
173             ${CMAKE_CURRENT_BINARY_DIR}/afb-daemon.pc
174             ${CMAKE_CURRENT_BINARY_DIR}/libafbwsc.pc
175             DESTINATION
176             ${CMAKE_INSTALL_LIBDIR}/pkgconfig
177         )
178
179 ENDIF()