Added stb redistributables.

This commit is contained in:
H. Utku Maden 2023-07-08 14:08:11 +03:00
parent 7d2dee5a4d
commit 10dcbeb55e
10 changed files with 114 additions and 37 deletions

2
.gitignore vendored

@ -6,3 +6,5 @@ riderModule.iml
.idea
.vscode
nuget_repo
*.redist/out
*.redist/runtimes

@ -1,2 +0,0 @@
out
runtimes

@ -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();
}

@ -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)) \

@ -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 .)

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Quik.StbTrueType.redist</id>
<version>1.0.0</version>
<authors>STBTT Authors, H. Utku Maden</authors>
<owners>utkumaden</owners>
<description>
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.
</description>
<tags>native</tags>
</metadata>
<files>
<file src="runtimes/**" target=""/>
</files>
</package>

@ -0,0 +1,6 @@
#include "quik_stbtt.h"
QUIK_DEFINE_LIB(quik_stbtt);
#define STB_TRUETYPE_IMPLEMENTATION 1
#include "stb/stb_truetype.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

50
lib/quik/quik_common.h Normal file

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

@ -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"
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"