0fde5699600fd1ac849c254df4e121527d78a36e
[src/app-framework-main.git] / src / CMakeLists.txt
1 ###########################################################################
2 # Copyright (C) 2015-2020 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 link_directories(${EXTRAS_LIBRARY_DIRS})
49
50 pkg_check_modules(libzip libzip>=0.11)
51 if(libzip_FOUND AND USE_LIBZIP)
52         add_compile_options(${libzip_CFLAGS})
53         include_directories(${libzip_INCLUDE_DIRS})
54         link_libraries(${libzip_LIBRARIES})
55         link_directories(${libzip_LIBRARY_DIRS})
56         add_definitions(-DUSE_LIBZIP=1)
57 else()
58         add_definitions(-DUSE_LIBZIP=0)
59 endif()
60
61 pkg_check_modules(libsystemd libsystemd>=222)
62 if(libsystemd_FOUND)
63         add_compile_options(${libsystemd_CFLAGS})
64         include_directories(${libsystemd_INCLUDE_DIRS})
65         link_libraries(${libsystemd_LIBRARIES})
66         link_directories(${libsystemd_LIBRARY_DIRS})
67 else()
68         add_definitions(-DNO_LIBSYSTEMD)
69 endif()
70
71 pkg_check_modules(AFB afb-daemon>=4.99 libafbwsc>=4.99)
72 if(AFB_FOUND)
73         add_compile_options(${AFB_CFLAGS})
74         include_directories(${AFB_INCLUDE_DIRS})
75         link_libraries(${AFB_LIBRARIES})
76         link_directories(${AFB_LIBRARY_DIRS})
77 endif()
78
79 ###########################################################################
80
81 if(SIMULATE_SECMGR)
82         add_definitions(-DSIMULATE_SECURITY_MANAGER=1)
83 else(SIMULATE_SECMGR)
84         pkg_check_modules(SECMGR REQUIRED security-manager)
85         add_compile_options(${SECMGR_CFLAGS})
86         include_directories(${SECMGR_INCLUDE_DIRS})
87         link_libraries(${SECMGR_LIBRARIES})
88         link_directories(${SECMGR_LIBRARY_DIRS})
89         add_definitions(-DSIMULATE_SECURITY_MANAGER=0)
90 endif(SIMULATE_SECMGR)
91
92 if(SIMULATE_SMACK)
93         add_definitions(-DSIMULATE_LIBSMACK=1)
94 else(SIMULATE_SMACK)
95         pkg_check_modules(SMACK REQUIRED libsmack)
96         add_compile_options(${SMACK_CFLAGS})
97         include_directories(${SMACK_INCLUDE_DIRS})
98         link_libraries(${SMACK_LIBRARIES})
99         link_directories(${SMACK_LIBRARY_DIRS})
100         add_definitions(-DSIMULATE_LIBSMACK=0)
101 endif(SIMULATE_SMACK)
102
103 ###########################################################################
104
105 add_library(wgtpkg STATIC
106         wgtpkg-base64.c
107         wgtpkg-certs.c
108         wgtpkg-digsig.c
109         wgtpkg-files.c
110         wgtpkg-install.c
111         wgtpkg-mustach.c
112         wgtpkg-permissions.c
113         wgtpkg-uninstall.c
114         wgtpkg-unit.c
115         wgtpkg-workdir.c
116         wgtpkg-xmlsec.c
117         wgtpkg-zip.c
118         )
119
120 add_library(utils STATIC
121         mustach.c
122         utils-dir.c
123         utils-file.c
124         utils-json.c
125         utils-systemd.c
126         verbose.c
127         )
128
129 add_library(wgt STATIC
130         wgt-config.c
131         wgt-info.c
132         wgt-strings.c
133         wgt-json.c
134         wgt.c
135         )
136
137 add_library(secwrp STATIC
138         secmgr-wrap.c
139         )
140
141 add_library(afm STATIC
142         afm-udb.c
143         afm-urun.c
144         )
145
146 ###########################################################################
147 # off line tools tools
148
149 MESSAGE(STATUS "Creating packaging tools")
150
151 add_executable(wgtpkg-sign wgtpkg-sign.c)
152 target_link_libraries(wgtpkg-sign wgtpkg utils)
153
154 add_executable(wgtpkg-pack wgtpkg-pack.c)
155 target_link_libraries(wgtpkg-pack wgtpkg utils)
156
157 add_executable(wgtpkg-info wgtpkg-info.c)
158 target_link_libraries(wgtpkg-info wgtpkg wgt utils)
159
160 add_executable(wgtpkg-installer wgtpkg-installer.c)
161 target_link_libraries(wgtpkg-installer wgtpkg wgt secwrp utils)
162
163 install(TARGETS wgtpkg-sign wgtpkg-pack wgtpkg-info wgtpkg-installer DESTINATION ${CMAKE_INSTALL_BINDIR})
164
165 ###########################################################################
166 # dynamic tool daemons
167
168 if(libsystemd_FOUND AND AFB_FOUND)
169         MESSAGE(STATUS "Creating daemons")
170
171         add_library(jbus STATIC utils-jbus.c)
172
173         if(LEGACY_USER_DAEMON)
174                 add_executable(afm-user-daemon afm-user-daemon.c)
175                 target_link_libraries(afm-user-daemon jbus utils)
176                 install(TARGETS afm-user-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})
177         endif()
178
179         add_library(afm-binding MODULE afm-binding.c)
180         target_link_libraries(afm-binding wgtpkg wgt secwrp utils afm)
181         set_target_properties(afm-binding PROPERTIES
182                 PREFIX ""
183                 LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/afm-binding.export-map"
184         )
185         install(TARGETS afm-binding LIBRARY DESTINATION ${afm_libexecdir})
186
187         add_executable(afm-user-session afm-user-session.c)
188         install(TARGETS afm-user-session DESTINATION ${afm_libexecdir}
189                         PERMISSIONS SETUID OWNER_READ OWNER_WRITE OWNER_EXECUTE
190                                         GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
191 else()
192         MESSAGE(STATUS "Not creating daemons")
193 endif()
194
195 ###########################################################################
196 # the tests
197
198 add_subdirectory(tests)
199