From a2af08c773803755e90614615fe9b649f5b242e6 Mon Sep 17 00:00:00 2001 From: Vitalii Shylienkov Date: Tue, 14 Apr 2020 11:02:24 +0200 Subject: [PATCH] project: revert UNITY_VERSION_* to unity.h --- CMakeLists.txt | 40 ++++++++++++++++++------------ cmake/templates/unity_version.h.in | 12 --------- meson.build | 3 +-- src/meson.build | 9 ------- src/unity.h | 5 +++- 5 files changed, 29 insertions(+), 40 deletions(-) delete mode 100644 cmake/templates/unity_version.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 70de467..3a9d8a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,17 +11,32 @@ cmake_minimum_required(VERSION 3.12) -# Read root meson.build file and get project version from it -set(ROOT_MESON_BUILD_FILE "meson.build") -file(READ "${ROOT_MESON_BUILD_FILE}" ROOT_MESON_BUILD_CONTENT) -string(REGEX MATCH " *version: '[.0-9]+'" UNITY_VERSION "${ROOT_MESON_BUILD_CONTENT}") -if(NOT UNITY_VERSION) - message(FATAL_ERROR "Cannot define version from meson build file") -endif() -string(REGEX REPLACE " *version: '([.0-9]+)'" "\\1" UNITY_VERSION "${UNITY_VERSION}") +# Read src/unity.h file and get project version from it +set(UNITY_HEADER "src/unity.h") + +file(STRINGS "${UNITY_HEADER}" UNITY_HEADER_CONTENT + REGEX "^#define UNITY_VERSION_(MAJOR|MINOR|BUILD) +[0-9]+$" +) + +set(UNITY_HEADER_VERSION_MAJOR 0) +set(UNITY_HEADER_VERSION_MINOR 0) +set(UNITY_HEADER_VERSION_BUILD 0) + +foreach(VERSION_LINE IN LISTS UNITY_HEADER_CONTENT) + foreach(VERSION_PART MAJOR MINOR BUILD) + string(CONCAT REGEX_STRING "#define UNITY_VERSION_" + "${VERSION_PART}" + " +([0-9]+)" + ) + + if(VERSION_LINE MATCHES "${REGEX_STRING}") + set(UNITY_HEADER_VERSION_${VERSION_PART} "${CMAKE_MATCH_1}") + endif() + endforeach() +endforeach() project(unity - VERSION ${UNITY_VERSION} + VERSION ${UNITY_HEADER_VERSION_MAJOR}.${UNITY_HEADER_VERSION_MINOR}.${UNITY_HEADER_VERSION_BUILD} LANGUAGES C DESCRIPTION "C Unit testing framework." ) @@ -34,12 +49,6 @@ add_library(${PROJECT_NAME}::framework ALIAS ${PROJECT_NAME}) include(GNUInstallDirs) include(CMakePackageConfigHelpers) -# Configuration ---------------------------------------------------------------- -configure_file(cmake/templates/${PROJECT_NAME}_version.h.in - ${PROJECT_NAME}_version.h - @ONLY -) - target_sources(${PROJECT_NAME} PRIVATE src/unity.c @@ -54,7 +63,6 @@ target_include_directories(${PROJECT_NAME} set(${PROJECT_NAME}_PUBLIC_HEADERS src/unity.h src/unity_internals.h - ${CMAKE_CURRENT_BINARY_DIR}/unity_version.h ) set_target_properties(${PROJECT_NAME} diff --git a/cmake/templates/unity_version.h.in b/cmake/templates/unity_version.h.in deleted file mode 100644 index 7c89e77..0000000 --- a/cmake/templates/unity_version.h.in +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef UNITY_CONFIG_H -#define UNITY_CONFIG_H - -#define UNITY_VERSION_STRING "@PROJECT_VERSION@" -#define UNITY_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ -#define UNITY_VERSION_MINOR @PROJECT_VERSION_MINOR@ -#define UNITY_VERSION_BUILD @PROJECT_VERSION_PATCH@ -#define UNITY_VERSION ((UNITY_VERSION_MAJOR << 16) | \ - (UNITY_VERSION_MINOR << 8) | \ - UNITY_VERSION_BUILD) - -#endif /* UNITY_CONFIG_H */ diff --git a/meson.build b/meson.build index 33d5887..968e5b1 100644 --- a/meson.build +++ b/meson.build @@ -7,8 +7,7 @@ project('unity', 'c', license: 'MIT', meson_version: '>=0.53.0', - default_options: ['layout=flat', 'warning_level=3', 'werror=true', 'c_std=c11'], - version: '2.5.0' + default_options: ['layout=flat', 'warning_level=3', 'werror=true', 'c_std=c11'] ) lang = 'c' cc = meson.get_compiler(lang) diff --git a/src/meson.build b/src/meson.build index 19e7bd8..7ede15a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -4,15 +4,6 @@ # # license: MIT # -conf_data = configuration_data() -conf_data.set('PROJECT_VERSION', meson.project_version()) -conf_data.set('PROJECT_VERSION_MAJOR',meson.project_version().split('.')[0]) -conf_data.set('PROJECT_VERSION_MINOR',meson.project_version().split('.')[1]) -conf_data.set('PROJECT_VERSION_PATCH',meson.project_version().split('.')[2]) -unity_version_template = join_paths(meson.source_root(), 'cmake/templates/unity_version.h.in') -unity_version_file =configure_file(input : unity_version_template, - output : 'unity_version.h', - configuration : conf_data) unity_dir = include_directories('.') unity_lib = static_library(meson.project_name(), diff --git a/src/unity.h b/src/unity.h index 6eceb8d..925cd4d 100644 --- a/src/unity.h +++ b/src/unity.h @@ -8,7 +8,10 @@ #define UNITY_FRAMEWORK_H #define UNITY -#include "unity_version.h" +#define UNITY_VERSION_MAJOR 2 +#define UNITY_VERSION_MINOR 5 +#define UNITY_VERSION_BUILD 0 +#define UNITY_VERSION ((UNITY_VERSION_MAJOR << 16) | (UNITY_VERSION_MINOR << 8) | UNITY_VERSION_BUILD) #ifdef __cplusplus extern "C"