Skip to content

Commit

Permalink
cmake: replace BUILD_... prefix of cmake options with ZXING_...
Browse files Browse the repository at this point in the history
Care has been taken to keep the old names functional for a transition
period. A cmake warning is emitted in this case.
  • Loading branch information
axxel committed Mar 15, 2024
1 parent dedec00 commit 21ed1e0
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 121 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ jobs:
- name: Configure
run: >
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_SHARED_LIBS=ON
-DBUILD_BLACKBOX_TESTS=ON -DBUILD_UNIT_TESTS=ON -DBUILD_PYTHON_MODULE=ON -DBUILD_C_API=ON
-DZXING_READERS=ON -DZXING_WRITERS=ON
-DZXING_BLACKBOX_TESTS=ON -DZXING_UNIT_TESTS=ON -DZXING_PYTHON_MODULE=ON -DZXING_C_API=ON
- name: Build
run: cmake --build build -j8 --config ${{env.BUILD_TYPE}}
Expand Down Expand Up @@ -67,7 +68,8 @@ jobs:
- name: Configure
run: >
cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo
-DBUILD_BLACKBOX_TESTS=ON -DBUILD_UNIT_TESTS=ON -DBUILD_PYTHON_MODULE=OFF -DBUILD_C_API=OFF
-DZXING_READERS=ON -DZXING_WRITERS=ON
-DZXING_BLACKBOX_TESTS=ON -DZXING_UNIT_TESTS=ON -DZXING_PYTHON_MODULE=OFF -DZXING_C_API=OFF
-DCMAKE_CXX_COMPILER=clang++
-DCMAKE_CXX_FLAGS="-march=native -fsanitize=address,undefined -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer"
-DCMAKE_C_COMPILER=clang
Expand Down Expand Up @@ -242,7 +244,7 @@ jobs:
run: >
cmake -S wrappers/winrt -B build -A ARM64
-DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 -DCMAKE_BUILD_TYPE=Release
-DBUILD_WINRT_LIB=ON -DBUILD_EXAMPLES=OFF -DBUILD_BLACKBOX_TESTS=OFF -DBUILD_C_API=OFF
-DBUILD_WINRT_LIB=ON -DZXING_EXAMPLES=OFF -DZXING_BLACKBOX_TESTS=OFF -DZXING_C_API=OFF
-DEXTENSION_SDK_OUTPUT=dist/UAP/v0.8.0.0/ExtensionSDKs/ZXingWinRT/1.0.0.0
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-winrt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Configure CMake
shell: cmd
working-directory: ${{runner.workspace}}/build
run: cmake ${{github.workspace}}/wrappers/winrt -A ${{matrix.target}} -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 -DCMAKE_BUILD_TYPE=Release -DBUILD_WINRT_LIB=ON -DBUILD_EXAMPLES=OFF -DBUILD_BLACKBOX_TESTS=OFF -DEXTENSION_SDK_OUTPUT=dist/UAP/v0.8.0.0/ExtensionSDKs/ZXingWinRT/1.0.0.0
run: cmake ${{github.workspace}}/wrappers/winrt -A ${{matrix.target}} -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 -DCMAKE_BUILD_TYPE=Release -DBUILD_WINRT_LIB=ON -DZXING_EXAMPLES=OFF -DZXING_BLACKBOX_TESTS=OFF -DEXTENSION_SDK_OUTPUT=dist/UAP/v0.8.0.0/ExtensionSDKs/ZXingWinRT/1.0.0.0

- name: Build
shell: cmd
Expand Down
81 changes: 50 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ cmake_minimum_required(VERSION 3.15)

project(ZXing)

# option (BUILD_WRITERS "Build with writer support (encoders)" ON)
set(BUILD_WRITERS "ON" CACHE STRING "Build with old and/or new writer (encoder) backend (OFF/ON/OLD/NEW/BOTH)")
option (BUILD_READERS "Build with reader support (decoders)" ON)
option (BUILD_EXAMPLES "Build the example barcode reader/writer applications" ON)
option (BUILD_BLACKBOX_TESTS "Build the black box reader/writer tests" OFF)
option (BUILD_UNIT_TESTS "Build the unit tests (don't enable for production builds)" OFF)
option (BUILD_PYTHON_MODULE "Build the python module" OFF)
option (BUILD_C_API "Build the C-API" OFF)
option (BUILD_EXPERIMENTAL_API "Build with experimental API" OFF)
option (ZXING_USE_BUNDLED_ZINT "Use the bundled libzint for barcode creation/generation" ON)
set(BUILD_DEPENDENCIES "AUTO" CACHE STRING "Fetch from github or use locally installed (AUTO/GITHUB/LOCAL)")
option (ZXING_READERS "Build with reader support (decoders)" ON)
set (ZXING_WRITERS "ON" CACHE STRING "Build with old and/or new writer (encoder) backend (OFF/ON/OLD/NEW/BOTH)")
option (ZXING_USE_BUNDLED_ZINT "Use the bundled libzint for barcode creation/writing" ON)
option (ZXING_C_API "Build the C-API" OFF)
option (ZXING_EXPERIMENTAL_API "Build with experimental API" OFF)
option (ZXING_EXAMPLES "Build the example barcode reader/writer applications" ON)
option (ZXING_BLACKBOX_TESTS "Build the black box reader/writer tests" OFF)
option (ZXING_UNIT_TESTS "Build the unit tests (don't enable for production builds)" OFF)
option (ZXING_PYTHON_MODULE "Build the python module" OFF)
set (ZXING_DEPENDENCIES "AUTO" CACHE STRING "Fetch from github or use locally installed (AUTO/GITHUB/LOCAL)")

if (WIN32)
option (BUILD_SHARED_LIBS "Build and link as shared library" OFF)
Expand All @@ -22,8 +21,8 @@ endif()

if (MSVC)
add_definitions (-DUNICODE -D_UNICODE -D_CRT_SECURE_NO_WARNINGS)
option (LINK_CPP_STATICALLY "MSVC only, link standard library statically (/MT and /MTd)" OFF)
if (LINK_CPP_STATICALLY)
option (ZXING_LINK_CPP_STATICALLY "MSVC only, link standard library statically (/MT and /MTd)" OFF)
if (LINK_CPP_STATICALLY OR ZXING_LINK_CPP_STATICALLY)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endif()
Expand All @@ -35,26 +34,46 @@ if (NOT CMAKE_BUILD_TYPE)
set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

if (NOT (BUILD_READERS OR BUILD_WRITERS))
message(FATAL_ERROR "At least one of BUILD_READERS/BUILD_WRITERS must be enabled.")
# provide backward compatibility for deprecated BUILD_... options
if (DEFINED BUILD_READERS)
set (ZXING_READERS ${BUILD_READERS})
endif()
if (DEFINED BUILD_WRITERS)
set (ZXING_WRITERS ${BUILD_WRITERS})
endif()
if (DEFINED BUILD_EXAMPLES)
message (WARNING "zxing-cpp cmake options BUILD_... are deprecated, please switch to ZXING_... variant")
set (ZXING_EXAMPLES ${BUILD_EXAMPLES})
endif()
if (DEFINED BUILD_PYTHON_MODULE)
message (WARNING "zxing-cpp cmake options BUILD_... are deprecated, please switch to ZXING_... variant")
set (ZXING_PYTHON_MODULE ${BUILD_PYTHON_MODULE})
endif()
if (DEFINED BUILD_DEPENDENCIES)
message (WARNING "zxing-cpp cmake options BUILD_... are deprecated, please switch to ZXING_... variant")
set (ZXING_DEPENDENCIES ${BUILD_DEPENDENCIES})
endif()

if (NOT (ZXING_READERS OR ZXING_WRITERS))
message(FATAL_ERROR "At least one of ZXING_READERS/ZXING_WRITERS must be enabled.")
endif()

if (BUILD_UNIT_TESTS AND (NOT BUILD_WRITERS OR NOT BUILD_READERS))
if (ZXING_UNIT_TESTS AND (NOT ZXING_WRITERS OR NOT ZXING_READERS))
message("Note: To build with unit tests, the library will be build with READERS and WRITERS.")
set (BUILD_WRITERS ON)
set (BUILD_READERS ON)
set (ZXING_WRITERS ON)
set (ZXING_READERS ON)
endif()

set(BUILD_WRITERS_LIST OFF ON OLD NEW BOTH)
set_property(CACHE BUILD_WRITERS PROPERTY STRINGS ${BUILD_WRITERS_LIST})
if(NOT BUILD_WRITERS IN_LIST BUILD_WRITERS_LIST)
message(FATAL_ERROR "BUILD_WRITERS must be one of ${BUILD_WRITERS_LIST}")
set(ZXING_WRITERS_LIST OFF ON OLD NEW BOTH)
set_property(CACHE ZXING_WRITERS PROPERTY STRINGS ${ZXING_WRITERS_LIST})
if(NOT ZXING_WRITERS IN_LIST ZXING_WRITERS_LIST)
message(FATAL_ERROR "ZXING_WRITERS must be one of ${ZXING_WRITERS_LIST}")
endif()

set(BUILD_DEPENDENCIES_LIST AUTO GITHUB LOCAL)
set_property(CACHE BUILD_DEPENDENCIES PROPERTY STRINGS ${BUILD_DEPENDENCIES_LIST})
if(NOT BUILD_DEPENDENCIES IN_LIST BUILD_DEPENDENCIES_LIST)
message(FATAL_ERROR "BUILD_DEPENDENCIES must be one of ${BUILD_DEPENDENCIES_LIST}")
set(ZXING_DEPENDENCIES_LIST AUTO GITHUB LOCAL)
set_property(CACHE ZXING_DEPENDENCIES PROPERTY STRINGS ${ZXING_DEPENDENCIES_LIST})
if(NOT ZXING_DEPENDENCIES IN_LIST ZXING_DEPENDENCIES_LIST)
message(FATAL_ERROR "ZXING_DEPENDENCIES must be one of ${ZXING_DEPENDENCIES_LIST}")
endif()

if (NOT DEFINED CMAKE_CXX_STANDARD)
Expand All @@ -70,18 +89,18 @@ enable_testing()

include(zxing.cmake)

if (BUILD_EXAMPLES)
if (ZXING_EXAMPLES)
add_subdirectory (example)
endif()
if (BUILD_BLACKBOX_TESTS)
if (ZXING_BLACKBOX_TESTS)
add_subdirectory (test/blackbox)
endif()
if (BUILD_UNIT_TESTS)
if (ZXING_UNIT_TESTS)
add_subdirectory (test/unit)
endif()
if (BUILD_PYTHON_MODULE)
if (ZXING_PYTHON_MODULE)
add_subdirectory (wrappers/python)
endif()
if (BUILD_C_API)
if (ZXING_C_API)
add_subdirectory (wrappers/c)
endif()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ These are the generic instructions to build the library on Windows/macOS/Linux.
1. Make sure [CMake](https://cmake.org) version 3.15 or newer is installed.
2. Make sure a C++17 compliant compiler is installed (minimum VS 2019 16.8 / gcc 7 / clang 5).
3. See the cmake `BUILD_...` options to enable the testing code, python wrapper, etc.
3. See the cmake `ZXING_...` options to enable the testing code, python wrapper, etc.
```
git clone https://github.com/zxing-cpp/zxing-cpp.git --single-branch --depth 1
Expand Down
Loading

0 comments on commit 21ed1e0

Please sign in to comment.