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 6d47a36
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 117 deletions.
78 changes: 47 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,43 @@ 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)
set (ZXING_EXAMPLES ${BUILD_EXAMPLES})
endif()
if (DEFINED BUILD_PYTHON_MODULE)
set (ZXING_PYTHON_MODULE ${BUILD_PYTHON_MODULE})
endif()
if (DEFINED BUILD_DEPENDENCIES)
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 +86,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 6d47a36

Please sign in to comment.