Skip to content

Commit

Permalink
project: revert UNITY_VERSION_* to unity.h
Browse files Browse the repository at this point in the history
  • Loading branch information
vshylienkov committed Apr 14, 2020
1 parent b397a72 commit a2af08c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 40 deletions.
40 changes: 24 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
Expand All @@ -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
Expand All @@ -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}
Expand Down
12 changes: 0 additions & 12 deletions cmake/templates/unity_version.h.in

This file was deleted.

3 changes: 1 addition & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 0 additions & 9 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
5 changes: 4 additions & 1 deletion src/unity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a2af08c

Please sign in to comment.