CMakeLists.txt 11.2 KB
Newer Older
1 2 3 4 5 6 7 8 9
# OpenVAS
# $Id$
# Description: Top-level cmake control for the Libraries.
#
# Authors:
# Matthew Mundell <matthew.mundell@greenbone.net>
# Jan-Oliver Wagner <jan-oliver.wagner@greenbone.net>
#
# Copyright:
10
# Copyright (C) 2011-2016 Greenbone Networks GmbH
11
#
12 13 14 15
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
16 17 18 19 20 21 22 23 24 25
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

26
cmake_minimum_required(VERSION 2.8)
27

28 29 30 31 32 33 34 35 36 37 38 39
include (openvas_cmake_macros)

message ("-- Configuring the Libraries...")

project (openvas-libraries C)

if (POLICY CMP0005)
  cmake_policy (SET CMP0005 OLD)
endif (POLICY CMP0005)

include (FindPkgConfig)

40 41 42 43
if (NOT PKG_CONFIG_FOUND)
  message(FATAL_ERROR "pkg-config executable not found. Aborting.")
endif (NOT PKG_CONFIG_FOUND)

44 45 46 47
if (NOT CMAKE_BUILD_TYPE)
  set (CMAKE_BUILD_TYPE Debug)
endif (NOT CMAKE_BUILD_TYPE)

48 49 50 51 52 53 54 55 56
OPTION(OPENVAS_OMP_ONLY "Build only the omp library and the required base and misc libraries" OFF)
OPTION(BUILD_STATIC "Build static versions of the openvas libraries" OFF)

if (NOT BUILD_STATIC)
  set (BUILD_SHARED ON)
else (NOT BUILD_STATIC)
  set (BUILD_SHARED OFF)
endif (NOT BUILD_STATIC)

57 58 59 60 61 62 63 64 65 66 67 68 69
## Retrieve svn revision (at configure time)
#  Not using Subversion_WC_INFO, as it would have to connect to the repo
find_program (SVN_EXECUTABLE svn DOC "subversion command line client")

macro (Subversion_GET_REVISION dir variable)
  execute_process (COMMAND ${SVN_EXECUTABLE} info ${CMAKE_SOURCE_DIR}/${dir}
    OUTPUT_VARIABLE ${variable}
    OUTPUT_STRIP_TRAILING_WHITESPACE)
  string (REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
    "\\2" ${variable} "${${variable}}")
endmacro (Subversion_GET_REVISION)

if (NOT CMAKE_BUILD_TYPE MATCHES "Release")
70
  if (EXISTS "${CMAKE_SOURCE_DIR}/.svn/")
71 72
    if (SVN_EXECUTABLE)
      Subversion_GET_REVISION(. ProjectRevision)
73
      set (SVN_REVISION "~svn${ProjectRevision}")
74
    else (SVN_EXECUTABLE)
75
      set (SVN_REVISION "~svn")
76
    endif (SVN_EXECUTABLE)
77
  endif (EXISTS "${CMAKE_SOURCE_DIR}/.svn/")
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
endif (NOT CMAKE_BUILD_TYPE MATCHES "Release")

# TODO: Check pkg-config (maybe with code like in gsa/CMakeLists.txt).

## CPack configuration

set (CPACK_CMAKE_GENERATOR "Unix Makefiles")
set (CPACK_GENERATOR "TGZ")
set (CPACK_INSTALL_CMAKE_PROJECTS ".;openvas-libraries;ALL;/")
set (CPACK_MODULE_PATH "")
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
set (CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README")
set (CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/README")
set (CPACK_SOURCE_GENERATOR "TGZ")
set (CPACK_SOURCE_TOPLEVEL_TAG "")
set (CPACK_SYSTEM_NAME "")
set (CPACK_TOPLEVEL_TAG "")
95
set (CPACK_PACKAGE_VERSION_MAJOR "9")
96
set (CPACK_PACKAGE_VERSION_MINOR "0")
97 98

# Use this scheme for stable releases:
Sophie Brun's avatar
Sophie Brun committed
99
set (CPACK_PACKAGE_VERSION_PATCH "2${SVN_REVISION}")
100
set (CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
101 102 103 104
# Use this scheme for +betaN and +rcN releases:
#set (CPACK_PACKAGE_VERSION_PATCH "+beta1${SVN_REVISION}")
#set (CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}${CPACK_PACKAGE_VERSION_PATCH}")

105 106 107 108
set (CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}")
set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}")
set (CPACK_PACKAGE_VENDOR "The OpenVAS Project")
set (CPACK_SOURCE_IGNORE_FILES
109
"${CMAKE_BINARY_DIR}"
110 111
"/.svn/"
"swp$"
112 113 114
"nasl/nasl_grammar.tab.c"
"nasl/nasl_grammar.tab.h"
"nasl/nasl_grammar.output"
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
)

include (CPack)

## Variables

if (SYSCONF_INSTALL_DIR)
  set (SYSCONFDIR "${SYSCONF_INSTALL_DIR}")
endif (SYSCONF_INSTALL_DIR)

if (NOT SYSCONFDIR)
  set (SYSCONFDIR "${CMAKE_INSTALL_PREFIX}/etc")
endif (NOT SYSCONFDIR)

if (NOT EXEC_PREFIX)
  set (EXEC_PREFIX "${CMAKE_INSTALL_PREFIX}")
endif (NOT EXEC_PREFIX)

if (NOT BINDIR)
  set (BINDIR "${EXEC_PREFIX}/bin")
endif (NOT BINDIR)

if (NOT SBINDIR)
  set (SBINDIR "${EXEC_PREFIX}/sbin")
endif (NOT SBINDIR)

if (NOT LIBDIR)
  set (_DEFAULT_LIBRARY_INSTALL_DIR lib)
  if (EXISTS "${EXEC_PREFIX}/lib32/" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
    set (_DEFAULT_LIBRARY_INSTALL_DIR lib32)
  endif (EXISTS "${EXEC_PREFIX}/lib32/" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
  if (EXISTS "${CMAKE_INSTALL_PREFIX}/lib64/" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
    set (_DEFAULT_LIBRARY_INSTALL_DIR lib64)
  endif (EXISTS "${CMAKE_INSTALL_PREFIX}/lib64/" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
  set( LIBRARY_INSTALL_DIR "${_DEFAULT_LIBRARY_INSTALL_DIR}")
  set (LIBDIR "${EXEC_PREFIX}/${LIBRARY_INSTALL_DIR}")
endif (NOT LIBDIR)

if (NOT LOCALSTATEDIR)
  set (LOCALSTATEDIR "${CMAKE_INSTALL_PREFIX}/var")
endif (NOT LOCALSTATEDIR)

if (NOT INCLUDEDIR)
  set (INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include")
endif (NOT INCLUDEDIR)

if (NOT DATADIR)
  set (DATADIR "${CMAKE_INSTALL_PREFIX}/share")
endif (NOT DATADIR)

165 166 167 168
if (NOT OPENVAS_PID_DIR)
  set (OPENVAS_PID_DIR "${LOCALSTATEDIR}/run")
endif (NOT OPENVAS_PID_DIR)

169 170 171 172 173 174 175 176 177 178 179 180 181
#if (NOT SYSCONFDIR)
#  set (SYSCONFDIR "${CMAKE_INSTALL_PREFIX}/etc")
#endif (NOT SYSCONFDIR)

set (OPENVAS_DATA_DIR    "${DATADIR}/openvas")
set (OPENVAS_STATE_DIR   "${LOCALSTATEDIR}/lib/openvas")
set (OPENVAS_LOG_DIR     "${LOCALSTATEDIR}/log/openvas")
set (OPENVAS_CACHE_DIR   "${LOCALSTATEDIR}/cache/openvas")
set (OPENVAS_SYSCONF_DIR "${SYSCONFDIR}/openvas")

set (OPENVAS_LIB_INSTALL_DIR     "${LIBDIR}")

set (OPENVAS_HEADER_INSTALL_DIR "${INCLUDEDIR}")
182
add_definitions (-DOPENVASSD_CONF=\\\"${OPENVAS_SYSCONF_DIR}/openvassd.conf\\\")
183 184 185 186 187 188

message ("-- Install prefix: ${CMAKE_INSTALL_PREFIX}")

## Dependency checks
##
## TODO Also check for headers where needed.
189

190 191
pkg_check_modules (GNUTLS REQUIRED gnutls>=3.2.15)
pkg_check_modules (GLIB REQUIRED glib-2.0>=2.32)
192
if (NOT OPENVAS_OMP_ONLY)
193 194
  pkg_check_modules (OPENVAS_WMICLIENT libopenvas_wmiclient>=1.0.1)
  pkg_check_modules (OPENVAS_WINCMD libopenvas_wincmd>=1.0.1)
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 254 255 256 257 258 259 260 261 262 263 264
  pkg_check_modules (LIBSSH REQUIRED libssh>=0.5.0)

  message (STATUS "Looking for pcap...")
  find_library (PCAP pcap)
  message (STATUS "Looking for pcap... ${PCAP}")
  if (NOT PCAP)
    message (SEND_ERROR "The pcap library is required.")
  endif (NOT PCAP)

  message (STATUS "Looking for pcap-config...")
  find_program (PCAP_CONFIG pcap-config)

  if (PCAP_CONFIG)
    message (STATUS "Looking for pcap-config... ${PCAP_CONFIG}")
    execute_process (COMMAND pcap-config --libs
      OUTPUT_VARIABLE PCAP_LDFLAGS
      OUTPUT_STRIP_TRAILING_WHITESPACE)
    execute_process (COMMAND pcap-config --cflags
      OUTPUT_VARIABLE PCAP_CFLAGS
      OUTPUT_STRIP_TRAILING_WHITESPACE)
  else (PCAP_CONFIG)
    message (STATUS "pcap-config not found, using defaults...")
    set (PCAP_LDFLAGS "-L/usr/lib -lpcap")
    set (PCAP_CFLAGS "-I/usr/include")
  endif (PCAP_CONFIG)
endif (NOT OPENVAS_OMP_ONLY)

if (NOT MINGW)
  # TODO: We do not have a library lookup for those modules
  # which also works when cross compiling. Library names
  # are hardcoded in the corresponding linker commands.
  message (STATUS "Looking for gpgme...")
  find_library (GPGME gpgme)
  message (STATUS "Looking for gpgme... ${GPGME}")
  if (NOT GPGME)
    message (SEND_ERROR "The gpgme library is required.")
  endif (NOT GPGME)

  execute_process (COMMAND gpgme-config --libs
    OUTPUT_VARIABLE GPGME_LDFLAGS
    OUTPUT_STRIP_TRAILING_WHITESPACE)
  execute_process (COMMAND gpgme-config --cflags
    OUTPUT_VARIABLE GPGME_CFLAGS
    OUTPUT_STRIP_TRAILING_WHITESPACE)

  message (STATUS "Looking for netsnmp...")
  find_library (SNMP snmp)
  message (STATUS "Looking for netsnmp... ${SNMP}")
  if (SNMP)
    execute_process (COMMAND net-snmp-config --libs
      OUTPUT_VARIABLE SNMP_LDFLAGS
      OUTPUT_STRIP_TRAILING_WHITESPACE)
  endif (SNMP)

  message (STATUS "Looking for libgcrypt...")
  find_library (GCRYPT gcrypt)
  message (STATUS "Looking for libgcrypt... ${GCRYPT}")
  if (NOT GCRYPT)
    message (SEND_ERROR "The libgcrypt library is required.")
  else (NOT GCRYPT)
    execute_process (COMMAND libgcrypt-config --libs
      OUTPUT_VARIABLE GCRYPT_LDFLAGS
      OUTPUT_STRIP_TRAILING_WHITESPACE)
    execute_process (COMMAND libgcrypt-config --cflags
      OUTPUT_VARIABLE GCRYPT_CFLAGS
      OUTPUT_STRIP_TRAILING_WHITESPACE)
  endif (NOT GCRYPT)

endif (NOT MINGW)

265 266
set (HARDENING_FLAGS "-Wformat -Wformat-security -O2 -D_FORTIFY_SOURCE=2 -fstack-protector")
set (LINKER_HARDENING_FLAGS "-Wl,-z,relro -Wl,-z,now")
267 268
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Werror")

269 270 271 272 273 274 275 276 277 278 279 280 281 282

## Version

string (REPLACE "
" "" OPENVASLIB_VERSION ${CPACK_PACKAGE_VERSION})

string(SUBSTRING ${CPACK_PACKAGE_VERSION_PATCH} 0 1 BETA_INDICATOR)
if (BETA_INDICATOR MATCHES "^\\+")
  set (LIBOPENVASCONFIG_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.0")
else (BETA_INDICATOR MATCHES "^\\+")
  set (LIBOPENVASCONFIG_VERSION "${OPENVASLIB_VERSION}")
endif (BETA_INDICATOR MATCHES "^\\+")

# Configure Doxyfile with version number
283 284 285 286 287 288 289
configure_file (doc/Doxyfile.in ${CMAKE_BINARY_DIR}/doc/Doxyfile @ONLY)
configure_file (doc/Doxyfile_full.in ${CMAKE_BINARY_DIR}/doc/Doxyfile_full @ONLY)
configure_file (VERSION.in ${CMAKE_BINARY_DIR}/VERSION @ONLY)
configure_file (libopenvas_base.pc.in ${CMAKE_BINARY_DIR}/libopenvas_base.pc @ONLY)
configure_file (libopenvas_omp.pc.in ${CMAKE_BINARY_DIR}/libopenvas_omp.pc @ONLY)
configure_file (libopenvas_misc.pc.in ${CMAKE_BINARY_DIR}/libopenvas_misc.pc @ONLY)
configure_file (libopenvas_nasl.pc.in ${CMAKE_BINARY_DIR}/libopenvas_nasl.pc @ONLY)
290
configure_file (libopenvas_osp.pc.in ${CMAKE_BINARY_DIR}/libopenvas_osp.pc @ONLY)
291 292 293 294 295

## Program

add_subdirectory (base)
add_subdirectory (misc)
296 297 298
if (NOT OPENVAS_OMP_ONLY)
  add_subdirectory (nasl)
endif (NOT OPENVAS_OMP_ONLY)
299
add_subdirectory (omp)
300
add_subdirectory (osp)
301 302 303 304 305 306 307 308 309

## Documentation

add_subdirectory (doc)

## Install

install (FILES doc/openvas-nasl.1
         DESTINATION ${DATADIR}/man/man1 )
310 311
install (FILES doc/openvas-nasl-lint.1
         DESTINATION ${DATADIR}/man/man1 )
312

313 314 315 316 317 318 319
install (FILES ${CMAKE_BINARY_DIR}/libopenvas_base.pc
         DESTINATION ${LIBDIR}/pkgconfig)
install (FILES ${CMAKE_BINARY_DIR}/libopenvas_omp.pc
         DESTINATION ${LIBDIR}/pkgconfig)
install (FILES ${CMAKE_BINARY_DIR}/libopenvas_misc.pc
         DESTINATION ${LIBDIR}/pkgconfig)
install (FILES ${CMAKE_BINARY_DIR}/libopenvas_nasl.pc
320
         DESTINATION ${LIBDIR}/pkgconfig)
321 322
install (FILES ${CMAKE_BINARY_DIR}/libopenvas_osp.pc
         DESTINATION ${LIBDIR}/pkgconfig)
323 324 325 326 327 328

install (DIRECTORY DESTINATION ${OPENVAS_LOG_DIR})
install (DIRECTORY DESTINATION ${OPENVAS_DATA_DIR})
install (DIRECTORY DESTINATION ${OPENVAS_CACHE_DIR})
install (DIRECTORY DESTINATION ${OPENVAS_PID_DIR})
install (DIRECTORY DESTINATION ${OPENVAS_SYSCONF_DIR})
329 330 331 332 333 334
install (DIRECTORY
  DESTINATION ${OPENVAS_SYSCONF_DIR}/gnupg
  DIRECTORY_PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE)
install (DIRECTORY
  DESTINATION ${OPENVAS_STATE_DIR}/gnupg
  DIRECTORY_PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE)
335 336 337 338 339 340

## Tests

enable_testing ()

## End