Remove afm-system-daemon
[src/app-framework-main.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 cmake_minimum_required(VERSION 3.4.3)
20
21 ###########################################################################
22
23 link_libraries(-Wl,--as-needed -Wl,--gc-sections)
24
25 add_compile_options(-Wall -Wextra -Wconversion)
26 add_compile_options(-Wno-unused-parameter) # frankly not using a parameter does it care?
27 add_compile_options(-Werror=maybe-uninitialized)
28 add_compile_options(-Werror=implicit-function-declaration)
29 add_compile_options(-Wno-pointer-sign) # for XmlChar handling
30 add_compile_options(-ffunction-sections -fdata-sections)
31 add_compile_options(-Wl,--as-needed -Wl,--gc-sections)
32 add_compile_options(-fPIC)
33 #add_definitions(-DNDEBUG)
34
35 set(CMAKE_C_FLAGS_PROFILING    "-g -O0 -pg -Wp,-U_FORTIFY_SOURCE")
36 set(CMAKE_C_FLAGS_DEBUG        "-g -O0 -ggdb -Wp,-U_FORTIFY_SOURCE")
37 set(CMAKE_C_FLAGS_RELEASE      "-g -O2")
38 set(CMAKE_C_FLAGS_CCOV         "-g -O2 --coverage")
39
40 ###########################################################################
41
42 include(FindPkgConfig)
43
44 pkg_check_modules(EXTRAS REQUIRED libxml-2.0 openssl xmlsec1 xmlsec1-openssl json-c)
45 add_compile_options(${EXTRAS_CFLAGS})
46 include_directories(${EXTRAS_INCLUDE_DIRS})
47 link_libraries(${EXTRAS_LIBRARIES})
48
49 pkg_check_modules(libzip libzip>=0.11)
50 if(libzip_FOUND AND USE_LIBZIP)
51         add_compile_options(${libzip_CFLAGS})
52         include_directories(${libzip_INCLUDE_DIRS})
53         link_libraries(${libzip_LIBRARIES})
54         add_definitions(-DUSE_LIBZIP=1)
55 else()
56         add_definitions(-DUSE_LIBZIP=0)
57 endif()
58
59 pkg_check_modules(libsystemd libsystemd>=222)
60 if(NOT libsystemd_FOUND)
61         add_definitions(-DNO_LIBSYSTEMD)
62 endif()
63
64 pkg_check_modules(AFB afb-daemon>=4.99 libafbwsc>=4.99)
65
66 ###########################################################################
67
68 if(SIMULATE_SECMGR)
69         add_definitions(-DSIMULATE_SECURITY_MANAGER=1)
70 else(SIMULATE_SECMGR)
71         pkg_check_modules(SECMGR REQUIRED security-manager)
72         add_compile_options(${SECMGR_CFLAGS})
73         include_directories(${SECMGR_INCLUDE_DIRS})
74         link_libraries(${SECMGR_LIBRARIES})
75         add_definitions(-DSIMULATE_SECURITY_MANAGER=0)
76 endif(SIMULATE_SECMGR)
77
78 if(SIMULATE_SMACK)
79         add_definitions(-DSIMULATE_LIBSMACK=1)
80 else(SIMULATE_SMACK)
81         pkg_check_modules(SMACK REQUIRED libsmack)
82         add_compile_options(${SMACK_CFLAGS})
83         include_directories(${SMACK_INCLUDE_DIRS})
84         link_libraries(${SMACK_LIBRARIES})
85         add_definitions(-DSIMULATE_LIBSMACK=0)
86 endif(SIMULATE_SMACK)
87
88 ###########################################################################
89
90 add_library(wgtpkg STATIC
91         wgtpkg-base64.c
92         wgtpkg-certs.c
93         wgtpkg-digsig.c
94         wgtpkg-files.c
95         wgtpkg-install.c
96         wgtpkg-mustach.c
97         wgtpkg-permissions.c
98         wgtpkg-uninstall.c
99         wgtpkg-unit.c
100         wgtpkg-workdir.c
101         wgtpkg-xmlsec.c
102         wgtpkg-zip.c
103         )
104
105 add_library(utils STATIC
106         mustach.c
107         utils-dir.c
108         utils-file.c
109         utils-json.c
110         utils-systemd.c
111         verbose.c
112         )
113
114 add_library(wgt STATIC
115         wgt-config.c
116         wgt-info.c
117         wgt-strings.c
118         wgt-json.c
119         wgt.c
120         )
121
122 add_library(secwrp STATIC
123         secmgr-wrap.c
124         )
125
126 add_library(afm STATIC
127         afm-udb.c
128         afm-urun.c
129         )
130
131 ###########################################################################
132 # off line tools tools
133
134 MESSAGE(STATUS "Creating packaging tools")
135
136 add_executable(wgtpkg-sign wgtpkg-sign.c)
137 target_link_libraries(wgtpkg-sign wgtpkg utils)
138
139 add_executable(wgtpkg-pack wgtpkg-pack.c)
140 target_link_libraries(wgtpkg-pack wgtpkg utils)
141
142 add_executable(wgtpkg-info wgtpkg-info.c)
143 target_link_libraries(wgtpkg-info wgtpkg wgt utils)
144
145 add_executable(wgtpkg-installer wgtpkg-installer.c)
146 target_link_libraries(wgtpkg-installer wgtpkg wgt secwrp utils)
147
148 install(TARGETS wgtpkg-sign wgtpkg-pack wgtpkg-info wgtpkg-installer DESTINATION ${CMAKE_INSTALL_BINDIR})
149
150 ###########################################################################
151 # dynamic tool daemons
152
153 if(libsystemd_FOUND AND AFB_FOUND)
154         MESSAGE(STATUS "Creating daemons")
155
156         add_compile_options(${libsystemd_CFLAGS} ${AFB_CFLAGS})
157         include_directories(${libsystemd_INCLUDE_DIRS} ${AFB_INCLUDE_DIRS})
158         link_libraries(${libsystemd_LIBRARIES} ${AFB_LIBRARIES})
159
160         add_library(jbus STATIC utils-jbus.c)
161
162         add_executable(afm-user-daemon afm-user-daemon.c)
163         target_link_libraries(afm-user-daemon jbus utils afbwsc)
164         install(TARGETS afm-user-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})
165
166         add_library(afm-binding MODULE afm-binding.c)
167         target_link_libraries(afm-binding wgtpkg wgt secwrp utils afm)
168         set_target_properties(afm-binding PROPERTIES
169                 PREFIX ""
170                 LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/afm-binding.export-map"
171         )
172         install(TARGETS afm-binding LIBRARY DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/afm)
173 else()
174         MESSAGE(STATUS "Not creating daemons")
175 endif()
176
177 ###########################################################################
178 # the tests
179
180 add_subdirectory(tests)
181