Skip to content

Commit

Permalink
cmake: replace -DZXING_BUILD_READER with #define in Version.h
Browse files Browse the repository at this point in the history
 * ZXVersion.h -> Version.h (with deprecated ZXVersion.h for compatibility)
 * Version.h contains #define ZXING_HAS_READERS and/or ZXING_HAS_WRITERS
 * work around issue with rusts bindgen not knowing about Version.h
  • Loading branch information
axxel committed Mar 10, 2024
1 parent 9351238 commit 8268dde
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 132 deletions.
10 changes: 6 additions & 4 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ if (MSVC)
endif()

set (ZXING_PRIVATE_FLAGS
$<$<BOOL:${BUILD_READERS}>:-DZXING_BUILD_READERS>
$<$<BOOL:${BUILD_WRITERS}>:-DZXING_BUILD_WRITERS>
$<$<BOOL:${BUILD_WRITERS_NEW}>:-DZXING_USE_ZINT>
$<$<BOOL:${BUILD_UNIT_TESTS}>:-DZXING_BUILD_FOR_TEST>
)
Expand Down Expand Up @@ -106,6 +104,7 @@ set (COMMON_FILES
src/ZXAlgorithms.h
src/ZXConfig.h
src/ZXTestSupport.h
src/ZXVersion.h # [[deprecated]]
$<$<BOOL:${BUILD_C_API}>:src/ZXingC.h>
$<$<BOOL:${BUILD_C_API}>:src/ZXingC.cpp>
)
Expand Down Expand Up @@ -208,6 +207,7 @@ set (PUBLIC_HEADERS
src/StructuredAppend.h
src/TextUtfEncoding.h # [[deprecated]]
src/ZXAlgorithms.h
src/ZXVersion.h # [[deprecated]]
$<$<BOOL:${BUILD_C_API}>:${CMAKE_CURRENT_SOURCE_DIR}/src/ZXingC.h>
)
if (BUILD_READERS)
Expand Down Expand Up @@ -599,10 +599,12 @@ install (
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ZXing"
)

configure_file (ZXVersion.h.in ZXVersion.h)
set(ZXING_HAS_READERS ${BUILD_READERS})
set(ZXING_HAS_WRITERS ${BUILD_WRITERS})
configure_file (Version.h.in Version.h)

install (
FILES "${CMAKE_CURRENT_BINARY_DIR}/ZXVersion.h"
FILES "${CMAKE_CURRENT_BINARY_DIR}/Version.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ZXing"
)

Expand Down
9 changes: 4 additions & 5 deletions core/ZXVersion.h.in → core/Version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

#pragma once

#cmakedefine ZXING_HAS_READERS
#cmakedefine ZXING_HAS_WRITERS

// Version numbering
#define ZXING_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
#define ZXING_VERSION_MINOR @PROJECT_VERSION_MINOR@
#define ZXING_VERSION_PATCH @PROJECT_VERSION_PATCH@

namespace ZXing {

constexpr const char* ZXING_VERSION_STR = "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@";

}
#define ZXING_VERSION_STR "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@"
10 changes: 10 additions & 0 deletions core/src/ZXVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright 2024 Axel Waggershauser
*/
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "Version.h"

#pragma message("Header `ZXVersion.h` is deprecated, please include `Version.h`.")
6 changes: 3 additions & 3 deletions core/src/ZXingC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static uint8_t* copy(const ByteArray& ba, int* len) noexcept
} \
ZX_CATCH({})

#ifdef ZXING_BUILD_READERS
#ifdef ZXING_HAS_READERS
static std::tuple<Barcodes, bool> ReadBarcodesAndSetLastError(const ZXing_ImageView* iv, const ZXing_ReaderOptions* opts,
int maxSymbols)
{
Expand Down Expand Up @@ -250,7 +250,7 @@ ZXing_Barcode* ZXing_Barcodes_move(ZXing_Barcodes* barcodes, int i)
ZX_TRY(new Barcode(std::move((*barcodes)[i])));
}

#ifdef ZXING_BUILD_READERS
#ifdef ZXING_HAS_READERS

/*
* ZXing/ReaderOptions.h
Expand Down Expand Up @@ -319,7 +319,7 @@ ZXing_Barcodes* ZXing_ReadBarcodes(const ZXing_ImageView* iv, const ZXing_Reader

#endif

#ifdef ZXING_BUILD_WRITERS
#ifdef ZXING_HAS_WRITERS
#ifdef ZXING_BUILD_EXPERIMENTAL_API
/*
* ZXing/WriteBarcode.h
Expand Down
170 changes: 99 additions & 71 deletions core/src/ZXingC.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,56 @@
#include <stdbool.h>
#include <stdint.h>

#if __has_include("Version.h")
#include "Version.h"
#else
#define ZXING_HAS_READERS
#endif

#ifdef __cplusplus

#include "Barcode.h"
#include "ImageView.h"

typedef ZXing::Barcode ZXing_Barcode;
typedef ZXing::Barcodes ZXing_Barcodes;
typedef ZXing::ImageView ZXing_ImageView;
typedef ZXing::Image ZXing_Image;

#ifdef ZXING_HAS_READERS
#include "ReaderOptions.h"

typedef ZXing::ReaderOptions ZXing_ReaderOptions;
#endif

#ifdef ZXING_BUILD_EXPERIMENTAL_API
#ifdef ZXING_HAS_WRITERS
#include "WriteBarcode.h"
typedef ZXing::CreatorOptions ZXing_CreatorOptions;
typedef ZXing::WriterOptions ZXing_WriterOptions;
#else
typedef struct ZXing_CreatorOptions ZXing_CreatorOptions;
typedef struct ZXing_WriterOptions ZXing_WriterOptions;
#endif

typedef ZXing::ImageView ZXing_ImageView;
typedef ZXing::Image ZXing_Image;
typedef ZXing::ReaderOptions ZXing_ReaderOptions;
typedef ZXing::Barcode ZXing_Barcode;
typedef ZXing::Barcodes ZXing_Barcodes;
#endif

extern "C"
{
#else

typedef struct ZXing_Barcode ZXing_Barcode;
typedef struct ZXing_Barcodes ZXing_Barcodes;
typedef struct ZXing_ImageView ZXing_ImageView;
typedef struct ZXing_Image ZXing_Image;

#ifdef ZXING_HAS_READERS
typedef struct ZXing_ReaderOptions ZXing_ReaderOptions;
#endif

#ifdef ZXING_HAS_WRITERS
typedef struct ZXing_CreatorOptions ZXing_CreatorOptions;
typedef struct ZXing_WriterOptions ZXing_WriterOptions;
typedef struct ZXing_Barcode ZXing_Barcode;
typedef struct ZXing_Barcodes ZXing_Barcodes;
#endif

#endif

Expand Down Expand Up @@ -122,6 +140,69 @@ ZXing_BarcodeFormats ZXing_BarcodeFormatsFromString(const char* str);
ZXing_BarcodeFormat ZXing_BarcodeFormatFromString(const char* str);
char* ZXing_BarcodeFormatToString(ZXing_BarcodeFormat format);

/*
* ZXing/Barcode.h
*/

typedef enum
{
ZXing_ContentType_Text,
ZXing_ContentType_Binary,
ZXing_ContentType_Mixed,
ZXing_ContentType_GS1,
ZXing_ContentType_ISO15434,
ZXing_ContentType_UnknownECI
} ZXing_ContentType;

typedef enum
{
ZXing_ErrorType_None,
ZXing_ErrorType_Format,
ZXing_ErrorType_Checksum,
ZXing_ErrorType_Unsupported
} ZXing_ErrorType;

char* ZXing_ContentTypeToString(ZXing_ContentType type);

typedef struct ZXing_PointI
{
int x, y;
} ZXing_PointI;

typedef struct ZXing_Position
{
ZXing_PointI topLeft, topRight, bottomRight, bottomLeft;
} ZXing_Position;

char* ZXing_PositionToString(ZXing_Position position);

bool ZXing_Barcode_isValid(const ZXing_Barcode* barcode);
ZXing_ErrorType ZXing_Barcode_errorType(const ZXing_Barcode* barcode);
char* ZXing_Barcode_errorMsg(const ZXing_Barcode* barcode);
ZXing_BarcodeFormat ZXing_Barcode_format(const ZXing_Barcode* barcode);
ZXing_ContentType ZXing_Barcode_contentType(const ZXing_Barcode* barcode);
uint8_t* ZXing_Barcode_bytes(const ZXing_Barcode* barcode, int* len);
uint8_t* ZXing_Barcode_bytesECI(const ZXing_Barcode* barcode, int* len);
char* ZXing_Barcode_text(const ZXing_Barcode* barcode);
char* ZXing_Barcode_ecLevel(const ZXing_Barcode* barcode);
char* ZXing_Barcode_symbologyIdentifier(const ZXing_Barcode* barcode);
ZXing_Position ZXing_Barcode_position(const ZXing_Barcode* barcode);
int ZXing_Barcode_orientation(const ZXing_Barcode* barcode);
bool ZXing_Barcode_hasECI(const ZXing_Barcode* barcode);
bool ZXing_Barcode_isInverted(const ZXing_Barcode* barcode);
bool ZXing_Barcode_isMirrored(const ZXing_Barcode* barcode);
int ZXing_Barcode_lineCount(const ZXing_Barcode* barcode);

void ZXing_Barcode_delete(ZXing_Barcode* barcode);
void ZXing_Barcodes_delete(ZXing_Barcodes* barcodes);

int ZXing_Barcodes_size(const ZXing_Barcodes* barcodes);
const ZXing_Barcode* ZXing_Barcodes_at(const ZXing_Barcodes* barcodes, int i);
ZXing_Barcode* ZXing_Barcodes_move(ZXing_Barcodes* barcodes, int i);


#ifdef ZXING_HAS_READERS

/*
* ZXing/ReaderOptions.h
*/
Expand Down Expand Up @@ -179,59 +260,6 @@ ZXing_TextMode ZXing_ReaderOptions_getTextMode(const ZXing_ReaderOptions* opts);
int ZXing_ReaderOptions_getMinLineCount(const ZXing_ReaderOptions* opts);
int ZXing_ReaderOptions_getMaxNumberOfSymbols(const ZXing_ReaderOptions* opts);

/*
* ZXing/Barcode.h
*/

typedef enum
{
ZXing_ContentType_Text,
ZXing_ContentType_Binary,
ZXing_ContentType_Mixed,
ZXing_ContentType_GS1,
ZXing_ContentType_ISO15434,
ZXing_ContentType_UnknownECI
} ZXing_ContentType;

typedef enum
{
ZXing_ErrorType_None,
ZXing_ErrorType_Format,
ZXing_ErrorType_Checksum,
ZXing_ErrorType_Unsupported
} ZXing_ErrorType;

char* ZXing_ContentTypeToString(ZXing_ContentType type);

typedef struct ZXing_PointI
{
int x, y;
} ZXing_PointI;

typedef struct ZXing_Position
{
ZXing_PointI topLeft, topRight, bottomRight, bottomLeft;
} ZXing_Position;

char* ZXing_PositionToString(ZXing_Position position);

bool ZXing_Barcode_isValid(const ZXing_Barcode* barcode);
ZXing_ErrorType ZXing_Barcode_errorType(const ZXing_Barcode* barcode);
char* ZXing_Barcode_errorMsg(const ZXing_Barcode* barcode);
ZXing_BarcodeFormat ZXing_Barcode_format(const ZXing_Barcode* barcode);
ZXing_ContentType ZXing_Barcode_contentType(const ZXing_Barcode* barcode);
uint8_t* ZXing_Barcode_bytes(const ZXing_Barcode* barcode, int* len);
uint8_t* ZXing_Barcode_bytesECI(const ZXing_Barcode* barcode, int* len);
char* ZXing_Barcode_text(const ZXing_Barcode* barcode);
char* ZXing_Barcode_ecLevel(const ZXing_Barcode* barcode);
char* ZXing_Barcode_symbologyIdentifier(const ZXing_Barcode* barcode);
ZXing_Position ZXing_Barcode_position(const ZXing_Barcode* barcode);
int ZXing_Barcode_orientation(const ZXing_Barcode* barcode);
bool ZXing_Barcode_hasECI(const ZXing_Barcode* barcode);
bool ZXing_Barcode_isInverted(const ZXing_Barcode* barcode);
bool ZXing_Barcode_isMirrored(const ZXing_Barcode* barcode);
int ZXing_Barcode_lineCount(const ZXing_Barcode* barcode);

/*
* ZXing/ReadBarcode.h
*/
Expand All @@ -240,17 +268,10 @@ int ZXing_Barcode_lineCount(const ZXing_Barcode* barcode);
ZXing_Barcode* ZXing_ReadBarcode(const ZXing_ImageView* iv, const ZXing_ReaderOptions* opts);
ZXing_Barcodes* ZXing_ReadBarcodes(const ZXing_ImageView* iv, const ZXing_ReaderOptions* opts);

void ZXing_Barcode_delete(ZXing_Barcode* barcode);
void ZXing_Barcodes_delete(ZXing_Barcodes* barcodes);

int ZXing_Barcodes_size(const ZXing_Barcodes* barcodes);
const ZXing_Barcode* ZXing_Barcodes_at(const ZXing_Barcodes* barcodes, int i);
ZXing_Barcode* ZXing_Barcodes_move(ZXing_Barcodes* barcodes, int i);
#endif /* ZXING_HAS_READERS */

/* ZXing_LastErrorMsg() returns NULL in case there is no last error and a copy of the string otherwise. */
char* ZXing_LastErrorMsg();

void ZXing_free(void* ptr);
#ifdef ZXING_HAS_WRITERS
#ifdef ZXING_BUILD_EXPERIMENTAL_API

/*
* ZXing/WriteBarcode.h
Expand Down Expand Up @@ -298,6 +319,13 @@ ZXing_Barcode* ZXing_CreateBarcodeFromBytes(const void* data, int size, const ZX
char* ZXing_WriteBarcodeToSVG(const ZXing_Barcode* barcode, const ZXing_WriterOptions* opts);
ZXing_Image* ZXing_WriteBarcodeToImage(const ZXing_Barcode* barcode, const ZXing_WriterOptions* opts);

#endif /* ZXING_HAS_WRITERS */
#endif /* ZXING_BUILD_EXPERIMENTAL_API */

/* ZXing_LastErrorMsg() returns NULL in case there is no last error and a copy of the string otherwise. */
char* ZXing_LastErrorMsg();

void ZXing_free(void* ptr);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion example/ZXingReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "GTIN.h"
#include "ReadBarcode.h"
#include "ZXVersion.h"
#include "Version.h"

#ifdef ZXING_BUILD_EXPERIMENTAL_API
#include "WriteBarcode.h"
Expand Down
6 changes: 2 additions & 4 deletions example/ZXingWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
*/
// SPDX-License-Identifier: Apache-2.0

#include "BarcodeFormat.h"
#include "BitMatrixIO.h"

#ifdef ZXING_BUILD_EXPERIMENTAL_API
#include "WriteBarcode.h"
#else
#include "BitMatrix.h"
#include "BitMatrixIO.h"
#include "CharacterSet.h"
#include "MultiFormatWriter.h"
#endif
#include "ZXVersion.h"
#include "Version.h"

#include <algorithm>
#include <cctype>
Expand Down
2 changes: 1 addition & 1 deletion wrappers/c/ZXingCTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main(int argc, char** argv)
CHECK(iv)
} else {
fprintf(stderr, "Could not read image '%s'\n", filename);
#ifdef ZXING_BUILD_EXPERIMENTAL_API
#if defined(ZXING_BUILD_EXPERIMENTAL_API) && defined(ZXING_HAS_WRITERS)
if (formats == ZXing_BarcodeFormat_Invalid)
return 2;
fprintf(stderr, "Using '%s' as text input to create barcode\n", filename);
Expand Down
2 changes: 1 addition & 1 deletion wrappers/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() -> miette::Result<()> {
}

// manual bindings.rs generation:
// bindgen core/src/ZXingC.h -o src/bindings.rs --no-prepend-enum-name --merge-extern-blocks --use-core --no-doc-comments --no-layout-tests --with-derive-partialeq --allowlist-item "ZXing.*"
// bindgen core/src/ZXingC.h -o src/bindings.rs --no-prepend-enum-name --merge-extern-blocks --use-core --no-doc-comments --no-layout-tests --with-derive-partialeq --allowlist-item "ZXing.*" -- -DRUST_BINDGEN

Ok(())
}
Loading

0 comments on commit 8268dde

Please sign in to comment.