1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/ait/os/CMakeLists.txt Tue Nov 12 11:31:34 2013 +0100
1.3 @@ -0,0 +1,285 @@
1.4 +# ------------------------------------------------------------
1.5 +# CMakeLists.txt the AIT OpenSecurity ShadowFUSE
1.6 +#
1.7 +# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
1.8 +#
1.9 +# Copyright (C) 2013 AIT Austrian Institute of Technology
1.10 +# AIT Austrian Institute of Technology GmbH
1.11 +# Donau-City-Strasse 1 | 1220 Vienna | Austria
1.12 +# http://www.ait.ac.at
1.13 +#
1.14 +# This program is free software; you can redistribute it and/or
1.15 +# modify it under the terms of the GNU General Public License
1.16 +# version 2 as published by the Free Software Foundation.
1.17 +#
1.18 +# This program is distributed in the hope that it will be useful,
1.19 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1.20 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.21 +# GNU General Public License for more details.
1.22 +#
1.23 +# You should have received a copy of the GNU Lesser General Public
1.24 +# License along with this library; if not, write to the
1.25 +# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.26 +# Boston, MA 02110-1301, USA.
1.27 +# ------------------------------------------------------------
1.28 +
1.29 +# project data
1.30 +project(os-server C CXX)
1.31 +cmake_minimum_required(VERSION 2.6)
1.32 +
1.33 +# load necessary basic cmake modules
1.34 +include(CheckIncludeFile)
1.35 +include(CheckIncludeFiles)
1.36 +include(CheckLibraryExists)
1.37 +include(FindPkgConfig)
1.38 +include(FindPythonInterp)
1.39 +
1.40 +# enable tests
1.41 +ENABLE_TESTING()
1.42 +
1.43 +
1.44 +# ------------------------------------------------------------
1.45 +# set global compiler flags
1.46 +
1.47 +set(VERSION "0.1")
1.48 +add_definitions(-DVERSION=\"${VERSION}\")
1.49 +
1.50 +# we relay on a GNU/BSD SOURCE
1.51 +add_definitions(-D_GNU_SOURCE)
1.52 +add_definitions(-D_BSD_SOURCE)
1.53 +
1.54 +# set compile flags
1.55 +if (CMAKE_COMPILER_IS_GNUCC)
1.56 +
1.57 + # tweak capabilities of gcc versions prior to 4.8
1.58 + if (${CMAKE_C_COMPILER_VERSION} LESS 4.8)
1.59 +
1.60 + message(STATUS "gcc compiler < 4.8 detected - tweaking flags")
1.61 +
1.62 + # make this clear: we use std::thread
1.63 + # so enforce pthread bindings
1.64 + # this may not be needed for gcc >= 4.8
1.65 + add_definitions(-pthread)
1.66 +
1.67 + # this is needed to have
1.68 + # std::_this_thread::sleep(...)
1.69 + # at hand - at least for gcc 4.6.3 and glibc 2.15
1.70 + add_definitions(-D_GLIBCXX_USE_NANOSLEEP)
1.71 +
1.72 + # this is needed to have
1.73 + # std::_this_thread::yield()
1.74 + # at hand - at least for gcc 4.6.3 and glibc 2.15
1.75 + add_definitions(-D_GLIBCXX_USE_SCHED_YIELD)
1.76 +
1.77 + endif (${CMAKE_C_COMPILER_VERSION} LESS 4.8)
1.78 +
1.79 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Werror -Wall -Wextra -pedantic -g -ggdb3 -rdynamic")
1.80 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x -Werror -Wall -Wextra -pedantic -g -ggdb3 -rdynamic")
1.81 +
1.82 + # TODO: make speed tests with -fno-builtin especially to
1.83 + # get a better memcpy performance
1.84 + #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin")
1.85 + #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin")
1.86 +
1.87 +endif (CMAKE_COMPILER_IS_GNUCC)
1.88 +
1.89 +# additional debug and profiling options
1.90 +option(DEBUG_MODE_ENABLED "enable debug mode" off)
1.91 +if (CMAKE_COMPILER_IS_GNUCC)
1.92 + if (DEBUG_MODE_ENABLED)
1.93 + message(STATUS "debug and profiling mode enabled")
1.94 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -pg --coverage")
1.95 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -pg --coverage")
1.96 + else(DEBUG_MODE_ENABLED)
1.97 + message(STATUS "debug and profiling mode disabled: go for optimizations")
1.98 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
1.99 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
1.100 + endif(DEBUG_MODE_ENABLED)
1.101 +endif (CMAKE_COMPILER_IS_GNUCC)
1.102 +
1.103 +
1.104 +# ------------------------------------------------------------
1.105 +# check for an existing python module (maybe extra)
1.106 +
1.107 +macro(CHECK_PYTHON_MODULE VARIABLE MODULE)
1.108 +
1.109 + message(STATUS "Looking for python module ${MODULE}")
1.110 +
1.111 + if (PYTHONINTERP_FOUND)
1.112 +
1.113 + execute_process(
1.114 + COMMAND ${PYTHON_EXECUTABLE} -c "import ${MODULE}"
1.115 + RESULT_VARIABLE _result
1.116 + OUTPUT_QUIET
1.117 + ERROR_QUIET
1.118 + )
1.119 +
1.120 + if ("${_result}" EQUAL "0")
1.121 + set (${VARIABLE}_FOUND TRUE)
1.122 + endif ("${_result}" EQUAL "0")
1.123 +
1.124 + endif (PYTHONINTERP_FOUND)
1.125 +
1.126 + if (${VARIABLE}_FOUND)
1.127 + message(STATUS "Looking for python module ${MODULE} - found")
1.128 + else (${VARIABLE}_FOUND)
1.129 + message(STATUS "Looking for python module ${MODULE} - not found")
1.130 + endif (${VARIABLE}_FOUND)
1.131 +
1.132 +endmacro(CHECK_PYTHON_MODULE MODULE)
1.133 +
1.134 +
1.135 +# ------------------------------------------------------------
1.136 +# check libs and packages (headers + lib)
1.137 +
1.138 +# standard C files
1.139 +check_include_file(stdio.h HAVE_STDIO_H)
1.140 +check_include_file(stddef.h HAVE_STDDEF_H)
1.141 +check_include_file(stdlib.h HAVE_STDLIB_H)
1.142 +check_include_file(inttypes.h HAVE_INTTYPES_H)
1.143 +check_include_file(memory.h HAVE_MEMORY_H)
1.144 +check_include_file(string.h HAVE_STRING_H)
1.145 +check_include_file(unistd.h HAVE_UNISTD_H)
1.146 +
1.147 +# time
1.148 +check_include_file(sys/time.h HAVE_SYS_TIME_H)
1.149 +check_include_file(time.h HAVE_TIME_H)
1.150 +
1.151 +# file system stuff
1.152 +check_include_file(fcntl.h HAVE_FCNTL_H)
1.153 +check_include_file(sys/stat.h HAVE_SYS_STAT_H)
1.154 +
1.155 +# math
1.156 +check_include_file(math.h HAVE_MATH_H)
1.157 +
1.158 +# stdbool
1.159 +check_include_file(stdbool.h HAVE_STDBOOL_H)
1.160 +
1.161 +# endian
1.162 +check_include_file(endian.h HAVE_ENDIAN_H)
1.163 +
1.164 +# math.h
1.165 +check_include_file(math.h HAVE_MATH_H)
1.166 +
1.167 +# networking
1.168 +check_include_file(netdb.h HAVE_NETDB_H)
1.169 +check_include_file(ifaddrs.h HAVE_IFADDRS_H)
1.170 +check_include_file(netinet/in.h HAVE_NETINET_IN_H)
1.171 +check_include_file(arpa/inet.h HAVE_ARPA_INET_H)
1.172 +check_include_file(sys/socket.h HAVE_SYS_SOCKET_H)
1.173 +check_include_file(sys/un.h HAVE_SYS_UN_H)
1.174 +
1.175 +# assert
1.176 +check_include_file(assert.h HAVE_ASSERT_H)
1.177 +
1.178 +# signal
1.179 +check_include_file(signal.h HAVE_SIGNAL_H)
1.180 +
1.181 +# sys/uio
1.182 +check_include_file(sys/uio.h HAVE_SYS_UIO_H)
1.183 +
1.184 +# syslog
1.185 +check_include_file(syslog.h HAVE_SYSLOG_H)
1.186 +
1.187 +# errno
1.188 +check_include_file(errno.h HAVE_ERRNO_H)
1.189 +
1.190 +# limits
1.191 +check_include_file(limits.h HAVE_LIMITS_H)
1.192 +
1.193 +# sys/mman.h
1.194 +check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
1.195 +
1.196 +# dirent.h
1.197 +check_include_file(dirent.h HAVE_DIRENT_H)
1.198 +
1.199 +# fuse.h
1.200 +pkg_check_modules(FUSE REQUIRED fuse)
1.201 +if (FUSE_FOUND)
1.202 + set(HAVE_FUSE_H 1)
1.203 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FUSE_CFLAGS_OTHER}")
1.204 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FUSE_CFLAGS_OTHER}")
1.205 + set(CMAKE_REQUIRED_LIBRARIES "${FUSE_LIBRARIES};${CMAKE_REQUIRED_LIBRARIES}")
1.206 +endif (FUSE_FOUND)
1.207 +
1.208 +# check python module dbus
1.209 +check_python_module(PYTHON_DBUS dbus)
1.210 +if (NOT PYTHON_DBUS_FOUND)
1.211 + message(FATAL_ERROR "python module 'dbus' missing.")
1.212 +endif (NOT PYTHON_DBUS_FOUND)
1.213 +
1.214 +# check python module fuse
1.215 +check_python_module(PYTHON_FUSE fuse)
1.216 +if (NOT PYTHON_FUSE_FOUND)
1.217 + message(FATAL_ERROR "python module 'fuse' missing. please install 'fuse-python'.")
1.218 +endif (NOT PYTHON_FUSE_FOUND)
1.219 +
1.220 +# check python module web
1.221 +check_python_module(PYTHON_WEB web)
1.222 +if (NOT PYTHON_WEB_FOUND)
1.223 + message(FATAL_ERROR "python module 'web' missing. please install 'web.py'.")
1.224 +endif (NOT PYTHON_WEB_FOUND)
1.225 +
1.226 +
1.227 +# ------------------------------------------------------------
1.228 +# dump the config file
1.229 +
1.230 +# create the config.h and baseinc.h
1.231 +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
1.232 +include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
1.233 +
1.234 +
1.235 +# ------------------------------------------------------------
1.236 +# go through the subs
1.237 +
1.238 +add_subdirectory(bin)
1.239 +
1.240 +
1.241 +# ------------------------------------------------------------
1.242 +# additional stuff for installation
1.243 +
1.244 +install(DIRECTORY etc/dbus-1 DESTINATION /etc)
1.245 +
1.246 +
1.247 +# ------------------------------------------------------------
1.248 +# packaging
1.249 +
1.250 +set(CPACK_PACKAGE_NAME "opensecurity")
1.251 +
1.252 +set(CPACK_PACKAGE_DESCRIPTION "OpenSecurity System")
1.253 +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "This is the OpenSecurity System suite to be insalled into a Security VM")
1.254 +set(CPACK_PACKAGE_CONTACT "Oliver Maurhart <oliver.maurhart@ait.ac.at>")
1.255 +set(CPACK_PACKAGE_VENDOR "AIT")
1.256 +set(CPACK_PACKAGE_VERSION_MAJOR "0")
1.257 +set(CPACK_PACKAGE_VERSION_MINOR "1")
1.258 +set(CPACK_PACKAGE_VERSION_PATCH "0")
1.259 +set(CPACK_PROJECT_VERSION_STRING "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}" )
1.260 +
1.261 +set(CPACK_GENERATOR "DEB;RPM;")
1.262 +set(CPACK_SOURCE_GENERATOR "TGZ")
1.263 +
1.264 +set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}-${CMAKE_SYSTEM_PROCESSOR}")
1.265 +set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
1.266 +set(CPACK_SOURCE_IGNORE_FILES "/build/*;/.git/")
1.267 +
1.268 +set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.13), libgcc1 (>= 1:4.4), python (>= 2.7)")
1.269 +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;")
1.270 +
1.271 +# debianization
1.272 +string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_PACKAGE_NAME_LOWERCASE)
1.273 +find_program(DPKG_PROGRAM dpkg DOC "dpkg program of Debian-based systems")
1.274 +if (DPKG_PROGRAM)
1.275 + # use dpkg to fix the package file name
1.276 + execute_process(
1.277 + COMMAND ${DPKG_PROGRAM} --print-architecture
1.278 + OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
1.279 + OUTPUT_STRIP_TRAILING_WHITESPACE
1.280 + )
1.281 + set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME_LOWERCASE}_${CPACK_PROJECT_VERSION_STRING}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
1.282 +else (DPKG_PROGRAM)
1.283 + set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME_LOWERCASE}_${CPACK_PROJECT_VERSION_STRING}_${CMAKE_SYSTEM_NAME}")
1.284 +endif (DPKG_PROGRAM)
1.285 +
1.286 +# package it
1.287 +include(CPack)
1.288 +