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