Compiles for cynara if present
[src/app-framework-binder.git] / src / 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 if (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9)
20     message(FATAL_ERROR "Require at least gcc-4.9")
21 endif(CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9)
22
23 INCLUDE(FindPkgConfig)
24
25 ADD_SUBDIRECTORY(genskel)
26 ADD_SUBDIRECTORY(tests)
27
28 ADD_DEFINITIONS(-DBINDING_INSTALL_DIR="${binding_install_dir}")
29 # Always add INFER_EXTENSION (more details in afb-hreq.c)
30 ADD_DEFINITIONS(-DINFER_EXTENSION)
31
32 CHECK_INCLUDE_FILES(magic.h HAVE_MAGIC_H)
33 CHECK_LIBRARY_EXISTS(magic magic_load "" HAVE_LIBMAGIC_SO)
34 IF(HAVE_MAGIC_H)
35   IF(HAVE_LIBMAGIC_SO)
36     SET(HAVE_LIBMAGIC "1")
37   ENDIF(HAVE_LIBMAGIC_SO)
38 ENDIF(HAVE_MAGIC_H)
39
40 IF(NOT HAVE_LIBMAGIC)
41   MESSAGE(FATAL_ERROR "\"magic.h\" or \"libmagic.so\" missing.
42     Please install the \"file-devel\" or \"libmagic-dev\" package !")
43 ENDIF(NOT HAVE_LIBMAGIC)
44 ADD_DEFINITIONS(-DUSE_MAGIC_MIME_TYPE)
45
46 PKG_CHECK_MODULES(libsystemd REQUIRED libsystemd>=222)
47 PKG_CHECK_MODULES(libmicrohttpd REQUIRED libmicrohttpd>=0.9.54)
48 PKG_CHECK_MODULES(openssl REQUIRED openssl)
49 PKG_CHECK_MODULES(uuid REQUIRED uuid)
50 PKG_CHECK_MODULES(cynara cynara-client)
51
52 IF(cynara_FOUND)
53         ADD_DEFINITIONS(-DBACKEND_PERMISSION_IS_CYNARA)
54 ENDIF(cynara_FOUND)
55
56 INCLUDE_DIRECTORIES(
57         ${include_dirs}
58         ${libsystemd_INCLUDE_DIRS}
59         ${libmicrohttpd_INCLUDE_DIRS}
60         ${uuid_INCLUDE_DIRS}
61         ${openssl_INCLUDE_DIRS}
62         ${cynara_INCLUDE_DIRS}
63 )
64
65 ADD_LIBRARY(afb-lib STATIC
66         afb-api.c
67         afb-api-dbus.c
68         afb-api-so.c
69         afb-api-so-v1.c
70         afb-api-so-v2.c
71         afb-api-ws.c
72         afb-apiset.c
73         afb-auth.c
74         afb-common.c
75         afb-config.c
76         afb-context.c
77         afb-cred.c
78         afb-ditf.c
79         afb-evt.c
80         afb-hook.c
81         afb-hreq.c
82         afb-hsrv.c
83         afb-hswitch.c
84         afb-method.c
85         afb-monitor.c
86         afb-msg-json.c
87         afb-session.c
88         afb-stub-ws.c
89         afb-subcall.c
90         afb-svc.c
91         afb-websock.c
92         afb-ws-client.c
93         afb-ws-json1.c
94         afb-ws.c
95         afb-wsj1.c
96         afb-xreq.c
97         jobs.c
98         locale-root.c
99         sd-fds.c
100         sig-monitor.c
101         verbose.c
102         websock.c
103 )
104
105 ###########################################
106 # build and install afb-daemon
107 ###########################################
108 ADD_EXECUTABLE(afb-daemon main.c)
109 TARGET_LINK_LIBRARIES(afb-daemon
110         afb-lib
111         ${link_libraries}
112         ${libsystemd_LIBRARIES}
113         ${libmicrohttpd_LIBRARIES}
114         ${uuid_LIBRARIES}
115         ${openssl_LIBRARIES}
116         ${cynara_LIBRARIES}
117         -lmagic
118         -ldl
119         -lrt
120 )
121 INSTALL(TARGETS afb-daemon
122         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
123
124 ###########################################
125 # build and install libafbwsc
126 ###########################################
127 ADD_LIBRARY(afbwsc SHARED afb-ws.c afb-ws-client.c afb-wsj1.c websock.c)
128 SET_TARGET_PROPERTIES(afbwsc PROPERTIES
129         VERSION ${LIBAFBWSC_VERSION}
130         SOVERSION ${LIBAFBWSC_SOVERSION})
131 TARGET_LINK_LIBRARIES(afbwsc
132         ${libsystemd_LIBRARIES}
133         -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/export-afbwsc.map
134         -Wl,--as-needed
135         -Wl,--gc-sections
136 )
137 INSTALL(TARGETS afbwsc LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
138 INSTALL(FILES afb-wsj1.h afb-ws-client.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/afb)
139
140 ###########################################
141 # build and install afb-client-demo
142 ###########################################
143 ADD_EXECUTABLE(afb-client-demo afb-client-demo.c)
144 TARGET_LINK_LIBRARIES(afb-client-demo
145         afbwsc
146         ${link_libraries}
147         ${libsystemd_LIBRARIES}
148 )
149 INSTALL(TARGETS afb-client-demo
150         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
151
152