Skip to content

Commit 499b4b6

Browse files
committed
enable single-file library use (merge build.h into tinyfseq.h)
1 parent 68f9264 commit 499b4b6

File tree

5 files changed

+20
-45
lines changed

5 files changed

+20
-45
lines changed

CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
cmake_minimum_required(VERSION 3.21)
22

33
project(tinyfseq
4-
VERSION 1.1.0
4+
VERSION 1.2.0
55
DESCRIPTION "A tiny library for decoding FSEQ (.fseq) v2.0+ sequence files"
66
HOMEPAGE_URL "https://github.com/Cryptkeeper/libtinyfseq"
77
LANGUAGES C)
88

99
set(CMAKE_C_STANDARD 90)
1010

11+
# enables you to disable replace all error strings returned by `tf_err_str` with "NULL"
12+
# this reduces the compiled size of the object + memory footprint
13+
#
14+
# you may also `#define TF_STRIP_ERR_STRINGS` prior to including `tinyfseq.h` to disable
15+
# error strings without using CMake
1116
set(TF_INCLUDE_ERR_STRINGS true)
1217

13-
configure_file(${PROJECT_SOURCE_DIR}/build.h.in ${PROJECT_SOURCE_DIR}/build.h)
18+
if (NOT ${TF_INCLUDE_ERR_STRINGS})
19+
add_compile_definitions(TF_STRIP_ERR_STRINGS)
20+
endif ()
1421

1522
add_library(tinyfseq tinyfseq.h tinyfseq.c)
1623

17-
set_target_properties(tinyfseq PROPERTIES PUBLIC_HEADER "tinyfseq.h;build.h")
24+
set_target_properties(tinyfseq PROPERTIES PUBLIC_HEADER "tinyfseq.h")
1825

1926
install(TARGETS tinyfseq
2027
LIBRARY DESTINATION lib/tinyfseq

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ at [Cryptkeeper/fseq-file-format](https://github.com/Cryptkeeper/fseq-file-forma
77

88
## Installation
99

10-
libtinyfseq uses [CMake](https://cmake.org/) for building and packaging the library.
10+
You may either install the library, or use `tinyfseq.h` & `tinyfseq.c` directly as a single-file library. libtinyfseq uses [CMake](https://cmake.org/) for building and packaging the library.
1111

1212
- Generate Makefiles using `cmake .`
1313
- Compile the library using `make`
@@ -18,8 +18,8 @@ If optionally installed, `install_manifest.txt` will be created, containing the
1818

1919
## Build Configuration
2020

21-
For devices with limited memory, a `TF_INCLUDE_ERR_STRINGS` definition is included in [CMakeLists.txt](CMakeLists.txt)
22-
to disable the inclusion of error strings in the build. Calls to `tf_err_str` will instead return `"NULL"` (as a string).
21+
For devices with limited memory, a `TF_INCLUDE_ERR_STRINGS` setting is included in [CMakeLists.txt](CMakeLists.txt)
22+
to disable the inclusion of error strings in the build. Calls to `tf_err_str` will instead return `"NULL"` (as a string). You may also `#define TF_STRIP_ERR_STRINGS` prior to including `tinyfseq.h` to disable error strings without using CMake.
2323

2424
## Compatibility
2525

@@ -37,10 +37,10 @@ to disable the inclusion of error strings in the build. Calls to `tf_err_str` wi
3737
libtinyfseq only defines three functions for reading the various components of a FSEQ file. See [tinyfseq.h](tinyfseq.h)
3838
for comments describing their usage.
3939

40-
| Function | Schema |
41-
| --- | --- |
42-
| `tf_read_file_header` | https://github.com/Cryptkeeper/fseq-file-format#header |
43-
| `tf_read_var_header` | https://github.com/Cryptkeeper/fseq-file-format#variable |
40+
| Function | Schema |
41+
| ----------------------- | ------------------------------------------------------------ |
42+
| `tf_read_file_header` | https://github.com/Cryptkeeper/fseq-file-format#header |
43+
| `tf_read_var_header` | https://github.com/Cryptkeeper/fseq-file-format#variable |
4444
| `tf_read_channel_range` | https://github.com/Cryptkeeper/fseq-file-format#sparse-range |
4545

4646
Two additional utility functions are provided:

build.h.in

Lines changed: 0 additions & 31 deletions
This file was deleted.

tinyfseq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <string.h>
2727

2828
const char *tf_err_str(enum tf_err_t err) {
29-
#ifdef TF_INCLUDE_ERR_STRINGS
29+
#ifndef TF_STRIP_ERR_STRINGS
3030
switch (err) {
3131
case TF_OK:
3232
return "TF_OK (ok)";

tinyfseq.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626

2727
#include <stdint.h>
2828

29-
// `build.h` is generated by CMake using the `build.h.in` template
30-
#include "build.h"
29+
#define TF_LIB_VERSION "1.2.0"
3130

3231
enum tf_err_t {
3332
TF_OK = 0,
@@ -44,7 +43,7 @@ enum tf_err_t {
4443
* `tf_err_str` does not allocate, its return values should not be freed. `tf_err_str` will never return a NULL value.
4544
*
4645
* @param err Unknown/invalid values will default to returning "unknown `tf_err_t` value"
47-
* @return A string version of the given value, or "NULL" (as a string) if the library is built without `TF_INCLUDE_ERR_STRINGS` defined
46+
* @return A string version of the given value, or "NULL" (as a string) if the library is built with `TF_STRIP_ERR_STRINGS` defined
4847
*/
4948
const char *tf_err_str(enum tf_err_t err);
5049

0 commit comments

Comments
 (0)