Skip to content

Commit af51f3d

Browse files
committed
CMake - introduce initial build configuration
1 parent d45dea4 commit af51f3d

File tree

6 files changed

+106
-0
lines changed

6 files changed

+106
-0
lines changed

CMakeLists.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
3+
set(VERSION_MAJOR 5)
4+
set(VERSION_MINOR 0)
5+
set(VERSION_PATCH 0)
6+
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
7+
8+
project(ipfixprobe VERSION ${VERSION} LANGUAGES CXX C)
9+
10+
include(cmake/build_type.cmake)
11+
include(cmake/installation.cmake)
12+
include(cmake/dependencies.cmake)
13+
14+
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
15+
16+
set(CMAKE_C_STANDARD 11)
17+
set(CMAKE_C_STANDARD_REQUIRED ON)
18+
set(CMAKE_C_EXTENSIONS ON)
19+
20+
set(CMAKE_CXX_STANDARD 20)
21+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
22+
set(CMAKE_CXX_EXTENSIONS ON)
23+
24+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
25+
26+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpedantic -Wall -Wextra -Wunused -Wconversion -Wsign-conversion")
27+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -Werror")
28+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -ggdb3")
29+
30+
31+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic -Wall -Wextra -Wunused -Wconversion -Wsign-conversion")
32+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Werror")
33+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -ggdb3")
34+
35+
add_subdirectory(src)

cmake/build_type.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Define default build type and supported options.
2+
set(DEFAULT_BUILD_TYPE "Release")
3+
4+
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
5+
message(STATUS
6+
"Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
7+
set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE}
8+
CACHE STRING "build type" FORCE)
9+
set_property(CACHE CMAKE_BUILD_TYPE
10+
PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
11+
endif()

cmake/dependencies.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Project dependencies

cmake/installation.cmake

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# The purpose of this file is to automatically determine install directories.
2+
#
3+
# If no directories are defined, use GNU install directories by default.
4+
# However, in case of RPM build, install directories are typically passed
5+
# to CMake as definitions that overwrites the default paths.
6+
#
7+
8+
include(GNUInstallDirs)
9+
10+
set(INSTALL_DIR_BIN ${CMAKE_INSTALL_FULL_BINDIR})
11+
12+
if (DEFINED LIB_INSTALL_DIR)
13+
set(INSTALL_DIR_LIB ${LIB_INSTALL_DIR})
14+
else()
15+
set(INSTALL_DIR_LIB ${CMAKE_INSTALL_FULL_LIBDIR})
16+
endif()
17+
18+
if (DEFINED INCLUDE_INSTALL_DIR)
19+
set(INSTALL_DIR_INCLUDE ${INCLUDE_INSTALL_DIR})
20+
else()
21+
set(INSTALL_DIR_INCLUDE ${CMAKE_INSTALL_FULL_INCLUDEDIR})
22+
endif()
23+
24+
if (DEFINED SYSCONF_INSTALL_DIR)
25+
set(INSTALL_DIR_SYSCONF ${SYSCONF_INSTALL_DIR})
26+
else()
27+
set(INSTALL_DIR_SYSCONF ${CMAKE_INSTALL_FULL_SYSCONFDIR})
28+
endif()
29+
30+
if (DEFINED SHARE_INSTALL_PREFIX)
31+
set(INSTALL_DIR_SHARE ${SHARE_INSTALL_PREFIX})
32+
else()
33+
set(INSTALL_DIR_SHARE ${CMAKE_INSTALL_FULL_DATAROOTDIR})
34+
endif()
35+
36+
set(INSTALL_DIR_MAN "${INSTALL_DIR_SHARE}/man/")
37+
set(INSTALL_DIR_DOC "${INSTALL_DIR_SHARE}/doc/${CMAKE_PROJECT_NAME}/")

src/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
add_subdirectory(core)
2+
add_subdirectory(plugins)
3+
4+
configure_file(
5+
${CMAKE_SOURCE_DIR}/src/buildConfig.hpp.in
6+
${CMAKE_BINARY_DIR}/src/buildConfig.hpp
7+
)

src/buildConfig.hpp.in

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @file
3+
* @brief Build configuration
4+
* @author Pavel Siska <[email protected]>
5+
* @date 2025
6+
*
7+
* Copyright (c) 2025 CESNET
8+
*
9+
* SPDX-License-Identifier: BSD-3-Clause
10+
*/
11+
12+
#pragma once
13+
14+
#define IPXP_APP_NAME "ipfixprobe"
15+
#define IPXP_APP_VERSION "@VERSION@"

0 commit comments

Comments
 (0)