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