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