From 9d601c274515225c412b8ac7365d2f5af335f39e Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Mon, 27 Aug 2018 05:50:40 +0200 Subject: [PATCH] CMake: set build info as compiler macros --- src/Cedar/CMakeLists.txt | 33 ++++++++++++++++++++++ src/Cedar/Cedar.h | 60 ++++++++++++++++++++-------------------- 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/src/Cedar/CMakeLists.txt b/src/Cedar/CMakeLists.txt index 0a84134a..19d5b60e 100644 --- a/src/Cedar/CMakeLists.txt +++ b/src/Cedar/CMakeLists.txt @@ -18,3 +18,36 @@ target_link_libraries(cedar ${LIB_READLINE} ${CURSES_LIBRARIES}) if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") target_link_libraries(cedar pcap) endif() + +# Version +add_definitions(-DCEDAR_VERSION_MAJOR=${PROJECT_VERSION_MAJOR} -DCEDAR_VERSION_MINOR=${PROJECT_VERSION_MINOR} -DCEDAR_VERSION_BUILD=${PROJECT_VERSION_PATCH}) + +# Builder +if(UNIX) + add_definitions(-DBUILDER_NAME="$ENV{USER}") +elseif(WIN32) + add_definitions(-DBUILDER_NAME="$ENV{USERNAME}") +endif() + +cmake_host_system_information(RESULT BUILDER_HOSTNAME QUERY HOSTNAME) + +add_definitions(-DBUILD_PLACE="${BUILDER_HOSTNAME}") + +# Date and time +string(TIMESTAMP BUILD_DAY "%d" UTC) +string(TIMESTAMP BUILD_MONTH "%m" UTC) +string(TIMESTAMP BUILD_YEAR "%Y" UTC) +string(TIMESTAMP BUILD_HOUR "%H" UTC) +string(TIMESTAMP BUILD_MINUTE "%M" UTC) +string(TIMESTAMP BUILD_SECOND "%S" UTC) + +## Remove leading 0 +string(REGEX REPLACE "^0" "" BUILD_DAY "${BUILD_DAY}") +string(REGEX REPLACE "^0" "" BUILD_MONTH "${BUILD_MONTH}") +string(REGEX REPLACE "^0" "" BUILD_YEAR "${BUILD_YEAR}") +string(REGEX REPLACE "^0" "" BUILD_HOUR "${BUILD_HOUR}") +string(REGEX REPLACE "^0" "" BUILD_MINUTE "${BUILD_MINUTE}") +string(REGEX REPLACE "^0" "" BUILD_SECOND "${BUILD_SECOND}") + +add_definitions(-DBUILD_DATE_D=${BUILD_DAY} -DBUILD_DATE_M=${BUILD_MONTH} -DBUILD_DATE_Y=${BUILD_YEAR}) +add_definitions(-DBUILD_DATE_HO=${BUILD_HOUR} -DBUILD_DATE_MI=${BUILD_MINUTE} -DBUILD_DATE_SE=${BUILD_SECOND}) diff --git a/src/Cedar/Cedar.h b/src/Cedar/Cedar.h index 990287d7..0d1f67c4 100644 --- a/src/Cedar/Cedar.h +++ b/src/Cedar/Cedar.h @@ -135,18 +135,18 @@ // Version number -#ifndef CEDAR_VERSION_MAJOR -#define CEDAR_VERSION_MAJOR 0 -#endif // CEDAR_VERSION_MAJOR +#ifndef CEDAR_VERSION_MAJOR +#define CEDAR_VERSION_MAJOR 0 +#endif // CEDAR_VERSION_MAJOR -#ifndef CEDAR_VERSION_MINOR -#define CEDAR_VERSION_MINOR 0 -#endif // CEDAR_VER_MINOR +#ifndef CEDAR_VERSION_MINOR +#define CEDAR_VERSION_MINOR 0 +#endif // CEDAR_VER_MINOR -// Build Number -#ifndef CEDAR_VERSION_BUILD -#define CEDAR_VERSION_BUILD 0 -#endif // CEDAR_VERSION_BUILD +// Build number +#ifndef CEDAR_VERSION_BUILD +#define CEDAR_VERSION_BUILD 0 +#endif // CEDAR_VERSION_BUILD // Beta number //#define BETA_NUMBER 3 @@ -156,38 +156,38 @@ // Specify the name of the person in charge building #ifndef BUILDER_NAME -#define BUILDER_NAME "Unknown" +#define BUILDER_NAME "Unknown" #endif // BUILDER_NAME // Specify the location to build #ifndef BUILD_PLACE -#define BUILD_PLACE "Unknown" +#define BUILD_PLACE "Unknown" #endif // BUILD_PLACE // Specifies the build date -#ifndef BUILD_DATE_Y -#define BUILD_DATE_Y 1970 -#endif // BUILD_DATE_Y +#ifndef BUILD_DATE_Y +#define BUILD_DATE_Y 1970 +#endif // BUILD_DATE_Y -#ifndef BUILD_DATE_M -#define BUILD_DATE_M 1 -#endif // BUILD_DATE_M +#ifndef BUILD_DATE_M +#define BUILD_DATE_M 1 +#endif // BUILD_DATE_M -#ifndef BUILD_DATE_D -#define BUILD_DATE_D 1 -#endif // BUILD_DATE_D +#ifndef BUILD_DATE_D +#define BUILD_DATE_D 1 +#endif // BUILD_DATE_D -#ifndef BUILD_DATE_HO -#define BUILD_DATE_HO 0 -#endif // BUILD_DATE_HO +#ifndef BUILD_DATE_HO +#define BUILD_DATE_HO 0 +#endif // BUILD_DATE_HO -#ifndef BUILD_DATE_MI -#define BUILD_DATE_MI 0 -#endif // BUILD_DATE_MI +#ifndef BUILD_DATE_MI +#define BUILD_DATE_MI 0 +#endif // BUILD_DATE_MI -#ifndef BUILD_DATE_SE -#define BUILD_DATE_SE 0 -#endif // BUILD_DATE_SE +#ifndef BUILD_DATE_SE +#define BUILD_DATE_SE 0 +#endif // BUILD_DATE_SE // Tolerable time difference #define ALLOW_TIMESTAMP_DIFF (UINT64)(3 * 24 * 60 * 60 * 1000)