| 1 |
# SPDX-FileCopyrightText: 2011-2023 Greenbone AG |
| 2 |
# |
| 3 |
# SPDX-License-Identifier: GPL-2.0-or-later |
| 4 |
|
| 5 |
cmake_minimum_required(VERSION 3.18) |
| 6 |
|
| 7 |
message("-- Configuring the Greenbone Vulnerability Management Libraries...") |
| 8 |
|
| 9 |
# VERSION: Always include major, minor and patch level. |
| 10 |
project(gvm-libs VERSION 22.41.0 LANGUAGES C) |
| 11 |
|
| 12 |
if(POLICY CMP0005) |
| 13 |
cmake_policy(SET CMP0005 NEW) |
| 14 |
endif(POLICY CMP0005) |
| 15 |
|
| 16 |
set(C_STANDARD, 11) |
| 17 |
set(CMAKE_C_STANDARD 11) |
| 18 |
if(NOT CMAKE_BUILD_TYPE) |
| 19 |
set(CMAKE_BUILD_TYPE Debug) |
| 20 |
endif(NOT CMAKE_BUILD_TYPE) |
| 21 |
|
| 22 |
option(BUILD_STATIC "Build static versions of the libraries" OFF) |
| 23 |
option(ENABLE_COVERAGE "Enable support for coverage analysis" OFF) |
| 24 |
option(BUILD_TESTS "Build tests for the libraries" OFF) |
| 25 |
option(ENABLE_OPENVASD "Build openvasd library" ON) |
| 26 |
option(ENABLE_AGENTS "Build agent controller library" ON) |
| 27 |
option(ENABLE_CREDENTIAL_STORES "Build credential store library" ON) |
| 28 |
option(ENABLE_SECURITY_INTELLIGENCE "Build security intelligence library" ON) |
| 29 |
|
| 30 |
if(NOT BUILD_STATIC) |
| 31 |
set(BUILD_SHARED ON) |
| 32 |
else(NOT BUILD_STATIC) |
| 33 |
set(BUILD_SHARED OFF) |
| 34 |
endif(NOT BUILD_STATIC) |
| 35 |
|
| 36 |
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) |
| 37 |
|
| 38 |
## Retrieve git revision (at configure time) |
| 39 |
find_package(Git) |
| 40 |
|
| 41 |
## make format |
| 42 |
message(STATUS "Looking for clang-format...") |
| 43 |
find_program(CLANG_FORMAT clang-format) |
| 44 |
|
| 45 |
if(CLANG_FORMAT) |
| 46 |
message(STATUS "Looking for clang-format... ${CLANG_FORMAT}") |
| 47 |
add_custom_target( |
| 48 |
format |
| 49 |
COMMAND |
| 50 |
${CLANG_FORMAT} "-i" "./agent_controller/*.c" "./base/*.c" "./boreas/*.c" |
| 51 |
"./gmp/*.c" "./http_scanner/*.c" "./openvasd/*.c" "./osp/*.c" "./util/*.c" |
| 52 |
"./agent_controller/*.h" "./base/*.h" "./boreas/*.h" "./gmp/*.h" |
| 53 |
"./http_scanner/*.h" "./openvasd/*.h" "./osp/*.h" "./util/*.h" |
| 54 |
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 55 |
) |
| 56 |
else(CLANG_FORMAT) |
| 57 |
message(STATUS "clang-format not found...") |
| 58 |
endif(CLANG_FORMAT) |
| 59 |
|
| 60 |
include(MacroGitGetRevision) |
| 61 |
|
| 62 |
if(NOT CMAKE_BUILD_TYPE MATCHES "Release") |
| 63 |
if(EXISTS "${CMAKE_SOURCE_DIR}/.git/") |
| 64 |
if(GIT_FOUND) |
| 65 |
git_get_revision(${CMAKE_SOURCE_DIR} ProjectRevision) |
| 66 |
set(GIT_REVISION "~git-${ProjectRevision}") |
| 67 |
else(GIT_FOUND) |
| 68 |
set(GIT_REVISION "~git") |
| 69 |
endif(GIT_FOUND) |
| 70 |
endif(EXISTS "${CMAKE_SOURCE_DIR}/.git/") |
| 71 |
endif(NOT CMAKE_BUILD_TYPE MATCHES "Release") |
| 72 |
|
| 73 |
# Set dev version if this is a development version and not a full release, |
| 74 |
# unset (put value 0 or delete line) before a full release and reset after. |
| 75 |
set(PROJECT_DEV_VERSION 0) |
| 76 |
|
| 77 |
# If PROJECT_DEV_VERSION is set, the version string will be set to: |
| 78 |
# "major.minor.patch~dev${PROJECT_DEV_VERSION}${GIT_REVISION}" |
| 79 |
# If PROJECT_DEV_VERSION is NOT set, the version string will be set to: |
| 80 |
# "major.minor.patch${GIT_REVISION}" |
| 81 |
# For CMAKE_BUILD_TYPE "Release" the git revision will be empty. |
| 82 |
if(PROJECT_DEV_VERSION) |
| 83 |
set(PROJECT_VERSION_SUFFIX "~dev${PROJECT_DEV_VERSION}") |
| 84 |
endif(PROJECT_DEV_VERSION) |
| 85 |
|
| 86 |
set( |
| 87 |
PROJECT_VERSION_STRING |
| 88 |
"${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}${PROJECT_VERSION_SUFFIX}${GIT_REVISION}" |
| 89 |
) |
| 90 |
|
| 91 |
## CPack configuration |
| 92 |
|
| 93 |
set(CPACK_CMAKE_GENERATOR "Unix Makefiles") |
| 94 |
set(CPACK_GENERATOR "TGZ") |
| 95 |
set(CPACK_INSTALL_CMAKE_PROJECTS ".;gvm-libs;ALL;/") |
| 96 |
set(CPACK_MODULE_PATH "") |
| 97 |
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING") |
| 98 |
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md") |
| 99 |
set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/README.md") |
| 100 |
set(CPACK_SOURCE_GENERATOR "TGZ") |
| 101 |
set(CPACK_SOURCE_TOPLEVEL_TAG "") |
| 102 |
set(CPACK_SYSTEM_NAME "") |
| 103 |
set(CPACK_TOPLEVEL_TAG "") |
| 104 |
|
| 105 |
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION_STRING}${PROJECT_VERSION_GIT}") |
| 106 |
|
| 107 |
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}") |
| 108 |
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}") |
| 109 |
set(CPACK_PACKAGE_VENDOR "Greenbone Networks") |
| 110 |
set(CPACK_SOURCE_IGNORE_FILES "${CMAKE_BINARY_DIR}" "/.git/" "swp$") |
| 111 |
|
| 112 |
include(CPack) |
| 113 |
|
| 114 |
## Variables |
| 115 |
|
| 116 |
if(SYSCONF_INSTALL_DIR) |
| 117 |
set(SYSCONFDIR "${SYSCONF_INSTALL_DIR}") |
| 118 |
endif(SYSCONF_INSTALL_DIR) |
| 119 |
|
| 120 |
if(NOT SYSCONFDIR) |
| 121 |
set(SYSCONFDIR "/etc") |
| 122 |
endif(NOT SYSCONFDIR) |
| 123 |
|
| 124 |
if(NOT EXEC_PREFIX) |
| 125 |
set(EXEC_PREFIX "${CMAKE_INSTALL_PREFIX}") |
| 126 |
endif(NOT EXEC_PREFIX) |
| 127 |
|
| 128 |
if(NOT BINDIR) |
| 129 |
set(BINDIR "${EXEC_PREFIX}/bin") |
| 130 |
endif(NOT BINDIR) |
| 131 |
|
| 132 |
if(NOT SBINDIR) |
| 133 |
set(SBINDIR "${EXEC_PREFIX}/sbin") |
| 134 |
endif(NOT SBINDIR) |
| 135 |
|
| 136 |
if(NOT LIBDIR) |
| 137 |
set(_DEFAULT_LIBRARY_INSTALL_DIR lib) |
| 138 |
if(EXISTS "${EXEC_PREFIX}/lib32/" AND CMAKE_SIZEOF_VOID_P EQUAL 4) |
| 139 |
set(_DEFAULT_LIBRARY_INSTALL_DIR lib32) |
| 140 |
endif(EXISTS "${EXEC_PREFIX}/lib32/" AND CMAKE_SIZEOF_VOID_P EQUAL 4) |
| 141 |
if(EXISTS "${CMAKE_INSTALL_PREFIX}/lib64/" AND CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 142 |
set(_DEFAULT_LIBRARY_INSTALL_DIR lib64) |
| 143 |
endif(EXISTS "${CMAKE_INSTALL_PREFIX}/lib64/" AND CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 144 |
set(LIBRARY_INSTALL_DIR "${_DEFAULT_LIBRARY_INSTALL_DIR}") |
| 145 |
set(LIBDIR "${EXEC_PREFIX}/${LIBRARY_INSTALL_DIR}") |
| 146 |
endif(NOT LIBDIR) |
| 147 |
|
| 148 |
if(NOT LOCALSTATEDIR) |
| 149 |
set(LOCALSTATEDIR "/var") |
| 150 |
endif(NOT LOCALSTATEDIR) |
| 151 |
|
| 152 |
if(NOT INCLUDEDIR) |
| 153 |
set(INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include") |
| 154 |
endif(NOT INCLUDEDIR) |
| 155 |
|
| 156 |
if(NOT DATADIR) |
| 157 |
set(DATADIR "${CMAKE_INSTALL_PREFIX}/share") |
| 158 |
endif(NOT DATADIR) |
| 159 |
|
| 160 |
if(NOT GVM_RUN_DIR) |
| 161 |
set(GVM_RUN_DIR "/run/gvm") |
| 162 |
endif(NOT GVM_RUN_DIR) |
| 163 |
|
| 164 |
if(NOT GVM_SYSCONF_DIR) |
| 165 |
set(GVM_SYSCONF_DIR "${SYSCONFDIR}/gvm") |
| 166 |
endif(NOT GVM_SYSCONF_DIR) |
| 167 |
|
| 168 |
if(NOT REDIS_SOCKET_PATH) |
| 169 |
set(REDIS_SOCKET_PATH "/run/redis/redis.sock") |
| 170 |
endif() |
| 171 |
|
| 172 |
add_definitions(-DREDIS_SOCKET_PATH="${REDIS_SOCKET_PATH}") |
| 173 |
message("-- Using redis socket ${REDIS_SOCKET_PATH}") |
| 174 |
|
| 175 |
message("-- Install prefix: ${CMAKE_INSTALL_PREFIX}") |
| 176 |
|
| 177 |
if(ENABLE_COVERAGE) |
| 178 |
set(COVERAGE_FLAGS "--coverage -ftest-coverage -fprofile-arcs") |
| 179 |
set(COVERAGE_DIR "${CMAKE_BINARY_DIR}/coverage") |
| 180 |
file(MAKE_DIRECTORY ${COVERAGE_DIR}) |
| 181 |
message("-- Code Coverage enabled") |
| 182 |
endif(ENABLE_COVERAGE) |
| 183 |
|
| 184 |
set( |
| 185 |
HARDENING_FLAGS |
| 186 |
"-Wformat -Wformat-security -D_FORTIFY_SOURCE=2 -fstack-protector" |
| 187 |
) |
| 188 |
set(LINKER_HARDENING_FLAGS "-Wl,-z,relro -Wl,-z,now") |
| 189 |
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COVERAGE_FLAGS}") |
| 190 |
set( |
| 191 |
CMAKE_C_FLAGS_RELEASE |
| 192 |
"${CMAKE_C_FLAGS_RELEASE} ${HARDENING_FLAGS} ${COVERAGE_FLAGS}" |
| 193 |
) |
| 194 |
|
| 195 |
set( |
| 196 |
CMAKE_C_FLAGS |
| 197 |
"${CMAKE_C_FLAGS} ${GPGME_C_FLAGS} \ |
| 198 |
-std=c11 \ |
| 199 |
-Wall \ |
| 200 |
-Wextra \ |
| 201 |
-Werror \ |
| 202 |
-Wpedantic \ |
| 203 |
-Wmissing-prototypes \ |
| 204 |
-Wshadow \ |
| 205 |
-Wsequence-point \ |
| 206 |
-D_ISOC11_SOURCE \ |
| 207 |
-D_DEFAULT_SOURCE" |
| 208 |
) |
| 209 |
|
| 210 |
## Version |
| 211 |
|
| 212 |
set(LIBGVMCONFIG_VERSION "${PROJECT_VERSION_STRING}") |
| 213 |
|
| 214 |
add_definitions(-DGVM_LIBS_VERSION="${LIBGVMCONFIG_VERSION}") |
| 215 |
|
| 216 |
# Configure Doxyfile with version number |
| 217 |
configure_file(doc/Doxyfile.in ${CMAKE_BINARY_DIR}/doc/Doxyfile @ONLY) |
| 218 |
configure_file(doc/Doxyfile_full.in ${CMAKE_BINARY_DIR}/doc/Doxyfile_full @ONLY) |
| 219 |
configure_file(doc/Doxyfile_xml.in ${CMAKE_BINARY_DIR}/doc/Doxyfile_xml @ONLY) |
| 220 |
configure_file(VERSION.in ${CMAKE_BINARY_DIR}/VERSION @ONLY) |
| 221 |
|
| 222 |
## Testing |
| 223 |
|
| 224 |
if(BUILD_TESTS AND NOT SKIP_SRC) |
| 225 |
message("-- Tests enabled.") |
| 226 |
enable_testing() |
| 227 |
|
| 228 |
include(MacroAddUnitTest) |
| 229 |
|
| 230 |
find_package(cgreen REQUIRED) |
| 231 |
|
| 232 |
set( |
| 233 |
TESTS |
| 234 |
array-test |
| 235 |
boreas-alivedetection-test |
| 236 |
boreas-cli-test |
| 237 |
boreas-error-test |
| 238 |
boreas-io-test |
| 239 |
boreas-ping-test |
| 240 |
boreas-sniffer-test |
| 241 |
compressutils-test |
| 242 |
cpeutils-test |
| 243 |
cvss-test |
| 244 |
hosts-test |
| 245 |
json-test |
| 246 |
jsonpull-test |
| 247 |
logging-test |
| 248 |
logging-domain-test |
| 249 |
networking-test |
| 250 |
nvti-test |
| 251 |
osp-test |
| 252 |
passwordbasedauthentication-test |
| 253 |
streamvalidator-test |
| 254 |
test-hosts |
| 255 |
util-test |
| 256 |
version-test |
| 257 |
versionutils-test |
| 258 |
xmlutils-test |
| 259 |
) |
| 260 |
|
| 261 |
if(ENABLE_OPENVASD) |
| 262 |
list( |
| 263 |
APPEND TESTS |
| 264 |
openvasd-test |
| 265 |
http-scanner-test |
| 266 |
container_image_scanner-test |
| 267 |
httputils-test |
| 268 |
vtparser-test |
| 269 |
) |
| 270 |
endif(ENABLE_OPENVASD) |
| 271 |
|
| 272 |
if(ENABLE_AGENTS) |
| 273 |
list(APPEND TESTS agent-controller-test) |
| 274 |
endif(ENABLE_AGENTS) |
| 275 |
|
| 276 |
if(ENABLE_SECURITY_INTELLIGENCE) |
| 277 |
list(APPEND TESTS security-intelligence-test) |
| 278 |
endif(ENABLE_SECURITY_INTELLIGENCE) |
| 279 |
|
| 280 |
add_custom_target(tests DEPENDS ${TESTS}) |
| 281 |
|
| 282 |
# Code coverage |
| 283 |
if(ENABLE_COVERAGE) |
| 284 |
find_program(GCOVR gcovr) |
| 285 |
|
| 286 |
if(NOT GCOVR) |
| 287 |
message(FATAL_ERROR "gcovr coverage reporting tool not found") |
| 288 |
endif() |
| 289 |
|
| 290 |
message("-- Code Coverage Reporting enabled") |
| 291 |
|
| 292 |
add_custom_target( |
| 293 |
coverage-html |
| 294 |
COMMAND |
| 295 |
${GCOVR} --config ${CMAKE_SOURCE_DIR}/.gcovr.cfg --html-details |
| 296 |
${COVERAGE_DIR}/coverage.html -r ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} |
| 297 |
DEPENDS tests |
| 298 |
) |
| 299 |
add_custom_target( |
| 300 |
coverage-xml |
| 301 |
COMMAND |
| 302 |
${GCOVR} --config ${CMAKE_SOURCE_DIR}/.gcovr.cfg --xml |
| 303 |
${COVERAGE_DIR}/coverage.xml -r ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} |
| 304 |
DEPENDS tests |
| 305 |
) |
| 306 |
add_custom_target(coverage DEPENDS coverage-xml coverage-html) |
| 307 |
endif(ENABLE_COVERAGE) |
| 308 |
endif(BUILD_TESTS AND NOT SKIP_SRC) |
| 309 |
|
| 310 |
add_custom_target( |
| 311 |
clean-coverage |
| 312 |
COMMAND find . -name *.gcda -delete -or -name *.gcno -delete |
| 313 |
COMMAND rm -f ${COVERAGE_DIR}/* |
| 314 |
) |
| 315 |
|
| 316 |
## Program |
| 317 |
|
| 318 |
if(NOT SKIP_SRC) |
| 319 |
add_subdirectory(base) |
| 320 |
add_subdirectory(boreas) |
| 321 |
add_subdirectory(util) |
| 322 |
add_subdirectory(osp) |
| 323 |
add_subdirectory(gmp) |
| 324 |
|
| 325 |
if( |
| 326 |
ENABLE_OPENVASD |
| 327 |
OR ENABLE_AGENTS |
| 328 |
OR ENABLE_CREDENTIAL_STORES |
| 329 |
OR ENABLE_SECURITY_INTELLIGENCE |
| 330 |
) |
| 331 |
add_subdirectory(http) |
| 332 |
endif( |
| 333 |
ENABLE_OPENVASD |
| 334 |
OR ENABLE_AGENTS |
| 335 |
OR ENABLE_CREDENTIAL_STORES |
| 336 |
OR ENABLE_SECURITY_INTELLIGENCE |
| 337 |
) |
| 338 |
|
| 339 |
if(ENABLE_OPENVASD) |
| 340 |
add_subdirectory(http_scanner) |
| 341 |
add_subdirectory(openvasd) |
| 342 |
add_subdirectory(container_image_scanner) |
| 343 |
endif(ENABLE_OPENVASD) |
| 344 |
|
| 345 |
if(ENABLE_AGENTS) |
| 346 |
add_subdirectory(agent_controller) |
| 347 |
endif(ENABLE_AGENTS) |
| 348 |
|
| 349 |
if(ENABLE_CREDENTIAL_STORES) |
| 350 |
add_subdirectory(cyberark) |
| 351 |
endif(ENABLE_CREDENTIAL_STORES) |
| 352 |
|
| 353 |
if(ENABLE_SECURITY_INTELLIGENCE) |
| 354 |
add_subdirectory(security_intelligence) |
| 355 |
endif(ENABLE_SECURITY_INTELLIGENCE) |
| 356 |
endif(NOT SKIP_SRC) |
| 357 |
|
| 358 |
## Documentation |
| 359 |
|
| 360 |
add_subdirectory(doc) |
| 361 |
|
| 362 |
if(BUILD_TESTS AND NOT SKIP_SRC) |
| 363 |
add_subdirectory(tests) |
| 364 |
add_test(NAME testhosts COMMAND test-hosts localhost) |
| 365 |
endif(BUILD_TESTS AND NOT SKIP_SRC) |
| 366 |
|
| 367 |
## End |