1 ###########################################################################
2 # Copyright 2015, 2016, 2017 IoT.bzh
4 # author: José Bollo <jose.bollo@iot.bzh>
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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 ###########################################################################
19 cmake_minimum_required(VERSION 3.4.3)
21 ###########################################################################
23 link_libraries(-Wl,--as-needed -Wl,--gc-sections)
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)
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")
40 ###########################################################################
42 include(FindPkgConfig)
44 pkg_check_modules(EXTRAS REQUIRED libxml-2.0 openssl xmlsec1 xmlsec1-openssl json-c libsystemd>=222)
45 add_compile_options(${EXTRAS_CFLAGS})
46 include_directories(${EXTRAS_INCLUDE_DIRS})
47 link_libraries(${EXTRAS_LIBRARIES})
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)
56 add_definitions(-DUSE_LIBZIP=0)
59 ###########################################################################
62 add_definitions(-DSIMULATE_SECURITY_MANAGER=1)
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)
72 add_definitions(-DSIMULATE_LIBSMACK=1)
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)
81 ###########################################################################
83 add_library(wgtpkg STATIC
98 add_library(utils STATIC
108 add_library(wgt STATIC
116 add_library(secwrp STATIC
120 add_library(afm STATIC
127 ###########################################################################
130 MESSAGE(STATUS "Creating packaging tools")
132 add_executable(wgtpkg-sign wgtpkg-sign.c)
133 target_link_libraries(wgtpkg-sign wgtpkg utils)
135 add_executable(wgtpkg-pack wgtpkg-pack.c)
136 target_link_libraries(wgtpkg-pack wgtpkg utils)
138 add_executable(wgtpkg-info wgtpkg-info.c)
139 target_link_libraries(wgtpkg-info wgtpkg wgt utils)
141 add_executable(wgtpkg-installer wgtpkg-installer.c)
142 target_link_libraries(wgtpkg-installer wgtpkg wgt secwrp utils)
144 install(TARGETS wgtpkg-sign wgtpkg-pack wgtpkg-info wgtpkg-installer DESTINATION ${CMAKE_INSTALL_BINDIR})
146 ###########################################################################
148 MESSAGE(STATUS "Creating daemons")
150 add_executable(afm-user-daemon afm-user-daemon.c)
151 target_link_libraries(afm-user-daemon afm secwrp wgt utils)
152 install(TARGETS afm-user-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})
154 add_executable(afm-system-daemon afm-system-daemon.c)
155 target_link_libraries(afm-system-daemon wgtpkg afm secwrp wgt utils)
156 install(TARGETS afm-system-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})
158 ###########################################################################
159 # the binding for afb
161 pkg_check_modules(AFB afb-daemon)
163 message(STATUS "Creation afm-main-binding for AFB-DAEMON")
164 ###############################################################
165 pkg_get_variable(afb_binding_install_dir afb-daemon binding_install_dir)
166 ###############################################################
167 add_library(afm-main-binding MODULE afm-main-binding.c)
168 target_compile_options(afm-main-binding PRIVATE ${AFB_CFLAGS})
169 target_include_directories(afm-main-binding PRIVATE ${AFB_INCLUDE_DIRS})
170 target_link_libraries(afm-main-binding utils ${AFB_LIBRARIES})
171 set_target_properties(afm-main-binding PROPERTIES
173 LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/afm-main-binding.export-map"
175 install(TARGETS afm-main-binding LIBRARY DESTINATION ${afb_binding_install_dir})
177 message(STATUS "Not creating the binding for AFB-DAEMON")
180 ###########################################################################
183 add_subdirectory(tests)