aboutsummaryrefslogtreecommitdiffstats
path: root/src/CMakeLists.txt
blob: 0f070595d4e373e6e31e0d8f740b72497623efaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
###########################################################################
# Copyright 2015 IoT.bzh
#
# author: José Bollo <jose.bollo@iot.bzh>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###########################################################################

cmake_minimum_required(VERSION 2.8)

###########################################################################

link_libraries(-Wl,--as-needed -Wl,--gc-sections)

add_compile_options(-Wall -Wextra -Wconversion)
add_compile_options(-Wno-unused-parameter) # frankly not using a parameter does it care?
add_compile_options(-Werror=maybe-uninitialized)
add_compile_options(-Werror=implicit-function-declaration)
add_compile_options(-Wno-pointer-sign) # for XmlChar handling
add_compile_options(-ffunction-sections -fdata-sections)
add_compile_options(-Wl,--as-needed -Wl,--gc-sections)
add_compile_options(-fPIC)
#add_definitions(-DNDEBUG)

set(CMAKE_C_FLAGS_PROFILING    "-g -O0 -pg -Wp,-U_FORTIFY_SOURCE")
set(CMAKE_C_FLAGS_DEBUG        "-g -O0 -ggdb -Wp,-U_FORTIFY_SOURCE")
set(CMAKE_C_FLAGS_RELEASE      "-g -O2")
set(CMAKE_C_FLAGS_CCOV         "-g -O2 --coverage")

###########################################################################

include(FindPkgConfig)

pkg_check_modules(EXTRAS REQUIRED libxml-2.0 openssl xmlsec1 xmlsec1-openssl json-c libsystemd)
add_compile_options(${EXTRAS_CFLAGS})
include_directories(${EXTRAS_INCLUDE_DIRS})
link_libraries(${EXTRAS_LIBRARIES})

pkg_check_modules(libzip libzip>=0.11)
if(libzip_FOUND)
	add_compile_options(${libzip_CFLAGS})
	include_directories(${libzip_INCLUDE_DIRS})
	link_libraries(${libzip_LIBRARIES})
	add_definitions(-DUSE_LIBZIP=1)
else()
	add_definitions(-DUSE_LIBZIP=0)
endif()

###########################################################################

if(USE_SIMULATION)
	include_directories(simulation)
else(USE_SIMULATION)
	pkg_check_modules(SECMGR REQUIRED security-manager)
	add_compile_options(${SECMGR_CFLAGS})
	include_directories(${SECMGR_INCLUDE_DIRS})
	link_libraries(${SECMGR_LIBRARIES})
endif(USE_SIMULATION)

###########################################################################

add_library(wgtpkg STATIC
	wgtpkg-base64.c
	wgtpkg-certs.c
	wgtpkg-digsig.c
	wgtpkg-files.c
	wgtpkg-install.c
	wgtpkg-permissions.c
	wgtpkg-uninstall.c
	wgtpkg-workdir.c
	wgtpkg-xmlsec.c
	wgtpkg-zip.c
	)

add_library(utils STATIC
	utils-dir.c
	utils-jbus.c
	utils-json.c
	verbose.c
	)

add_library(wgt STATIC
	wgt-config.c
	wgt-info.c
	wgt.c
	)

add_library(secwrp STATIC
	secmgr-wrap.c
	)

add_library(afm STATIC
	afm-db.c
	afm-launch.c
	afm-launch-mode.c
	afm-run.c
	)

###########################################################################
# packaging tools

MESSAGE(STATUS "Creating packaging tools")

add_executable(wgtpkg-sign wgtpkg-sign.c)
target_link_libraries(wgtpkg-sign wgtpkg utils)

add_executable(wgtpkg-pack wgtpkg-pack.c)
target_link_libraries(wgtpkg-pack wgtpkg utils)

add_executable(wgtpkg-info wgtpkg-info.c)
target_link_libraries(wgtpkg-info wgtpkg wgt utils)

add_executable(wgtpkg-installer wgtpkg-installer.c)
target_link_libraries(wgtpkg-installer wgtpkg wgt secwrp utils)

install(TARGETS wgtpkg-sign wgtpkg-pack wgtpkg-info wgtpkg-installer DESTINATION ${CMAKE_INSTALL_BINDIR})

###########################################################################
# the daemons

MESSAGE(STATUS "Creating daemons")

add_executable(afm-user-daemon afm-user-daemon.c)
target_link_libraries(afm-user-daemon afm secwrp wgt utils )
install(TARGETS afm-user-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})

add_executable(afm-system-daemon afm-system-daemon.c)
target_link_libraries(afm-system-daemon wgtpkg afm secwrp wgt utils)
install(TARGETS afm-system-daemon DESTINATION ${CMAKE_INSTALL_BINDIR})

###########################################################################
# the binding for afb

pkg_check_modules(afb afb-daemon)
if(afb_FOUND)
	message(STATUS "Creation afm-main-binding for AFB-DAEMON")
	###############################################################
	#pkg_get_variable(afb_binding_install_dir afb-daemon binding_install_dir)
	execute_process(
		COMMAND pkg-config --variable binding_install_dir afb-daemon
		OUTPUT_VARIABLE afb_binding_install_dir OUTPUT_STRIP_TRAILING_WHITESPACE
	)
	###############################################################
	add_library(afm-main-binding MODULE afm-main-binding.c)
	target_compile_options(afm-main-binding PRIVATE ${afb_CFLAGS})
	target_include_directories(afm-main-binding PRIVATE ${afb_INCLUDE_DIRS})
	target_link_libraries(afm-main-binding utils ${afb_LIBRARIES})
	set_target_properties(afm-main-binding PROPERTIES
		PREFIX ""
		LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/afm-main-binding.export-map"
	)
	install(TARGETS afm-main-binding LIBRARY DESTINATION ${afb_binding_install_dir})
else()
	message(STATUS "Not creating the binding for AFB-DAEMON")
endif()