ait/os/CMakeLists.txt
author om
Tue, 12 Nov 2013 11:31:34 +0100
branchom
changeset 2 c9bf2537109a
permissions -rw-r--r--
added C/C++ and Python sources
om@2
     1
# ------------------------------------------------------------
om@2
     2
# CMakeLists.txt the AIT OpenSecurity ShadowFUSE
om@2
     3
#
om@2
     4
# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
om@2
     5
# 
om@2
     6
# Copyright (C) 2013 AIT Austrian Institute of Technology
om@2
     7
# AIT Austrian Institute of Technology GmbH
om@2
     8
# Donau-City-Strasse 1 | 1220 Vienna | Austria
om@2
     9
# http://www.ait.ac.at
om@2
    10
#
om@2
    11
# This program is free software; you can redistribute it and/or 
om@2
    12
# modify it under the terms of the GNU General Public License 
om@2
    13
# version 2 as published by the Free Software Foundation.
om@2
    14
#
om@2
    15
# This program is distributed in the hope that it will be useful,
om@2
    16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
om@2
    17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
om@2
    18
# GNU General Public License for more details.
om@2
    19
#
om@2
    20
# You should have received a copy of the GNU Lesser General Public
om@2
    21
# License along with this library; if not, write to the
om@2
    22
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
om@2
    23
# Boston, MA 02110-1301, USA.
om@2
    24
# ------------------------------------------------------------
om@2
    25
om@2
    26
# project data
om@2
    27
project(os-server C CXX)
om@2
    28
cmake_minimum_required(VERSION 2.6)
om@2
    29
om@2
    30
# load necessary basic cmake modules
om@2
    31
include(CheckIncludeFile)
om@2
    32
include(CheckIncludeFiles)
om@2
    33
include(CheckLibraryExists)
om@2
    34
include(FindPkgConfig)
om@2
    35
include(FindPythonInterp)
om@2
    36
om@2
    37
# enable tests
om@2
    38
ENABLE_TESTING()
om@2
    39
om@2
    40
om@2
    41
# ------------------------------------------------------------
om@2
    42
# set global compiler flags
om@2
    43
om@2
    44
set(VERSION "0.1")
om@2
    45
add_definitions(-DVERSION=\"${VERSION}\")
om@2
    46
om@2
    47
# we relay on a GNU/BSD SOURCE
om@2
    48
add_definitions(-D_GNU_SOURCE)
om@2
    49
add_definitions(-D_BSD_SOURCE)
om@2
    50
om@2
    51
# set compile flags
om@2
    52
if (CMAKE_COMPILER_IS_GNUCC)
om@2
    53
om@2
    54
    # tweak capabilities of gcc versions prior to 4.8
om@2
    55
    if (${CMAKE_C_COMPILER_VERSION} LESS 4.8)
om@2
    56
    
om@2
    57
        message(STATUS "gcc compiler < 4.8 detected - tweaking flags")
om@2
    58
om@2
    59
        # make this clear: we use std::thread
om@2
    60
        # so enforce pthread bindings
om@2
    61
        # this may not be needed for gcc >= 4.8
om@2
    62
        add_definitions(-pthread)
om@2
    63
        
om@2
    64
        # this is needed to have
om@2
    65
        #   std::_this_thread::sleep(...)
om@2
    66
        # at hand - at least for gcc 4.6.3 and glibc 2.15
om@2
    67
        add_definitions(-D_GLIBCXX_USE_NANOSLEEP)
om@2
    68
om@2
    69
        # this is needed to have
om@2
    70
        #   std::_this_thread::yield()
om@2
    71
        # at hand - at least for gcc 4.6.3 and glibc 2.15
om@2
    72
        add_definitions(-D_GLIBCXX_USE_SCHED_YIELD)
om@2
    73
        
om@2
    74
    endif (${CMAKE_C_COMPILER_VERSION} LESS 4.8)
om@2
    75
    
om@2
    76
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Werror -Wall -Wextra -pedantic -g -ggdb3 -rdynamic")
om@2
    77
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x -Werror -Wall -Wextra -pedantic -g -ggdb3 -rdynamic")
om@2
    78
    
om@2
    79
    # TODO: make speed tests with -fno-builtin especially to
om@2
    80
    #       get a better memcpy performance
om@2
    81
    #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin")
om@2
    82
    #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin")
om@2
    83
    
om@2
    84
endif (CMAKE_COMPILER_IS_GNUCC)
om@2
    85
om@2
    86
# additional debug and profiling options
om@2
    87
option(DEBUG_MODE_ENABLED "enable debug mode" off)
om@2
    88
if (CMAKE_COMPILER_IS_GNUCC)
om@2
    89
    if (DEBUG_MODE_ENABLED)
om@2
    90
        message(STATUS "debug and profiling mode enabled")
om@2
    91
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -pg --coverage")
om@2
    92
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -pg --coverage")
om@2
    93
    else(DEBUG_MODE_ENABLED)
om@2
    94
        message(STATUS "debug and profiling mode disabled: go for optimizations")
om@2
    95
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
om@2
    96
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
om@2
    97
    endif(DEBUG_MODE_ENABLED)
om@2
    98
endif (CMAKE_COMPILER_IS_GNUCC)
om@2
    99
om@2
   100
om@2
   101
# ------------------------------------------------------------
om@2
   102
# check for an existing python module (maybe extra)
om@2
   103
om@2
   104
macro(CHECK_PYTHON_MODULE VARIABLE MODULE)
om@2
   105
om@2
   106
    message(STATUS "Looking for python module ${MODULE}")        
om@2
   107
    
om@2
   108
    if (PYTHONINTERP_FOUND)
om@2
   109
    
om@2
   110
        execute_process(
om@2
   111
            COMMAND ${PYTHON_EXECUTABLE} -c "import ${MODULE}"
om@2
   112
            RESULT_VARIABLE _result
om@2
   113
            OUTPUT_QUIET
om@2
   114
            ERROR_QUIET
om@2
   115
            )
om@2
   116
            
om@2
   117
        if ("${_result}" EQUAL "0")
om@2
   118
            set (${VARIABLE}_FOUND TRUE)
om@2
   119
        endif ("${_result}" EQUAL "0")
om@2
   120
        
om@2
   121
    endif (PYTHONINTERP_FOUND)
om@2
   122
om@2
   123
    if (${VARIABLE}_FOUND)
om@2
   124
        message(STATUS "Looking for python module ${MODULE} - found")        
om@2
   125
    else (${VARIABLE}_FOUND)
om@2
   126
        message(STATUS "Looking for python module ${MODULE} - not found")        
om@2
   127
    endif (${VARIABLE}_FOUND)
om@2
   128
om@2
   129
endmacro(CHECK_PYTHON_MODULE MODULE)
om@2
   130
om@2
   131
om@2
   132
# ------------------------------------------------------------
om@2
   133
# check libs and packages (headers + lib)
om@2
   134
om@2
   135
# standard C files
om@2
   136
check_include_file(stdio.h HAVE_STDIO_H)
om@2
   137
check_include_file(stddef.h HAVE_STDDEF_H)
om@2
   138
check_include_file(stdlib.h HAVE_STDLIB_H)
om@2
   139
check_include_file(inttypes.h HAVE_INTTYPES_H)
om@2
   140
check_include_file(memory.h HAVE_MEMORY_H)
om@2
   141
check_include_file(string.h HAVE_STRING_H)
om@2
   142
check_include_file(unistd.h HAVE_UNISTD_H)
om@2
   143
om@2
   144
# time
om@2
   145
check_include_file(sys/time.h HAVE_SYS_TIME_H)
om@2
   146
check_include_file(time.h HAVE_TIME_H)
om@2
   147
om@2
   148
# file system stuff
om@2
   149
check_include_file(fcntl.h HAVE_FCNTL_H)
om@2
   150
check_include_file(sys/stat.h HAVE_SYS_STAT_H)
om@2
   151
om@2
   152
# math
om@2
   153
check_include_file(math.h HAVE_MATH_H)
om@2
   154
om@2
   155
# stdbool
om@2
   156
check_include_file(stdbool.h HAVE_STDBOOL_H)
om@2
   157
om@2
   158
# endian
om@2
   159
check_include_file(endian.h HAVE_ENDIAN_H)
om@2
   160
om@2
   161
# math.h
om@2
   162
check_include_file(math.h HAVE_MATH_H)
om@2
   163
om@2
   164
# networking
om@2
   165
check_include_file(netdb.h HAVE_NETDB_H)
om@2
   166
check_include_file(ifaddrs.h HAVE_IFADDRS_H)
om@2
   167
check_include_file(netinet/in.h HAVE_NETINET_IN_H)
om@2
   168
check_include_file(arpa/inet.h HAVE_ARPA_INET_H)
om@2
   169
check_include_file(sys/socket.h HAVE_SYS_SOCKET_H)
om@2
   170
check_include_file(sys/un.h HAVE_SYS_UN_H)
om@2
   171
om@2
   172
# assert
om@2
   173
check_include_file(assert.h HAVE_ASSERT_H)
om@2
   174
om@2
   175
# signal
om@2
   176
check_include_file(signal.h HAVE_SIGNAL_H)
om@2
   177
om@2
   178
# sys/uio
om@2
   179
check_include_file(sys/uio.h HAVE_SYS_UIO_H)
om@2
   180
om@2
   181
# syslog
om@2
   182
check_include_file(syslog.h HAVE_SYSLOG_H)
om@2
   183
om@2
   184
# errno
om@2
   185
check_include_file(errno.h HAVE_ERRNO_H)
om@2
   186
om@2
   187
# limits
om@2
   188
check_include_file(limits.h HAVE_LIMITS_H)
om@2
   189
om@2
   190
# sys/mman.h
om@2
   191
check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
om@2
   192
om@2
   193
# dirent.h
om@2
   194
check_include_file(dirent.h HAVE_DIRENT_H)
om@2
   195
om@2
   196
# fuse.h
om@2
   197
pkg_check_modules(FUSE REQUIRED fuse)
om@2
   198
if (FUSE_FOUND)
om@2
   199
    set(HAVE_FUSE_H 1)
om@2
   200
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FUSE_CFLAGS_OTHER}")
om@2
   201
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FUSE_CFLAGS_OTHER}")
om@2
   202
    set(CMAKE_REQUIRED_LIBRARIES "${FUSE_LIBRARIES};${CMAKE_REQUIRED_LIBRARIES}")
om@2
   203
endif (FUSE_FOUND)
om@2
   204
om@2
   205
# check python module dbus
om@2
   206
check_python_module(PYTHON_DBUS dbus)
om@2
   207
if (NOT PYTHON_DBUS_FOUND)
om@2
   208
    message(FATAL_ERROR "python module 'dbus' missing.")
om@2
   209
endif (NOT PYTHON_DBUS_FOUND)
om@2
   210
om@2
   211
# check python module fuse
om@2
   212
check_python_module(PYTHON_FUSE fuse)
om@2
   213
if (NOT PYTHON_FUSE_FOUND)
om@2
   214
    message(FATAL_ERROR "python module 'fuse' missing. please install 'fuse-python'.")
om@2
   215
endif (NOT PYTHON_FUSE_FOUND)
om@2
   216
om@2
   217
# check python module web
om@2
   218
check_python_module(PYTHON_WEB web)
om@2
   219
if (NOT PYTHON_WEB_FOUND)
om@2
   220
    message(FATAL_ERROR "python module 'web' missing. please install 'web.py'.")
om@2
   221
endif (NOT PYTHON_WEB_FOUND)
om@2
   222
om@2
   223
om@2
   224
# ------------------------------------------------------------
om@2
   225
# dump the config file
om@2
   226
om@2
   227
# create the config.h and baseinc.h
om@2
   228
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
om@2
   229
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
om@2
   230
om@2
   231
om@2
   232
# ------------------------------------------------------------
om@2
   233
# go through the subs
om@2
   234
om@2
   235
add_subdirectory(bin)
om@2
   236
om@2
   237
om@2
   238
# ------------------------------------------------------------
om@2
   239
# additional stuff for installation
om@2
   240
om@2
   241
install(DIRECTORY etc/dbus-1 DESTINATION /etc)
om@2
   242
om@2
   243
om@2
   244
# ------------------------------------------------------------
om@2
   245
# packaging
om@2
   246
om@2
   247
set(CPACK_PACKAGE_NAME "opensecurity")
om@2
   248
om@2
   249
set(CPACK_PACKAGE_DESCRIPTION "OpenSecurity System")
om@2
   250
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "This is the OpenSecurity System suite to be insalled into a Security VM")
om@2
   251
set(CPACK_PACKAGE_CONTACT "Oliver Maurhart <oliver.maurhart@ait.ac.at>")
om@2
   252
set(CPACK_PACKAGE_VENDOR "AIT")
om@2
   253
set(CPACK_PACKAGE_VERSION_MAJOR "0")
om@2
   254
set(CPACK_PACKAGE_VERSION_MINOR "1")
om@2
   255
set(CPACK_PACKAGE_VERSION_PATCH "0")
om@2
   256
set(CPACK_PROJECT_VERSION_STRING "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}" )
om@2
   257
om@2
   258
set(CPACK_GENERATOR "DEB;RPM;")
om@2
   259
set(CPACK_SOURCE_GENERATOR "TGZ")
om@2
   260
om@2
   261
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}-${CMAKE_SYSTEM_PROCESSOR}")
om@2
   262
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
om@2
   263
set(CPACK_SOURCE_IGNORE_FILES "/build/*;/.git/")
om@2
   264
om@2
   265
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.13), libgcc1 (>= 1:4.4), python (>= 2.7)")
om@2
   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;")
om@2
   267
om@2
   268
# debianization
om@2
   269
string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_PACKAGE_NAME_LOWERCASE)
om@2
   270
find_program(DPKG_PROGRAM dpkg DOC "dpkg program of Debian-based systems")
om@2
   271
if (DPKG_PROGRAM)
om@2
   272
    # use dpkg to fix the package file name
om@2
   273
    execute_process(
om@2
   274
        COMMAND ${DPKG_PROGRAM} --print-architecture
om@2
   275
        OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
om@2
   276
        OUTPUT_STRIP_TRAILING_WHITESPACE
om@2
   277
    )
om@2
   278
    set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME_LOWERCASE}_${CPACK_PROJECT_VERSION_STRING}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
om@2
   279
else (DPKG_PROGRAM)
om@2
   280
    set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME_LOWERCASE}_${CPACK_PROJECT_VERSION_STRING}_${CMAKE_SYSTEM_NAME}")
om@2
   281
endif (DPKG_PROGRAM)
om@2
   282
om@2
   283
# package it
om@2
   284
include(CPack)
om@2
   285