From 10dcbeb55e78ca5e3641148fb715e97b33b2ec24 Mon Sep 17 00:00:00 2001 From: "H. Utku Maden" Date: Sat, 8 Jul 2023 14:08:11 +0300 Subject: [PATCH] Added stb redistributables. --- .gitignore | 2 + Quik.StbImage.redist/.gitignore | 2 - Quik.StbImage.redist/quik_stbi.c | 15 +----- Quik.StbImage.redist/quik_stbi.h | 25 ++-------- Quik.StbTrueType.redist/CMakeLists.txt | 12 +++++ .../Quik.StbTrueType.redist.nuspec | 19 +++++++ Quik.StbTrueType.redist/quik_stbtt.c | 6 +++ Quik.StbTrueType.redist/quik_stbtt.h | 14 ++++++ lib/quik/quik_common.h | 50 +++++++++++++++++++ sh/build_native.sh | 6 ++- 10 files changed, 114 insertions(+), 37 deletions(-) delete mode 100644 Quik.StbImage.redist/.gitignore create mode 100644 Quik.StbTrueType.redist/CMakeLists.txt create mode 100644 Quik.StbTrueType.redist/Quik.StbTrueType.redist.nuspec create mode 100644 Quik.StbTrueType.redist/quik_stbtt.c create mode 100644 Quik.StbTrueType.redist/quik_stbtt.h create mode 100644 lib/quik/quik_common.h diff --git a/.gitignore b/.gitignore index 83df60d..8a5925c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ riderModule.iml .idea .vscode nuget_repo +*.redist/out +*.redist/runtimes \ No newline at end of file diff --git a/Quik.StbImage.redist/.gitignore b/Quik.StbImage.redist/.gitignore deleted file mode 100644 index 3cf806a..0000000 --- a/Quik.StbImage.redist/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -runtimes diff --git a/Quik.StbImage.redist/quik_stbi.c b/Quik.StbImage.redist/quik_stbi.c index f5e332a..75bd55e 100644 --- a/Quik.StbImage.redist/quik_stbi.c +++ b/Quik.StbImage.redist/quik_stbi.c @@ -1,17 +1,6 @@ #include "quik_stbi.h" +QUIK_DEFINE_LIB(quik_stbi); + #define STB_IMAGE_IMPLEMENTATION 1 #include "stb/stb_image.h" - -quik_failed_assert_cb_t quik_stbi_failed_assert = quik_stbi_failed_assert_default; - -void quik_stbi_failed_assert_store(quik_failed_assert_cb_t cb) -{ - quik_stbi_failed_assert = cb != NULL ? cb : quik_stbi_failed_assert_default; - -} - -void quik_stbi_failed_assert_default(const char *expr, const char *file, int line, const char *function) -{ - abort(); -} \ No newline at end of file diff --git a/Quik.StbImage.redist/quik_stbi.h b/Quik.StbImage.redist/quik_stbi.h index 128f12d..4f9d579 100644 --- a/Quik.StbImage.redist/quik_stbi.h +++ b/Quik.StbImage.redist/quik_stbi.h @@ -1,26 +1,9 @@ -#ifndef _QUIK_STB_CONFIG_H_ -#define _QUIK_STB_CONFIG_H_ +#ifndef _QUIK_STBI_H_ +#define _QUIK_STBI_H_ -#include "stddef.h" +#include "quik/quik_common.h" -#if __GNUC__ || __MSC_VER - #define __QUIK_FUNCTION__ __FUNCTION__ - #define QEXTERN extern -#else - #define __QUIK_FUNCTION__ NULL -#endif - -/* TODO: Change this declaration so we can export a DLL properly in windows. */ -#define STBIDEF QEXTERN -#define STBI_NO_STDIO 1 - -typedef void (*quik_failed_assert_cb_t)(const char *expr, const char *file, int line, const char* func); - -QEXTERN quik_failed_assert_cb_t quik_stbi_failed_assert; -QEXTERN void quik_stbi_failed_assert_store(quik_failed_assert_cb_t cb); -QEXTERN void quik_stbi_failed_assert_default(const char * expr, const char *file, int line, const char *function); - -/* Overwrite cstdlib functions so we can get as close as possible to freestanding environment. */ +QUIK_DECLARE_LIB(quik_stbi) #define STBI_ASSERT(EXPR) do { \ if (!(EXPR)) \ diff --git a/Quik.StbTrueType.redist/CMakeLists.txt b/Quik.StbTrueType.redist/CMakeLists.txt new file mode 100644 index 0000000..761ef0b --- /dev/null +++ b/Quik.StbTrueType.redist/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.0) + +project(quik_stbtt LANGUAGES C VERSION 1.0) + +add_compile_options(-static-libgcc) + +add_library(stbtt SHARED "quik_stbtt.c") +target_include_directories(stbtt PRIVATE "../lib") +install( + TARGETS stbtt + RUNTIME DESTINATION . + LIBRARY DESTINATION .) diff --git a/Quik.StbTrueType.redist/Quik.StbTrueType.redist.nuspec b/Quik.StbTrueType.redist/Quik.StbTrueType.redist.nuspec new file mode 100644 index 0000000..196fa55 --- /dev/null +++ b/Quik.StbTrueType.redist/Quik.StbTrueType.redist.nuspec @@ -0,0 +1,19 @@ + + + + Quik.StbTrueType.redist + 1.0.0 + STBTT Authors, H. Utku Maden + utkumaden + + This is a redistribution of STBTT for use with the QUIK project. + + Compiled with a custom assert function. Call `quik_stbtt_failed_assert_store` + to replace. + + native + + + + + \ No newline at end of file diff --git a/Quik.StbTrueType.redist/quik_stbtt.c b/Quik.StbTrueType.redist/quik_stbtt.c new file mode 100644 index 0000000..b377217 --- /dev/null +++ b/Quik.StbTrueType.redist/quik_stbtt.c @@ -0,0 +1,6 @@ +#include "quik_stbtt.h" + +QUIK_DEFINE_LIB(quik_stbtt); + +#define STB_TRUETYPE_IMPLEMENTATION 1 +#include "stb/stb_truetype.h" diff --git a/Quik.StbTrueType.redist/quik_stbtt.h b/Quik.StbTrueType.redist/quik_stbtt.h new file mode 100644 index 0000000..e1ff001 --- /dev/null +++ b/Quik.StbTrueType.redist/quik_stbtt.h @@ -0,0 +1,14 @@ +#ifndef _QUIK_STBTT_H_ +#define _QUIK_STBTT_H_ + +#include "quik/quik_common.h" + +QUIK_DECLARE_LIB(quik_stbtt); + +#define STBTT_assert(EXPR) do { \ + quik_stbtt_failed_assert(#EXPR, __FILE__, __LINE__ - 2, __QUIK_FUNCTION__); \ +} while(0) + +#include "stb/stb_truetype.h" + +#endif diff --git a/lib/quik/quik_common.h b/lib/quik/quik_common.h new file mode 100644 index 0000000..1a57d94 --- /dev/null +++ b/lib/quik/quik_common.h @@ -0,0 +1,50 @@ +#ifndef _QUIK_COMMON_H_ +#define _QUIK_COMMON_H_ + +#include "stdlib.h" + +#if __GNUC__ || __MSC_VER + #define __QUIK_FUNCTION__ __FUNCTION__ + #define QEXTERN extern +#else + #define __QUIK_FUNCTION__ NULL +#endif + +/* TODO: Change this declaration so we can export a DLL properly in windows. */ +#define STBIDEF QEXTERN + +/** + * @brief Callback for failed assert function for QUIK redist libraries. + * @param[in] expr The expression that failed. + * @param[in] file The failing file (if available) + * @param[in] line The failing line number (if available) + * @param[in] func The failing function (if available) +*/ +typedef void (*quik_failed_assert_cb_t)(const char *expr, const char *file, int line, const char* func); + +#define DECLARE_ASSERT_CB(NAME) \ + QEXTERN quik_failed_assert_cb_t NAME##_failed_assert +#define DECLARE_ASSERT_STORE(NAME) \ + QEXTERN void NAME##_failed_assert_store(quik_failed_assert_cb_t cb) + +#define DEFINE_ASSERT_CB(NAME) \ + quik_failed_assert_cb_t NAME##_failed_assert +#define DEFINE_ASSERT_STORE(NAME) \ + void NAME##_failed_assert_store(quik_failed_assert_cb_t cb) { \ + NAME##_failed_assert = cb != NULL ? cb : quik_default_assert; \ + } + +#define QUIK_DECLARE_LIB(NAME) \ + DECLARE_ASSERT_CB(NAME); \ + DECLARE_ASSERT_STORE(NAME); + +#define QUIK_DEFINE_LIB(NAME) \ + DEFINE_ASSERT_CB(NAME); \ + DEFINE_ASSERT_STORE(NAME); + +inline static void quik_default_assert(const char *expr, const char *file, int line, const char *function) +{ + abort(); +} + +#endif diff --git a/sh/build_native.sh b/sh/build_native.sh index d8ec71e..ea8722d 100755 --- a/sh/build_native.sh +++ b/sh/build_native.sh @@ -1,3 +1,7 @@ #!/bin/bash source $(dirname "$0")/quik_build_native.sh -quik_build_native "Quik.StbImage.redist" "linux-arm linux-arm64 linux-x64 linux-x86 win-x64 win-x86" \ No newline at end of file + +ARCHS="linux-arm linux-arm64 linux-x64 linux-x86 win-x64 win-x86" +quik_build_native "Quik.StbImage.redist" "$ARCHS" +cd .. +quik_build_native "Quik.StbTrueType.redist" "$ARCHS"