doc: add new document quick-tutorial
[src/app-framework-main.git] / src / CMakeLists.txt
1 ###########################################################################
2 # Copyright 2015 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 2.8)
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 libsystemd)
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)
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(USE_SIMULATION)
62         include_directories(simulation)
63 else(USE_SIMULATION)
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 endif(USE_SIMULATION)
69
70 ###########################################################################
71
72 add_library(wgtpkg STATIC
73         wgtpkg-base64.c
74         wgtpkg-certs.c
75         wgtpkg-digsig.c
76         wgtpkg-files.c
77         wgtpkg-install.c
78         wgtpkg-permissions.c
79         wgtpkg-uninstall.c
80         wgtpkg-workdir.c
81         wgtpkg-xmlsec.c
82         wgtpkg-zip.c
83         )
84
85 add_library(utils STATIC
86         utils-dir.c
87         utils-jbus.c
88         utils-json.c
89         verbose.c
90         )
91
92 add_library(wgt STATIC
93         wgt-config.c
94         wgt-info.c
95         wgt.c
96         )
97
98 add_library(secwrp STATIC
99         secmgr-wrap.c
100         )
101
102 add_library(afm STATIC
103         afm-db.c
104         afm-launch.c
105         afm-launch-mode.c
106         afm-run.c
107         )
108
109 ###########################################################################
110 # packaging tools
111
112 MESSAGE(STATUS "Creating packaging tools")
113
114 add_executable(wgtpkg-sign wgtpkg-sign.c)
115 target_link_libraries(wgtpkg-sign wgtpkg utils)
116
117 add_executable(wgtpkg-pack wgtpkg-pack.c)
118 target_link_libraries(wgtpkg-pack wgtpkg utils)
119
120 add_executable(wgtpkg-info wgtpkg-info.c)
121 target_link_libraries(wgtpkg-info wgtpkg wgt utils)
122
123 add_executable(wgtpkg-installer wgtpkg-installer.c)
124 target_link_libraries(wgtpkg-installer wgtpkg wgt secwrp utils)
125
126 install(TARGETS wgtpkg-sign wgtpkg-pack wgtpkg-info wgtpkg-installer DESTINATION ${CMAKE_INSTALL_BINDIR})
127
128 ###########################################################################
129 # the daemons
130
131 MESSAGE(STATUS "Creating daemons")
132
133 add_executable(afm-user-daemon afm-user-daemon.c)
134 target_link_libraries(afm-user-daemon afm secwrp wgt utils )
135 install(TARGETS afm-user-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})
136
137 add_executable(afm-system-daemon afm-system-daemon.c)
138 target_link_libraries(afm-system-daemon wgtpkg afm secwrp wgt utils)
139 install(TARGETS afm-system-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})
140
141 ###########################################################################
142 # the plugin for afb
143
144 pkg_check_modules(afb afb-daemon)
145 if(afb_FOUND)
146         message(STATUS "Creation afm-main-plugin for AFB-DAEMON")
147         ###############################################################
148         #pkg_get_variable(afb_plugin_install_dir afb-daemon plugin_install_dir)
149         execute_process(
150                 COMMAND pkg-config --variable plugin_install_dir afb-daemon
151                 OUTPUT_VARIABLE afb_plugin_install_dir OUTPUT_STRIP_TRAILING_WHITESPACE
152         )
153         ###############################################################
154         add_library(afm-main-plugin MODULE afm-main-plugin.c)
155         target_compile_options(afm-main-plugin PRIVATE ${afb_CFLAGS})
156         target_include_directories(afm-main-plugin PRIVATE ${afb_INCLUDE_DIRS})
157         target_link_libraries(afm-main-plugin utils ${afb_LIBRARIES})
158         set_target_properties(afm-main-plugin PROPERTIES
159                 PREFIX ""
160                 LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/afm-main-plugin.export-map"
161         )
162         install(TARGETS afm-main-plugin LIBRARY DESTINATION ${afb_plugin_install_dir})
163 else()
164         message(STATUS "Not creating the plugin for AFB-DAEMON")
165 endif()
166