From a4a235735588822a3e14cbc0e9661cb4fe572ab3 Mon Sep 17 00:00:00 2001 From: Axel Sommerfeldt Date: Mon, 13 Nov 2023 19:17:38 +0100 Subject: [PATCH] CMake build support revised - Compiler options '-Wall -pedantic' added - Definition of _XOPEN_SOURCE_EXTENDED added - Template configuration header file src/config.h.cmake added - README updated See also: https://github.com/irontec/sngrep/pull/462 --- .gitignore | 3 +- CMakeLists.txt | 60 +++++++++---------------------------- README | 14 ++++----- src/config.h.cmake | 73 ++++++++++++++++++++++++++++++++++++++++++++++ src/option.h | 4 +-- 5 files changed, 97 insertions(+), 57 deletions(-) create mode 100644 src/config.h.cmake diff --git a/.gitignore b/.gitignore index 35d242c..6f247ee 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,8 @@ tests/test-??? .deps .dirstamp *gmon.out -src/config.h* +src/config.h.in +src/config.h src/stamp-h1 .autotools diff --git a/CMakeLists.txt b/CMakeLists.txt index a4ee5f5..263530f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,9 +7,9 @@ option( WITH_OPENSSL "Enable SSL Support (TLS SIP Transport)" no ) option( WITH_PCRE "Enable Perl compatible regular expressions" no ) option( WITH_PCRE2 "Enable Perl compatible regular expressions (v2)" no ) option( WITH_ZLIB "Enable zlib to support gzip compressed pcap files" no ) -option( ENABLE_UNICODE "Enable Ncurses Unicode support" no ) -option( ENABLE_IPV6 "Enable IPv6 Support" no ) -option( ENABLE_EEP "Enable EEP/HEP Support" no ) +option( WITH_UNICODE "Enable Ncurses Unicode support" no ) +option( USE_IPV6 "Enable IPv6 Support" no ) +option( USE_EEP "Enable EEP/HEP Support" no ) option( DISABLE_LOGO "Disable Irontec Logo from Summary menu" no ) # Read parameters of AC_INIT() from file configure.ac @@ -33,17 +33,17 @@ project( ${AC_PACKAGE_NAME} add_executable( sngrep src/main.c ) +set_target_properties( sngrep PROPERTIES C_STANDARD 11 C_STANDARD_REQUIRED YES C_EXTENSIONS YES ) +target_compile_options( sngrep PRIVATE -Wall -pedantic ) # -Wextra -Wconversion -Werror + # Define _GNU_SOURCE etc. if( CMAKE_SYSTEM_NAME STREQUAL "Linux" ) - target_compile_definitions( sngrep PRIVATE _GNU_SOURCE=1 ) + target_compile_definitions( sngrep PRIVATE _GNU_SOURCE=1 _XOPEN_SOURCE_EXTENDED=1 ) endif() # we might want to use this with zlib for compressed pcap support include( CheckFunctionExists ) check_function_exists( fopencookie HAVE_FOPENCOOKIE ) -if( HAVE_FOPENCOOKIE ) - target_compile_definitions( sngrep PRIVATE HAVE_FOPENCOOKIE=1 ) -endif() ####################################################################### # Check for other REQUIRED libraries @@ -78,9 +78,7 @@ endif() #### #### Ncurses Wide character support #### -if( ENABLE_UNICODE ) - target_compile_definitions( sngrep PRIVATE WITH_UNICODE ) # Compile With Unicode compatibility - +if( WITH_UNICODE ) pkg_check_modules( NCURSES REQUIRED IMPORTED_TARGET ncursesw ) pkg_check_modules( PANEL REQUIRED IMPORTED_TARGET panelw ) pkg_check_modules( FORM REQUIRED IMPORTED_TARGET formw ) @@ -97,8 +95,6 @@ target_link_libraries( sngrep PUBLIC PkgConfig::NCURSES PkgConfig::PANEL PkgConf #### GnuTLS Support #### if( WITH_GNUTLS ) - target_compile_definitions( sngrep PRIVATE WITH_GNUTLS ) # Compile With GnuTLS compatibility - pkg_check_modules( GNUTLS REQUIRED IMPORTED_TARGET gnutls ) message( STATUS "Checking for library 'libgcrypt'" ) find_library( LIBGCRYPT gcrypt ) # Note: The use of "REQUIRED" here would need CMake 3.18... @@ -119,8 +115,6 @@ if( WITH_OPENSSL ) message( FATAL_ERROR "GnuTLS and OpenSSL can not be enabled at the same time" ) endif() - target_compile_definitions( sngrep PRIVATE WITH_OPENSSL ) # Compile With Openssl compatibility - pkg_check_modules( LIBSSL REQUIRED IMPORTED_TARGET libssl ) pkg_check_modules( LIBCRYPTO REQUIRED IMPORTED_TARGET libcrypto ) target_link_libraries( sngrep PUBLIC pthread PkgConfig::LIBSSL PkgConfig::LIBCRYPTO ) @@ -130,8 +124,6 @@ endif() #### PCRE Support #### if( WITH_PCRE ) - target_compile_definitions( sngrep PRIVATE WITH_PCRE ) # Compile With Perl Compatible regular expressions support - pkg_check_modules( LIBPCRE REQUIRED IMPORTED_TARGET libpcre ) target_link_libraries( sngrep PUBLIC pthread PkgConfig::LIBPCRE ) endif() @@ -144,33 +136,16 @@ if( WITH_PCRE2 ) message( FATAL_ERROR "libpcre-2 and libpcre-3 can not be enabled at the same time" ) endif() - target_compile_definitions( sngrep PRIVATE WITH_PCRE2 ) # Compile With Perl Compatible regular expressions support target_compile_definitions( sngrep PRIVATE PCRE2_CODE_UNIT_WIDTH=8 ) # Required for including pcre2.h pkg_check_modules( LIBPCRE2 REQUIRED IMPORTED_TARGET libpcre2-8 ) target_link_libraries( sngrep PUBLIC pthread PkgConfig::LIBPCRE2 ) endif() -#### -#### IPv6 Support -#### -if( ENABLE_IPV6 ) - target_compile_definitions( sngrep PRIVATE USE_IPV6 ) # Compile With IPv6 support -endif() - -#### -#### EEP Support -#### -if( ENABLE_EEP ) - target_compile_definitions( sngrep PRIVATE USE_EEP ) # Compile With EEP support -endif() - #### #### zlib Support #### if ( WITH_ZLIB ) - target_compile_definitions( sngrep PRIVATE WITH_ZLIB ) # Compile With zlib support - pkg_check_modules( ZLIB REQUIRED IMPORTED_TARGET zlib ) target_link_libraries( sngrep PUBLIC pthread PkgConfig::ZLIB ) endif() @@ -219,23 +194,14 @@ endif() if( WITH_OPENSSL ) target_sources( sngrep PRIVATE src/capture_openssl.c ) endif() -if( ENABLE_EEP ) +if( USE_EEP ) target_sources( sngrep PRIVATE src/capture_eep.c ) endif() ###################################################################### # Generate config.h -file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/config.h - "#define PACKAGE \"${PROJECT_NAME}\"\n" - "#define PACKAGE_BUGREPORT \"${CPACK_PACKAGE_CONTACT}\"\n" - "#define PACKAGE_NAME \"${PROJECT_NAME}\"\n" - "#define PACKAGE_STRING \"${PROJECT_NAME} ${PROJECT_VERSION}\"\n" - "#define PACKAGE_URL \"${PROJECT_HOMEPAGE_URL}\"\n" - "#define PACKAGE_VERSION \"${PROJECT_VERSION}\"\n" - "#define VERSION \"${PROJECT_VERSION}\"\n\n" - "#define CMAKE_CURRENT_BINARY_DIR \"${CMAKE_CURRENT_BINARY_DIR}\"\n" ) # CMAKE_CURRENT_BINARY_DIR is needed in tests/test_input.c - +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h ) target_include_directories( sngrep PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ) ###################################################################### @@ -305,11 +271,11 @@ message( STATUS "sngrep configure finished" ) message( STATUS "======================================================" ) message( STATUS "GnuTLS Support : ${WITH_GNUTLS}" ) message( STATUS "OpenSSL Support : ${WITH_OPENSSL}" ) -message( STATUS "Unicode Support : ${ENABLE_UNICODE}" ) +message( STATUS "Unicode Support : ${WITH_UNICODE}" ) message( STATUS "Perl Expressions Support : ${WITH_PCRE}" ) message( STATUS "Perl Expressions Support (v2): ${WITH_PCRE2}" ) -message( STATUS "IPv6 Support : ${ENABLE_IPV6}" ) -message( STATUS "EEP Support : ${ENABLE_EEP}" ) +message( STATUS "IPv6 Support : ${USE_IPV6}" ) +message( STATUS "EEP Support : ${USE_EEP}" ) message( STATUS "Zlib Support : ${WITH_ZLIB}" ) message( STATUS "======================================================" ) message( STATUS "" ) diff --git a/README b/README index f80b7d5..c4f6afe 100644 --- a/README +++ b/README @@ -59,13 +59,13 @@ You can pass following options to cmake to enable some features | CMake option | Feature | | ------------- | ------------- | -| `-D WITH_OPENSSL` | Adds OpenSSL support to parse TLS captured messages (req. libssl) | -| `-D WITH_GNUTLS` | Adds GnuTLS support to parse TLS captured messages (req. gnutls) | -| `-D WITH_PCRE`| Adds Perl Compatible regular expressions support in regexp fields | -| `-D WITH_ZLIB`| Enable zlib to support gzip compressed pcap files | -| `-D ENABLE_UNICODE` | Adds Ncurses UTF-8/Unicode support (req. libncursesw5) | -| `-D ENABLE_IPV6` | Enable IPv6 packet capture support | -| `-D ENABLE_EEP` | Enable EEP packet send/receive support | +| `-D WITH_OPENSSL=ON` | Adds OpenSSL support to parse TLS captured messages (req. libssl) | +| `-D WITH_GNUTLS=ON` | Adds GnuTLS support to parse TLS captured messages (req. gnutls) | +| `-D WITH_PCRE=ON`| Adds Perl Compatible regular expressions support in regexp fields | +| `-D WITH_ZLIB=ON`| Enable zlib to support gzip compressed pcap files | +| `-D WITH_UNICODE=ON` | Adds Ncurses UTF-8/Unicode support (req. libncursesw5) | +| `-D USE_IPV6=ON` | Enable IPv6 packet capture support | +| `-D USE_EEP=ON` | Enable EEP packet send/receive support | | `-D CPACK_GENERATOR=DEB` | `make package` builds a Debian package | | `-D CPACK_GENERATOR=RPM` | `make package` builds a RPM package | diff --git a/src/config.h.cmake b/src/config.h.cmake new file mode 100644 index 0000000..d968bf4 --- /dev/null +++ b/src/config.h.cmake @@ -0,0 +1,73 @@ +/************************************************************************** + ** + ** sngrep - SIP Messages flow viewer + ** + ** Copyright (C) 2013-2023 Ivan Alonso (Kaian) + ** Copyright (C) 2013-2023 Irontec SL. All rights reserved. + ** + ** 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 3 of the License, or + ** (at your option) any later version. + ** + ** 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, see . + ** + ****************************************************************************/ +/** + * @file config.h + * @author Ivan Alonso [aka Kaian] + * + * @brief Generated from config.h.cmake by CMake + * + */ + +#ifndef __SNGREP_CONFIG_H +#define __SNGREP_CONFIG_H + +/* Parameters of AC_INIT() */ +#define PACKAGE "@AC_PACKAGE_NAME@" +#define PACKAGE_BUGREPORT "@AC_PACKAGE_BUGREPORT@" +#define PACKAGE_NAME "@AC_PACKAGE_NAME@" +#define PACKAGE_STRING "@AC_PACKAGE_STRING@" +#define PACKAGE_URL "@AC_PACKAGE_URL@" +#define PACKAGE_VERSION "@AC_PACKAGE_VERSION@" +#define VERSION "@AC_PACKAGE_VERSION@" + +/* Define if you have the `fopencookie' function */ +#cmakedefine HAVE_FOPENCOOKIE + +/* Compile With Unicode compatibility */ +#cmakedefine WITH_UNICODE + +/* Compile With GnuTLS compatibility */ +#cmakedefine WITH_GNUTLS + +/* Compile With Openssl compatibility */ +#cmakedefine WITH_OPENSSL + +/* Compile With Perl Compatible regular expressions support */ +#cmakedefine WITH_PCRE + +/* Compile With Perl Compatible regular expressions support */ +#cmakedefine WITH_PCRE2 + +/* Compile With zlib support */ +#cmakedefine WITH_ZLIB + +/* Compile With IPv6 support */ +#cmakedefine USE_IPV6 + +/* Compile With EEP support */ +#cmakedefine USE_EEP + +/* CMAKE_CURRENT_BINARY_DIR is needed in tests/test_input.c */ +#define CMAKE_CURRENT_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@" + +#endif /* __SNGREP_CONFIG_H */ + diff --git a/src/option.h b/src/option.h index 78b149d..7748c18 100644 --- a/src/option.h +++ b/src/option.h @@ -40,8 +40,8 @@ * */ -#ifndef __SNGREP_CONFIG_H -#define __SNGREP_CONFIG_H +#ifndef __SNGREP_OPTION_H +#define __SNGREP_OPTION_H #include