1
0
mirror of https://github.com/ThrowTheSwitch/Unity.git synced 2026-01-23 08:25:58 +01:00

project: revert UNITY_VERSION_* to unity.h

This commit is contained in:
Vitalii Shylienkov
2020-04-14 11:02:24 +02:00
parent b397a72e89
commit a2af08c773
5 changed files with 29 additions and 40 deletions

View File

@@ -11,17 +11,32 @@
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.12)
# Read root meson.build file and get project version from it # Read src/unity.h file and get project version from it
set(ROOT_MESON_BUILD_FILE "meson.build") set(UNITY_HEADER "src/unity.h")
file(READ "${ROOT_MESON_BUILD_FILE}" ROOT_MESON_BUILD_CONTENT)
string(REGEX MATCH " *version: '[.0-9]+'" UNITY_VERSION "${ROOT_MESON_BUILD_CONTENT}") file(STRINGS "${UNITY_HEADER}" UNITY_HEADER_CONTENT
if(NOT UNITY_VERSION) REGEX "^#define UNITY_VERSION_(MAJOR|MINOR|BUILD) +[0-9]+$"
message(FATAL_ERROR "Cannot define version from meson build file") )
endif()
string(REGEX REPLACE " *version: '([.0-9]+)'" "\\1" UNITY_VERSION "${UNITY_VERSION}") 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 project(unity
VERSION ${UNITY_VERSION} VERSION ${UNITY_HEADER_VERSION_MAJOR}.${UNITY_HEADER_VERSION_MINOR}.${UNITY_HEADER_VERSION_BUILD}
LANGUAGES C LANGUAGES C
DESCRIPTION "C Unit testing framework." DESCRIPTION "C Unit testing framework."
) )
@@ -34,12 +49,6 @@ add_library(${PROJECT_NAME}::framework ALIAS ${PROJECT_NAME})
include(GNUInstallDirs) include(GNUInstallDirs)
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
# Configuration ----------------------------------------------------------------
configure_file(cmake/templates/${PROJECT_NAME}_version.h.in
${PROJECT_NAME}_version.h
@ONLY
)
target_sources(${PROJECT_NAME} target_sources(${PROJECT_NAME}
PRIVATE PRIVATE
src/unity.c src/unity.c
@@ -54,7 +63,6 @@ target_include_directories(${PROJECT_NAME}
set(${PROJECT_NAME}_PUBLIC_HEADERS src/unity.h set(${PROJECT_NAME}_PUBLIC_HEADERS src/unity.h
src/unity_internals.h src/unity_internals.h
${CMAKE_CURRENT_BINARY_DIR}/unity_version.h
) )
set_target_properties(${PROJECT_NAME} set_target_properties(${PROJECT_NAME}

View File

@@ -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 */

View File

@@ -7,8 +7,7 @@
project('unity', 'c', project('unity', 'c',
license: 'MIT', license: 'MIT',
meson_version: '>=0.53.0', meson_version: '>=0.53.0',
default_options: ['layout=flat', 'warning_level=3', 'werror=true', 'c_std=c11'], default_options: ['layout=flat', 'warning_level=3', 'werror=true', 'c_std=c11']
version: '2.5.0'
) )
lang = 'c' lang = 'c'
cc = meson.get_compiler(lang) cc = meson.get_compiler(lang)

View File

@@ -4,15 +4,6 @@
# #
# license: MIT # 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_dir = include_directories('.')
unity_lib = static_library(meson.project_name(), unity_lib = static_library(meson.project_name(),

View File

@@ -8,7 +8,10 @@
#define UNITY_FRAMEWORK_H #define UNITY_FRAMEWORK_H
#define UNITY #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 #ifdef __cplusplus
extern "C" extern "C"