1 # ------------------------------------------------------------
2 # CMakeLists.txt the AIT OpenSecurity ShadowFUSE
4 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
6 # Copyright (C) 2013 AIT Austrian Institute of Technology
7 # AIT Austrian Institute of Technology GmbH
8 # Donau-City-Strasse 1 | 1220 Vienna | Austria
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # version 2 as published by the Free Software Foundation.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with this library; if not, write to the
22 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 # Boston, MA 02110-1301, USA.
24 # ------------------------------------------------------------
27 project(os-server C CXX)
28 cmake_minimum_required(VERSION 2.6)
30 # load necessary basic cmake modules
31 include(CheckIncludeFile)
32 include(CheckIncludeFiles)
33 include(CheckLibraryExists)
34 include(FindPkgConfig)
35 include(FindPythonInterp)
41 # ------------------------------------------------------------
42 # set global compiler flags
45 add_definitions(-DVERSION=\"${VERSION}\")
47 # we relay on a GNU/BSD SOURCE
48 add_definitions(-D_GNU_SOURCE)
49 add_definitions(-D_BSD_SOURCE)
52 if (CMAKE_COMPILER_IS_GNUCC)
54 # tweak capabilities of gcc versions prior to 4.8
55 if (${CMAKE_C_COMPILER_VERSION} LESS 4.8)
57 message(STATUS "gcc compiler < 4.8 detected - tweaking flags")
59 # make this clear: we use std::thread
60 # so enforce pthread bindings
61 # this may not be needed for gcc >= 4.8
62 add_definitions(-pthread)
64 # this is needed to have
65 # std::_this_thread::sleep(...)
66 # at hand - at least for gcc 4.6.3 and glibc 2.15
67 add_definitions(-D_GLIBCXX_USE_NANOSLEEP)
69 # this is needed to have
70 # std::_this_thread::yield()
71 # at hand - at least for gcc 4.6.3 and glibc 2.15
72 add_definitions(-D_GLIBCXX_USE_SCHED_YIELD)
74 endif (${CMAKE_C_COMPILER_VERSION} LESS 4.8)
76 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Werror -Wall -Wextra -pedantic -g -ggdb3 -rdynamic")
77 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x -Werror -Wall -Wextra -pedantic -g -ggdb3 -rdynamic")
79 # TODO: make speed tests with -fno-builtin especially to
80 # get a better memcpy performance
81 #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin")
82 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin")
84 endif (CMAKE_COMPILER_IS_GNUCC)
86 # additional debug and profiling options
87 option(DEBUG_MODE_ENABLED "enable debug mode" off)
88 if (CMAKE_COMPILER_IS_GNUCC)
89 if (DEBUG_MODE_ENABLED)
90 message(STATUS "debug and profiling mode enabled")
91 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -pg --coverage")
92 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -pg --coverage")
93 else(DEBUG_MODE_ENABLED)
94 message(STATUS "debug and profiling mode disabled: go for optimizations")
95 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
96 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
97 endif(DEBUG_MODE_ENABLED)
98 endif (CMAKE_COMPILER_IS_GNUCC)
101 # ------------------------------------------------------------
102 # check for an existing python module (maybe extra)
104 macro(CHECK_PYTHON_MODULE VARIABLE MODULE)
106 message(STATUS "Looking for python module ${MODULE}")
108 if (PYTHONINTERP_FOUND)
111 COMMAND ${PYTHON_EXECUTABLE} -c "import ${MODULE}"
112 RESULT_VARIABLE _result
117 if ("${_result}" EQUAL "0")
118 set (${VARIABLE}_FOUND TRUE)
119 endif ("${_result}" EQUAL "0")
121 endif (PYTHONINTERP_FOUND)
123 if (${VARIABLE}_FOUND)
124 message(STATUS "Looking for python module ${MODULE} - found")
125 else (${VARIABLE}_FOUND)
126 message(STATUS "Looking for python module ${MODULE} - not found")
127 endif (${VARIABLE}_FOUND)
129 endmacro(CHECK_PYTHON_MODULE MODULE)
132 # ------------------------------------------------------------
133 # check libs and packages (headers + lib)
136 check_include_file(stdio.h HAVE_STDIO_H)
137 check_include_file(stddef.h HAVE_STDDEF_H)
138 check_include_file(stdlib.h HAVE_STDLIB_H)
139 check_include_file(inttypes.h HAVE_INTTYPES_H)
140 check_include_file(memory.h HAVE_MEMORY_H)
141 check_include_file(string.h HAVE_STRING_H)
142 check_include_file(unistd.h HAVE_UNISTD_H)
145 check_include_file(sys/time.h HAVE_SYS_TIME_H)
146 check_include_file(time.h HAVE_TIME_H)
149 check_include_file(fcntl.h HAVE_FCNTL_H)
150 check_include_file(sys/stat.h HAVE_SYS_STAT_H)
153 check_include_file(math.h HAVE_MATH_H)
156 check_include_file(stdbool.h HAVE_STDBOOL_H)
159 check_include_file(endian.h HAVE_ENDIAN_H)
162 check_include_file(math.h HAVE_MATH_H)
165 check_include_file(netdb.h HAVE_NETDB_H)
166 check_include_file(ifaddrs.h HAVE_IFADDRS_H)
167 check_include_file(netinet/in.h HAVE_NETINET_IN_H)
168 check_include_file(arpa/inet.h HAVE_ARPA_INET_H)
169 check_include_file(sys/socket.h HAVE_SYS_SOCKET_H)
170 check_include_file(sys/un.h HAVE_SYS_UN_H)
173 check_include_file(assert.h HAVE_ASSERT_H)
176 check_include_file(signal.h HAVE_SIGNAL_H)
179 check_include_file(sys/uio.h HAVE_SYS_UIO_H)
182 check_include_file(syslog.h HAVE_SYSLOG_H)
185 check_include_file(errno.h HAVE_ERRNO_H)
188 check_include_file(limits.h HAVE_LIMITS_H)
191 check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
194 check_include_file(dirent.h HAVE_DIRENT_H)
197 pkg_check_modules(FUSE REQUIRED fuse)
200 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FUSE_CFLAGS_OTHER}")
201 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FUSE_CFLAGS_OTHER}")
202 set(CMAKE_REQUIRED_LIBRARIES "${FUSE_LIBRARIES};${CMAKE_REQUIRED_LIBRARIES}")
205 # check python module dbus
206 check_python_module(PYTHON_DBUS dbus)
207 if (NOT PYTHON_DBUS_FOUND)
208 message(FATAL_ERROR "python module 'dbus' missing.")
209 endif (NOT PYTHON_DBUS_FOUND)
211 # check python module fuse
212 check_python_module(PYTHON_FUSE fuse)
213 if (NOT PYTHON_FUSE_FOUND)
214 message(FATAL_ERROR "python module 'fuse' missing. please install 'fuse-python'.")
215 endif (NOT PYTHON_FUSE_FOUND)
217 # check python module web
218 check_python_module(PYTHON_WEB web)
219 if (NOT PYTHON_WEB_FOUND)
220 message(FATAL_ERROR "python module 'web' missing. please install 'web.py'.")
221 endif (NOT PYTHON_WEB_FOUND)
224 # ------------------------------------------------------------
225 # dump the config file
227 # create the config.h and baseinc.h
228 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
229 include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
232 # ------------------------------------------------------------
233 # go through the subs
235 add_subdirectory(bin)
238 # ------------------------------------------------------------
239 # additional stuff for installation
241 install(DIRECTORY etc/dbus-1 DESTINATION /etc)
244 # ------------------------------------------------------------
247 set(CPACK_PACKAGE_NAME "opensecurity")
249 set(CPACK_PACKAGE_DESCRIPTION "OpenSecurity System")
250 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "This is the OpenSecurity System suite to be insalled into a Security VM")
251 set(CPACK_PACKAGE_CONTACT "Oliver Maurhart <oliver.maurhart@ait.ac.at>")
252 set(CPACK_PACKAGE_VENDOR "AIT")
253 set(CPACK_PACKAGE_VERSION_MAJOR "0")
254 set(CPACK_PACKAGE_VERSION_MINOR "1")
255 set(CPACK_PACKAGE_VERSION_PATCH "0")
256 set(CPACK_PROJECT_VERSION_STRING "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}" )
258 set(CPACK_GENERATOR "DEB;RPM;")
259 set(CPACK_SOURCE_GENERATOR "TGZ")
261 set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}-${CMAKE_SYSTEM_PROCESSOR}")
262 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
263 set(CPACK_SOURCE_IGNORE_FILES "/build/*;/.git/")
265 set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.13), libgcc1 (>= 1:4.4), python (>= 2.7)")
266 set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cpack/deb/control/postinst;${CMAKE_CURRENT_SOURCE_DIR}/cmake/cpack/deb/control/postrm;${CMAKE_CURRENT_SOURCE_DIR}/cmake/cpack/deb/control/prerm;")
269 string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_PACKAGE_NAME_LOWERCASE)
270 find_program(DPKG_PROGRAM dpkg DOC "dpkg program of Debian-based systems")
272 # use dpkg to fix the package file name
274 COMMAND ${DPKG_PROGRAM} --print-architecture
275 OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
276 OUTPUT_STRIP_TRAILING_WHITESPACE
278 set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME_LOWERCASE}_${CPACK_PROJECT_VERSION_STRING}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
280 set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME_LOWERCASE}_${CPACK_PROJECT_VERSION_STRING}_${CMAKE_SYSTEM_NAME}")