utils-systemd: introduction of systemd interface
[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 ###########################################################################
60
61 if(SIMULATE_SECMGR)
62         add_definitions(-DSIMULATE_SECURITY_MANAGER=1)
63 else(SIMULATE_SECMGR)
64         pkg_check_modules(SECMGR REQUIRED security-manager)
65         add_compile_options(${SECMGR_CFLAGS})
66         include_directories(${SECMGR_INCLUDE_DIRS})
67         link_libraries(${SECMGR_LIBRARIES})
68         add_definitions(-DSIMULATE_SECURITY_MANAGER=0)
69 endif(SIMULATE_SECMGR)
70
71 if(SIMULATE_SMACK)
72         add_definitions(-DSIMULATE_LIBSMACK=1)
73 else(SIMULATE_SMACK)
74         pkg_check_modules(SMACK REQUIRED libsmack)
75         add_compile_options(${SMACK_CFLAGS})
76         include_directories(${SMACK_INCLUDE_DIRS})
77         link_libraries(${SMACK_LIBRARIES})
78         add_definitions(-DSIMULATE_LIBSMACK=0)
79 endif(SIMULATE_SMACK)
80
81 ###########################################################################
82
83 add_library(wgtpkg STATIC
84         wgtpkg-base64.c
85         wgtpkg-certs.c
86         wgtpkg-digsig.c
87         wgtpkg-files.c
88         wgtpkg-install.c
89         wgtpkg-mustach.c
90         wgtpkg-permissions.c
91         wgtpkg-uninstall.c
92         wgtpkg-unit.c
93         wgtpkg-workdir.c
94         wgtpkg-xmlsec.c
95         wgtpkg-zip.c
96         )
97
98 add_library(utils STATIC
99         mustach.c
100         utils-dir.c
101         utils-file.c
102         utils-json.c
103         utils-systemd.c
104         verbose.c
105         )
106
107 add_library(wgt STATIC
108         wgt-config.c
109         wgt-info.c
110         wgt-strings.c
111         wgt-json.c
112         wgt.c
113         )
114
115 add_library(secwrp STATIC
116         secmgr-wrap.c
117         )
118
119 ###########################################################################
120 # packaging tools
121
122 MESSAGE(STATUS "Creating packaging tools")
123
124 add_executable(wgtpkg-sign wgtpkg-sign.c)
125 target_link_libraries(wgtpkg-sign wgtpkg utils)
126
127 add_executable(wgtpkg-pack wgtpkg-pack.c)
128 target_link_libraries(wgtpkg-pack wgtpkg utils)
129
130 add_executable(wgtpkg-info wgtpkg-info.c)
131 target_link_libraries(wgtpkg-info wgtpkg wgt utils)
132
133 add_executable(wgtpkg-installer wgtpkg-installer.c)
134 target_link_libraries(wgtpkg-installer wgtpkg wgt secwrp utils)
135
136 install(TARGETS wgtpkg-sign wgtpkg-pack wgtpkg-info wgtpkg-installer DESTINATION ${CMAKE_INSTALL_BINDIR})
137
138 ###########################################################################
139 # the targeted
140
141 pkg_check_modules(SYSTEMD libsystemd>=222)
142 if(SYSTEMD_FOUND)
143         add_compile_options(${SYSTEMD_CFLAGS})
144         include_directories(${SYSTEMD_INCLUDE_DIRS})
145         link_libraries(${SYSTEMD_LIBRARIES})
146
147         add_library(utils2 STATIC
148                 utils-jbus.c
149                 )
150
151         add_library(afm STATIC
152                 afm-db.c
153                 afm-launch.c
154                 afm-launch-mode.c
155                 afm-run.c
156                 )
157
158         ###########################################################################
159         # the daemons
160         MESSAGE(STATUS "Creating daemons")
161
162         add_executable(afm-user-daemon afm-user-daemon.c)
163         target_link_libraries(afm-user-daemon afm secwrp wgt utils utils2)
164         install(TARGETS afm-user-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})
165
166         add_executable(afm-system-daemon afm-system-daemon.c)
167         target_link_libraries(afm-system-daemon wgtpkg afm secwrp wgt utils utils2)
168         install(TARGETS afm-system-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})
169
170         ###########################################################################
171         # the binding for afb
172
173         pkg_check_modules(AFB afb-daemon)
174         if(AFB_FOUND)
175                 message(STATUS "Creation afm-main-binding for AFB-DAEMON")
176                 ###############################################################
177                 pkg_get_variable(afb_binding_install_dir afb-daemon binding_install_dir)
178                 ###############################################################
179                 add_library(afm-main-binding MODULE afm-main-binding.c)
180                 target_compile_options(afm-main-binding PRIVATE ${AFB_CFLAGS})
181                 target_include_directories(afm-main-binding PRIVATE ${AFB_INCLUDE_DIRS})
182                 target_link_libraries(afm-main-binding utils utils2 ${AFB_LIBRARIES})
183                 set_target_properties(afm-main-binding PROPERTIES
184                         PREFIX ""
185                         LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/afm-main-binding.export-map"
186                 )
187                 install(TARGETS afm-main-binding LIBRARY DESTINATION ${afb_binding_install_dir})
188         else()
189                 message(STATUS "Not creating the binding for AFB-DAEMON")
190         endif()
191
192 endif(SYSTEMD_FOUND)
193
194 ###########################################################################
195 # the tests
196
197 add_subdirectory(tests)
198