Skip to content

Commit

Permalink
cmake: add new experimental SupportedBarcodeFormats API
Browse files Browse the repository at this point in the history
* reorganize building such that both reader (and new creator) APIs are
  always present but might fail on every call, depending on build mode
* new ZXingCpp.h as single point of entry for c++ API (similar to ZXingC.h)
* fix a few build issues with prior untested configurations
  • Loading branch information
axxel committed Mar 19, 2024
1 parent 6d398a3 commit df04899
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 134 deletions.
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ let package = Package(
name: "ZXingCppCore",
path: "core/src",
exclude: ["libzint"],
publicHeadersPath: "."
publicHeadersPath: ".",
cxxSettings: [
.define("ZXING_READERS")
]
),
.target(
name: "ZXingCpp",
Expand Down
52 changes: 25 additions & 27 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,15 @@ set (COMMON_FILES
src/Point.h
src/Quadrilateral.h
src/Range.h
src/ReaderOptions.h
src/ReadBarcode.h
src/ReadBarcode.cpp
src/Utf.h
src/Utf.cpp
src/WriteBarcode.h
src/WriteBarcode.cpp
src/ZXingCpp.h
src/ZXingCpp.cpp
src/ZXAlgorithms.h
src/ZXConfig.h
src/ZXTestSupport.h
Expand Down Expand Up @@ -165,9 +172,6 @@ if (ZXING_READERS)
src/PerspectiveTransform.h
src/PerspectiveTransform.cpp
src/Reader.h
src/ReaderOptions.h
src/ReadBarcode.h
src/ReadBarcode.cpp
src/ReedSolomonDecoder.h
src/ReedSolomonDecoder.cpp
src/RegressionLine.h
Expand All @@ -186,8 +190,6 @@ endif()

if (ZXING_WRITERS)
set (COMMON_FILES ${COMMON_FILES}
src/WriteBarcode.h
src/WriteBarcode.cpp
)
endif()

Expand Down Expand Up @@ -217,25 +219,22 @@ set (PUBLIC_HEADERS
src/ImageView.h
src/Point.h
src/Quadrilateral.h
src/ReadBarcode.h
src/ReaderOptions.h
src/StructuredAppend.h
src/TextUtfEncoding.h # [[deprecated]]
src/ZXingCpp.h
src/ZXAlgorithms.h
src/ZXVersion.h # [[deprecated]]
$<$<BOOL:${ZXING_C_API}>:${CMAKE_CURRENT_SOURCE_DIR}/src/ZXingC.h>
$<$<BOOL:${ZXING_EXPERIMENTAL_API}>:${CMAKE_CURRENT_SOURCE_DIR}/src/WriteBarcode.h>
)
if (ZXING_READERS)
set (PUBLIC_HEADERS ${PUBLIC_HEADERS}
src/DecodeHints.h # [[deprecated]]
src/ReadBarcode.h
src/ReaderOptions.h
src/Result.h # [[deprecated]]
)
endif()
if (ZXING_WRITERS)
set (PUBLIC_HEADERS ${PUBLIC_HEADERS}
$<$<BOOL:${ZXING_EXPERIMENTAL_API}>:${CMAKE_CURRENT_SOURCE_DIR}/src/WriteBarcode.h>
)
endif()
if (ZXING_WRITERS_OLD)
set (PUBLIC_HEADERS ${PUBLIC_HEADERS}
src/BitMatrix.h
Expand Down Expand Up @@ -476,26 +475,13 @@ if (ZXING_WRITERS_OLD)
)
endif()

set (LIBZUECI_FILES
src/libzueci/zueci.c
src/libzueci/zueci.h
)

if (NOT ZXING_READERS)
set_source_files_properties(src/libzueci/zueci.c PROPERTIES COMPILE_FLAGS -DZUECI_EMBED_NO_TO_UTF)
endif()
if (NOT ZXING_WRITERS_OLD)
set_source_files_properties(src/libzueci/zueci.c PROPERTIES COMPILE_FLAGS -DZUECI_EMBED_NO_TO_ECI)
endif()

source_group (Sources FILES ${COMMON_FILES})
source_group (Sources\\aztec FILES ${AZTEC_FILES})
source_group (Sources\\datamatrix FILES ${DATAMATRIX_FILES})
source_group (Sources\\maxicode FILES ${MAXICODE_FILES})
source_group (Sources\\oned FILES ${ONED_FILES})
source_group (Sources\\pdf417 FILES ${PDF417_FILES})
source_group (Sources\\qrcode FILES ${QRCODE_FILES})
source_group (Sources\\libzueci FILES ${LIBZUECI_FILES})

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
Expand All @@ -509,7 +495,6 @@ add_library (ZXing
${ONED_FILES}
${PDF417_FILES}
${QRCODE_FILES}
${LIBZUECI_FILES}
)

target_include_directories (ZXing
Expand All @@ -526,11 +511,25 @@ target_compile_features(ZXing PUBLIC cxx_std_17)

target_link_libraries (ZXing PRIVATE Threads::Threads)

if (ZXING_READERS OR ZXING_WRITERS_OLD)
set (LIBZUECI_FILES
src/libzueci/zueci.c
src/libzueci/zueci.h
)
set_source_files_properties(${LIBZUECI_FILES} PROPERTIES
COMPILE_FLAGS "$<$<NOT:$<BOOL:${ZXING_READERS}>>:-DZUECI_EMBED_NO_TO_UTF> $<$<NOT:$<BOOL:${ZXING_WRITERS_OLD}>>:-DZUECI_EMBED_NO_TO_ECI>"
SKIP_PRECOMPILE_HEADERS ON
)
target_sources(ZXing PRIVATE ${LIBZUECI_FILES})
source_group (Sources\\libzueci FILES ${LIBZUECI_FILES})
endif()

if (ZXING_WRITERS_NEW)
if (ZXING_USE_BUNDLED_ZINT)
aux_source_directory(src/libzint LIBZINT_FILES) # manually re-run cmake after adding a new file/symlink
set_source_files_properties(${LIBZINT_FILES} PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
target_sources(ZXing PRIVATE ${LIBZINT_FILES})
source_group (Sources\\libzint FILES ${LIBZINT_FILES})
target_include_directories (ZXing PRIVATE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/libzint>")
else()
include(../zxing.cmake)
Expand Down Expand Up @@ -561,7 +560,6 @@ list(REMOVE_ITEM PRECOMPILE_HEADERS src/DecodeHints.h) # [[deprecated]]
list(REMOVE_ITEM PRECOMPILE_HEADERS src/Result.h) # [[deprecated]]
list(REMOVE_ITEM PRECOMPILE_HEADERS src/ZXVersion.h) # [[deprecated]]
target_precompile_headers(ZXing PRIVATE ${PRECOMPILE_HEADERS})
set_source_files_properties(src/libzueci/zueci.c PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
set_source_files_properties(src/DecodeHints.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON)

if(CMAKE_BUILD_TYPE STREQUAL "Release")
Expand Down
23 changes: 22 additions & 1 deletion core/src/ReadBarcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@

#include "ReadBarcode.h"

#include "ReaderOptions.h"
#if !defined(ZXING_READERS) && !defined(ZXING_WRITERS)
#include "Version.h"
#endif

#ifdef ZXING_READERS
#include "GlobalHistogramBinarizer.h"
#include "HybridBinarizer.h"
#include "MultiFormatReader.h"
#include "Pattern.h"
#include "ThresholdBinarizer.h"
#endif

#include <climits>
#include <memory>
#include <stdexcept>

namespace ZXing {

#ifdef ZXING_READERS

class LumImage : public Image
{
public:
Expand Down Expand Up @@ -195,4 +202,18 @@ Barcodes ReadBarcodes(const ImageView& _iv, const ReaderOptions& opts)
return res;
}

#else // ZXING_READERS

Barcode ReadBarcode(const ImageView&, const ReaderOptions&)
{
throw std::runtime_error("This build of zxing-cpp does not support reading barcodes.");
}

Barcodes ReadBarcodes(const ImageView&, const ReaderOptions&)
{
throw std::runtime_error("This build of zxing-cpp does not support reading barcodes.");
}

#endif // ZXING_READERS

} // ZXing
Loading

0 comments on commit df04899

Please sign in to comment.