fix typo
[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 PROJECT(afb-daemon C)
20
21 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)
22 SET(CMAKE_BUILD_TYPE Debug)
23 SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
24
25 SET(PROJECT_NAME "AFB Daemon")
26 SET(PROJECT_PRETTY_NAME "Application Framework Binder Daemon")
27 SET(PROJECT_DESCRIPTION "Secured binder of API for clients of the Application framework")
28 SET(PROJECT_VERSION "1.0")
29 SET(PROJECT_URL "https://github.com/iotbzh/afb-daemon")
30
31 SET(LIBAFBWSC_VERSION "1.0")
32 SET(LIBAFBWSC_SOVERSION "1")
33
34 INCLUDE(FindPkgConfig)
35 INCLUDE(CheckIncludeFiles)
36 INCLUDE(CheckLibraryExists)
37 INCLUDE(GNUInstallDirs)
38 INCLUDE(CTest)
39
40 ###########################################################################
41
42 link_libraries(-Wl,--as-needed -Wl,--gc-sections -Wl,--no-undefined)
43
44 add_compile_options(-Wall -Wextra -Wconversion)
45 add_compile_options(-Wno-unused-parameter) # frankly not using a parameter does it care?
46 add_compile_options(-Wno-sign-compare -Wno-sign-conversion)
47 add_compile_options(-Werror=maybe-uninitialized)
48 add_compile_options(-Werror=implicit-function-declaration)
49 add_compile_options(-ffunction-sections -fdata-sections)
50 add_compile_options(-fPIC)
51 add_compile_options(-g)
52
53 set(CMAKE_C_FLAGS_PROFILING    "-g -O2 -pg -Wp,-U_FORTIFY_SOURCE")
54 set(CMAKE_C_FLAGS_DEBUG        "-g -ggdb -Wp,-U_FORTIFY_SOURCE")
55 set(CMAKE_C_FLAGS_RELEASE      "-g -O2")
56 set(CMAKE_C_FLAGS_CCOV         "-g -O2 --coverage")
57
58 ###########################################################################
59
60 INCLUDE(FindThreads)
61 FIND_PACKAGE(Threads)
62
63 PKG_CHECK_MODULES(json-c REQUIRED json-c)
64
65 CHECK_INCLUDE_FILES(magic.h HAVE_MAGIC_H)
66 CHECK_LIBRARY_EXISTS(magic magic_load "" HAVE_LIBMAGIC_SO)
67 IF(HAVE_MAGIC_H)
68   IF(HAVE_LIBMAGIC_SO)
69     SET(HAVE_LIBMAGIC "1")
70   ENDIF(HAVE_LIBMAGIC_SO)
71 ENDIF(HAVE_MAGIC_H)
72
73 IF(NOT HAVE_LIBMAGIC)
74   MESSAGE(FATAL_ERROR "\"magic.h\" or \"libmagic.so\" missing.
75     Please install the \"file-devel\" or \"libmagic-dev\" package !")
76 ENDIF(NOT HAVE_LIBMAGIC)
77 ADD_DEFINITIONS(-DUSE_MAGIC_MIME_TYPE)
78
79 PKG_CHECK_MODULES(libsystemd REQUIRED libsystemd>=222)
80 PKG_CHECK_MODULES(libmicrohttpd REQUIRED libmicrohttpd>=0.9.55)
81 PKG_CHECK_MODULES(openssl REQUIRED openssl)
82 PKG_CHECK_MODULES(uuid REQUIRED uuid)
83 PKG_CHECK_MODULES(cynara cynara-client)
84
85 IF(cynara_FOUND)
86         ADD_DEFINITIONS(-DBACKEND_PERMISSION_IS_CYNARA)
87 ENDIF(cynara_FOUND)
88
89 INCLUDE_DIRECTORIES(
90         ${INCLUDE_DIRS}
91         ${CMAKE_SOURCE_DIR}/include
92         ${json-c_INCLUDE_DIRS}
93         ${libsystemd_INCLUDE_DIRS}
94         ${libmicrohttpd_INCLUDE_DIRS}
95         ${uuid_INCLUDE_DIRS}
96         ${openssl_INCLUDE_DIRS}
97         ${cynara_INCLUDE_DIRS}
98 )
99
100 SET(link_libraries
101         ${CMAKE_THREAD_LIBS_INIT}
102         ${json-c_LDFLAGS}
103         ${libsystemd_LDFLAGS}
104         ${libmicrohttpd_LDFLAGS}
105         ${uuid_LDFLAGS}
106         ${openssl_LDFLAGS}
107         ${cynara_LDFLAGS}
108         -lmagic
109         -ldl
110         -lrt
111         )
112
113 SET(binding_install_dir ${CMAKE_INSTALL_FULL_LIBDIR}/afb)
114
115 ###########################################################################
116 # activates the monitoring by default
117 set(INCLUDE_MONITORING ON CACHE BOOL "Activates installation of monitoring")
118 if(INCLUDE_MONITORING)
119         add_definitions(-DWITH_MONITORING_OPTION)
120         INSTALL(DIRECTORY
121                 ${CMAKE_CURRENT_SOURCE_DIR}/test/monitoring
122                 DESTINATION
123                 ${binding_install_dir}
124         )
125 endif()
126
127 ###########################################################################
128
129 ADD_SUBDIRECTORY(src)
130 ADD_SUBDIRECTORY(include)
131 ADD_SUBDIRECTORY(bindings)
132
133 ############################################################
134 # installs the pkgconfig files
135 CONFIGURE_FILE(afb-daemon.pc.in afb-daemon.pc @ONLY)
136 CONFIGURE_FILE(libafbwsc.pc.in libafbwsc.pc @ONLY)
137
138 INSTALL(FILES
139     ${CMAKE_CURRENT_BINARY_DIR}/afb-daemon.pc
140     ${CMAKE_CURRENT_BINARY_DIR}/libafbwsc.pc
141     DESTINATION
142     ${CMAKE_INSTALL_LIBDIR}/pkgconfig
143     )
144