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
     1 # ------------------------------------------------------------
     2 # CMakeLists.txt the AIT OpenSecurity ShadowFUSE
     3 #
     4 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
     5 # 
     6 # Copyright (C) 2013 AIT Austrian Institute of Technology
     7 # AIT Austrian Institute of Technology GmbH
     8 # Donau-City-Strasse 1 | 1220 Vienna | Austria
     9 # http://www.ait.ac.at
    10 #
    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.
    14 #
    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.
    19 #
    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 # ------------------------------------------------------------
    25 
    26 # project data
    27 project(os-server C CXX)
    28 cmake_minimum_required(VERSION 2.6)
    29 
    30 # load necessary basic cmake modules
    31 include(CheckIncludeFile)
    32 include(CheckIncludeFiles)
    33 include(CheckLibraryExists)
    34 include(FindPkgConfig)
    35 include(FindPythonInterp)
    36 
    37 # enable tests
    38 ENABLE_TESTING()
    39 
    40 
    41 # ------------------------------------------------------------
    42 # set global compiler flags
    43 
    44 set(VERSION "0.1")
    45 add_definitions(-DVERSION=\"${VERSION}\")
    46 
    47 # we relay on a GNU/BSD SOURCE
    48 add_definitions(-D_GNU_SOURCE)
    49 add_definitions(-D_BSD_SOURCE)
    50 
    51 # set compile flags
    52 if (CMAKE_COMPILER_IS_GNUCC)
    53 
    54     # tweak capabilities of gcc versions prior to 4.8
    55     if (${CMAKE_C_COMPILER_VERSION} LESS 4.8)
    56     
    57         message(STATUS "gcc compiler < 4.8 detected - tweaking flags")
    58 
    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)
    63         
    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)
    68 
    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)
    73         
    74     endif (${CMAKE_C_COMPILER_VERSION} LESS 4.8)
    75     
    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")
    78     
    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")
    83     
    84 endif (CMAKE_COMPILER_IS_GNUCC)
    85 
    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)
    99 
   100 
   101 # ------------------------------------------------------------
   102 # check for an existing python module (maybe extra)
   103 
   104 macro(CHECK_PYTHON_MODULE VARIABLE MODULE)
   105 
   106     message(STATUS "Looking for python module ${MODULE}")        
   107     
   108     if (PYTHONINTERP_FOUND)
   109     
   110         execute_process(
   111             COMMAND ${PYTHON_EXECUTABLE} -c "import ${MODULE}"
   112             RESULT_VARIABLE _result
   113             OUTPUT_QUIET
   114             ERROR_QUIET
   115             )
   116             
   117         if ("${_result}" EQUAL "0")
   118             set (${VARIABLE}_FOUND TRUE)
   119         endif ("${_result}" EQUAL "0")
   120         
   121     endif (PYTHONINTERP_FOUND)
   122 
   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)
   128 
   129 endmacro(CHECK_PYTHON_MODULE MODULE)
   130 
   131 
   132 # ------------------------------------------------------------
   133 # check libs and packages (headers + lib)
   134 
   135 # standard C files
   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)
   143 
   144 # time
   145 check_include_file(sys/time.h HAVE_SYS_TIME_H)
   146 check_include_file(time.h HAVE_TIME_H)
   147 
   148 # file system stuff
   149 check_include_file(fcntl.h HAVE_FCNTL_H)
   150 check_include_file(sys/stat.h HAVE_SYS_STAT_H)
   151 
   152 # math
   153 check_include_file(math.h HAVE_MATH_H)
   154 
   155 # stdbool
   156 check_include_file(stdbool.h HAVE_STDBOOL_H)
   157 
   158 # endian
   159 check_include_file(endian.h HAVE_ENDIAN_H)
   160 
   161 # math.h
   162 check_include_file(math.h HAVE_MATH_H)
   163 
   164 # networking
   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)
   171 
   172 # assert
   173 check_include_file(assert.h HAVE_ASSERT_H)
   174 
   175 # signal
   176 check_include_file(signal.h HAVE_SIGNAL_H)
   177 
   178 # sys/uio
   179 check_include_file(sys/uio.h HAVE_SYS_UIO_H)
   180 
   181 # syslog
   182 check_include_file(syslog.h HAVE_SYSLOG_H)
   183 
   184 # errno
   185 check_include_file(errno.h HAVE_ERRNO_H)
   186 
   187 # limits
   188 check_include_file(limits.h HAVE_LIMITS_H)
   189 
   190 # sys/mman.h
   191 check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
   192 
   193 # dirent.h
   194 check_include_file(dirent.h HAVE_DIRENT_H)
   195 
   196 # fuse.h
   197 pkg_check_modules(FUSE REQUIRED fuse)
   198 if (FUSE_FOUND)
   199     set(HAVE_FUSE_H 1)
   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}")
   203 endif (FUSE_FOUND)
   204 
   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)
   210 
   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)
   216 
   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)
   222 
   223 
   224 # ------------------------------------------------------------
   225 # dump the config file
   226 
   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})
   230 
   231 
   232 # ------------------------------------------------------------
   233 # go through the subs
   234 
   235 add_subdirectory(bin)
   236 
   237 
   238 # ------------------------------------------------------------
   239 # additional stuff for installation
   240 
   241 install(DIRECTORY etc/dbus-1 DESTINATION /etc)
   242 
   243 
   244 # ------------------------------------------------------------
   245 # packaging
   246 
   247 set(CPACK_PACKAGE_NAME "opensecurity")
   248 
   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}" )
   257 
   258 set(CPACK_GENERATOR "DEB;RPM;")
   259 set(CPACK_SOURCE_GENERATOR "TGZ")
   260 
   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/")
   264 
   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;")
   267 
   268 # debianization
   269 string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_PACKAGE_NAME_LOWERCASE)
   270 find_program(DPKG_PROGRAM dpkg DOC "dpkg program of Debian-based systems")
   271 if (DPKG_PROGRAM)
   272     # use dpkg to fix the package file name
   273     execute_process(
   274         COMMAND ${DPKG_PROGRAM} --print-architecture
   275         OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
   276         OUTPUT_STRIP_TRAILING_WHITESPACE
   277     )
   278     set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME_LOWERCASE}_${CPACK_PROJECT_VERSION_STRING}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
   279 else (DPKG_PROGRAM)
   280     set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME_LOWERCASE}_${CPACK_PROJECT_VERSION_STRING}_${CMAKE_SYSTEM_NAME}")
   281 endif (DPKG_PROGRAM)
   282 
   283 # package it
   284 include(CPack)
   285