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