forked from Pelagicore/softwarecontainer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
253 lines (204 loc) · 10.6 KB
/
CMakeLists.txt
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# Copyright (C) 2016 Pelagicore AB
#
# Permission to use, copy, modify, and/or distribute this software for
# any purpose with or without fee is hereby granted, provided that the
# above copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
# BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.
#
# For further information see LICENSE
cmake_minimum_required(VERSION 2.6)
project(softwarecontainer)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules)
set(${PROJECT_NAME}_MAJOR_VERSION 0)
set(${PROJECT_NAME}_MINOR_VERSION 9)
set(${PROJECT_NAME}_PATCH_LEVEL 1)
set(VERSION ${${PROJECT_NAME}_MAJOR_VERSION}.${${PROJECT_NAME}_MINOR_VERSION}.${${PROJECT_NAME}_PATCH_LEVEL})
if(EXTRA_PKG_CONFIG_PATH)
set(ENV{PKG_CONFIG_PATH} ${EXTRA_PKG_CONFIG_PATH})
message("Using PKG_CONFIG_PATH: " ${EXTRA_PKG_CONFIG_PATH})
endif(EXTRA_PKG_CONFIG_PATH)
add_definitions(-DPACKAGE_VERSION="${VERSION}")
find_package(PkgConfig REQUIRED)
pkg_check_modules(IVILogging REQUIRED ivi-logging)
pkg_check_modules(DBusCpp REQUIRED dbus-c++-glib-1)
pkg_check_modules(Glibmm REQUIRED glibmm-2.4)
pkg_check_modules(LXC REQUIRED lxc)
pkg_check_modules(Jansson REQUIRED jansson)
add_definitions(${IVILogging_CFLAGS_OTHER})
add_definitions(${DBusCpp_CFLAGS_OTHER})
add_definitions(${Glibmm_CFLAGS_OTHER})
add_definitions(${LXC_CFLAGS_OTHER})
add_definitions(${Jansson_CFLAGS_OTHER})
include_directories(${IVILogging_INCLUDE_DIRS})
include_directories(${DBusCpp_INCLUDE_DIRS})
include_directories(${Glibmm_INCLUDE_DIRS})
include_directories(${LXC_INCLUDE_DIRS})
include_directories(${Jansson_INCLUDE_DIRS})
link_directories(${IVILogging_LIBRARY_DIRS})
link_directories(${DBusCpp_LIBRARY_DIRS})
link_directories(${Glibmm_LIBRARY_DIRS})
link_directories(${LXC_LIBRARY_DIRS})
link_directories(${Jansson_LIBRARY_DIRS})
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system directory
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")
if(ADDITIONAL_LD_LIBRARY_PATH)
add_definitions(-DADDITIONAL_LD_LIBRARY_PATH=${ADDITIONAL_LD_LIBRARY_PATH})
endif()
if(ADDITIONAL_PATH)
add_definitions(-DADDITIONAL_PATH=${ADDITIONAL_PATH})
endif()
if(${CMAKE_INSTALL_PREFIX} STREQUAL "/usr")
SET(SYS_CONFIG_DIR /etc)
SET(LXC_TEMPLATE_DIR /var/hl/lxc-templates/)
else()
SET(SYS_CONFIG_DIR ${CMAKE_INSTALL_PREFIX}/etc)
SET(LXC_TEMPLATE_DIR ${CMAKE_INSTALL_PREFIX}/var/hl/lxc-templates)
endif()
message("Configuration files will be installed in " ${SYS_CONFIG_DIR})
message("LXC template will be installed in " ${LXC_TEMPLATE_DIR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused -Wall -std=c++11")
include_directories(
common
libsoftwarecontainer/src
libsoftwarecontainer/include
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/libsoftwarecontainer/src
)
option(ENABLE_PROFILING "Enables profiling support in the application" OFF)
if(ENABLE_PROFILING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPROFILING_ENABLED=1")
endif()
# Google Mock add (and fetch) macro
macro(add_gmock)
set(ZIPNAME release-1.8.0)
set(MOCKDIR googletest-${ZIPNAME})
if(NOT IS_DIRECTORY ${CMAKE_BINARY_DIR}/${MOCKDIR})
if(NOT EXISTS ${CMAKE_BINARY_DIR}/${ZIPNAME}.zip)
execute_process(COMMAND wget -P ${CMAKE_BINARY_DIR} https://github.com/google/googletest/archive/${ZIPNAME}.zip)
endif()
execute_process(COMMAND unzip ${CMAKE_BINARY_DIR}/${ZIPNAME}.zip -d ${CMAKE_BINARY_DIR})
endif()
if(IS_DIRECTORY ${CMAKE_BINARY_DIR}/${MOCKDIR})
add_subdirectory(${CMAKE_BINARY_DIR}/${MOCKDIR})
endif()
endmacro()
option(ENABLE_TEST "Enables unit testing" ON)
if(ENABLE_TEST)
enable_testing()
add_gmock()
configure_file(scripts/run-tests.sh run-tests.sh COPYONLY)
endif()
option(ENABLE_SYSTEMD "Enables installation of systemD unit files" ON)
# Macro for making it easy to use gcov/lcov
macro(add_coverage)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -O0")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
find_program(LCOV lcov)
find_program(GENHTML genhtml)
if(LCOV AND GENHTML)
add_custom_target(lcov)
add_custom_command(
TARGET lcov
COMMAND mkdir -p coverage
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
# Run baseline coverage file, then remove unwanted files from baseline data
add_custom_command(
TARGET lcov
# Create baseline
COMMAND ${LCOV} --capture --initial --directory . --base-directory . --output-file coverage/baseline.info
# Remove unwanted files from baseline data
COMMAND ${LCOV} --remove coverage/baseline.info \"/usr*\" --no-checksum --directory . --base-directory . --output-file coverage/baseline.info
COMMAND ${LCOV} --remove coverage/baseline.info \"gmock*\" --no-checksum --directory . --base-directory . --output-file coverage/baseline.info
COMMAND ${LCOV} --remove coverage/baseline.info \"gtest*\" --no-checksum --directory . --base-directory . --output-file coverage/baseline.info
COMMAND ${LCOV} --remove coverage/baseline.info \"unit-test*\" --no-checksum --directory . --base-directory . --output-file coverage/baseline.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
# Run the actual tests and stuff
add_custom_command(
TARGET lcov
# Run tests
COMMAND make test
# Capture coverage data after tests have run
COMMAND ${LCOV} --capture --directory . --base-directory . --output-file coverage/testrun.info
# Remove unwanted files from captured data
COMMAND ${LCOV} --remove coverage/testrun.info \"/usr*\" --no-checksum --directory . --base-directory . --output-file coverage/testrun.info
COMMAND ${LCOV} --remove coverage/testrun.info \"gmock*\" --no-checksum --directory . --base-directory . --output-file coverage/testrun.info
COMMAND ${LCOV} --remove coverage/testrun.info \"gtest*\" --no-checksum --directory . --base-directory . --output-file coverage/testrun.info
COMMAND ${LCOV} --remove coverage/testrun.info \"unit-test*\" --no-checksum --directory . --base-directory . --output-file coverage/testrun.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_custom_command(
TARGET lcov
# Combine baseline data and coverage data for accurate coverage stats
COMMAND ${LCOV} --add-tracefile coverage/baseline.info --add-tracefile coverage/testrun.info --output-file coverage/final.info
# Generate HTML report
COMMAND genhtml --no-prefix coverage/final.info --output-directory coverage/
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
else(LCOV AND GENHTML)
message(WARNING "Please install lcov and genhtml to enable the lcov target (apt-get install lcov)" )
endif(LCOV AND GENHTML)
message("Code coverage enabled")
endmacro(add_coverage)
macro(generate_dbuscpp_hfile xmlInterfaceFile h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(GENERATED_PROXY_FILENAME ${h}_dbuscpp_proxy.h)
set(GENERATED_ADAPTOR_FILENAME ${h}_dbuscpp_adaptor.h)
message("Creating DBusCpp proxy and stubs : ${GENERATED_PROXY_FILENAME} / ${GENERATED_ADAPTOR_FILENAME}")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${GENERATED_PROXY_FILENAME} ${CMAKE_CURRENT_BINARY_DIR}/${GENERATED_ADAPTOR_FILENAME}
COMMAND dbusxx-xml2cpp ${xmlInterfaceFile} --proxy=${GENERATED_PROXY_FILENAME}
COMMAND dbusxx-xml2cpp ${xmlInterfaceFile} --adaptor=${GENERATED_ADAPTOR_FILENAME}
DEPENDS ${xmlInterfaceFile}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
add_custom_target(dbus_cpp_${h} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${GENERATED_PROXY_FILENAME} ${CMAKE_CURRENT_BINARY_DIR}/${GENERATED_ADAPTOR_FILENAME})
endmacro()
if(ENABLE_COVERAGE)
add_coverage()
endif(ENABLE_COVERAGE)
install(FILES scripts/setup_softwarecontainer.sh DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
add_definitions(-DINSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}")
configure_file(softwarecontainer.pc.in softwarecontainer.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/softwarecontainer.pc DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)
set(DEVELOPMENT_INCLUDE_PATH " -I${CMAKE_CURRENT_SOURCE_DIR}/agent/lib -I${CMAKE_CURRENT_SOURCE_DIR}/clientLib -I${CMAKE_CURRENT_BINARY_DIR} -I${CMAKE_CURRENT_SOURCE_DIR}/softwarecontainer/src -I${CMAKE_CURRENT_SOURCE_DIR}/common #")
set(DEVELOPMENT_LIBRARY_PATH " -L${CMAKE_CURRENT_BINARY_DIR}/clientLib -L${CMAKE_CURRENT_BINARY_DIR}/lib #" )
configure_file(softwarecontainer.pc.in softwarecontainer-uninstalled.pc @ONLY)
if(INSTALL_PKGCONFIG_UNINSTALLED_FILE)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/softwarecontainer-uninstalled.pc DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)
endif()
configure_file(softwarecontainer-config.h.in softwarecontainer-config.h @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/softwarecontainer-config.h DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/softwarecontainer)
add_subdirectory(common)
add_subdirectory(libsoftwarecontainer)
add_subdirectory(agent)
add_subdirectory(libsoftwarecontaineragent)
option (ENABLE_EXAMPLES "Enable building and installation of examples" OFF)
if (ENABLE_EXAMPLES)
add_subdirectory(examples)
endif()
option(ENABLE_DOC "Enable building and installation of documentation" OFF)
if (ENABLE_DOC)
add_subdirectory(doc)
endif()