Add static assertions that the version number is consistent

Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2022-05-03 14:39:00 +01:00 committed by Sam Lantinga
parent 22002d9155
commit 63814ec767
4 changed files with 25 additions and 1 deletions

View File

@ -2951,6 +2951,10 @@ if(SDL_STATIC)
endif()
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSDL_BUILD_MAJOR_VERSION=${SDL_MAJOR_VERSION}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSDL_BUILD_MINOR_VERSION=${SDL_MINOR_VERSION}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSDL_BUILD_MICRO_VERSION=${SDL_MICRO_VERSION}")
##### Tests #####
if(SDL_TEST)

View File

@ -11,7 +11,10 @@
# wmake -f Makefile.os2 HIDAPI=1
LIBNAME = SDL2
VERSION = 2.0.23
MAJOR_VERSION = 2
MINOR_VERSION = 0
MICRO_VERSION = 23
VERSION = $(MAJOR_VERSION).$(MINOR_VERSION).$(MICRO_VERSION)
DESCRIPTION = Simple DirectMedia Layer 2
LIBICONV=0
@ -60,6 +63,10 @@ CFLAGS_DLL+= -DHAVE_LIBUSB_H=1
# building SDL itself (for DECLSPEC):
CFLAGS_DLL+= -DBUILD_SDL
CFLAGS+= -DSDL_BUILD_MAJOR_VERSION=$(MAJOR_VERSION)
CFLAGS+= -DSDL_BUILD_MINOR_VERSION=$(MINOR_VERSION)
CFLAGS+= -DSDL_BUILD_MICRO_VERSION=$(MICRO_VERSION)
SRCS = SDL.c SDL_assert.c SDL_error.c SDL_log.c SDL_dataqueue.c SDL_hints.c SDL_list.c
SRCS+= SDL_getenv.c SDL_iconv.c SDL_malloc.c SDL_qsort.c SDL_stdlib.c SDL_string.c SDL_strtokr.c SDL_crc32.c
SRCS+= SDL_cpuinfo.c SDL_atomic.c SDL_spinlock.c SDL_thread.c SDL_timer.c

View File

@ -209,6 +209,10 @@ case "$enable_assertions" in
;;
esac
AC_DEFINE_UNQUOTED([SDL_BUILD_MAJOR_VERSION], $SDL_MAJOR_VERSION, [ ])
AC_DEFINE_UNQUOTED([SDL_BUILD_MINOR_VERSION], $SDL_MINOR_VERSION, [ ])
AC_DEFINE_UNQUOTED([SDL_BUILD_MICRO_VERSION], $SDL_MICRO_VERSION, [ ])
dnl See whether we can use gcc style dependency tracking
AC_ARG_ENABLE(dependency-tracking,
[AS_HELP_STRING([--enable-dependency-tracking],

View File

@ -62,6 +62,15 @@ extern int SDL_HelperWindowCreate(void);
extern int SDL_HelperWindowDestroy(void);
#endif
#ifdef SDL_BUILD_MAJOR_VERSION
SDL_COMPILE_TIME_ASSERT(SDL_BUILD_MAJOR_VERSION,
SDL_MAJOR_VERSION == SDL_BUILD_MAJOR_VERSION);
SDL_COMPILE_TIME_ASSERT(SDL_BUILD_MINOR_VERSION,
SDL_MINOR_VERSION == SDL_BUILD_MINOR_VERSION);
SDL_COMPILE_TIME_ASSERT(SDL_BUILD_MICRO_VERSION,
SDL_PATCHLEVEL == SDL_BUILD_MICRO_VERSION);
#endif
SDL_COMPILE_TIME_ASSERT(SDL_MAJOR_VERSION_min, SDL_MAJOR_VERSION >= 0);
/* Limited only by the need to fit in SDL_version */
SDL_COMPILE_TIME_ASSERT(SDL_MAJOR_VERSION_max, SDL_MAJOR_VERSION <= 255);