CMakeLists.txt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. cmake_minimum_required(VERSION 3.16)
  2. project(ZXing)
  3. option (ZXING_READERS "Build with reader support (decoders)" ON)
  4. set (ZXING_WRITERS "ON" CACHE STRING "Build with old and/or new writer (encoder) backend (OFF/ON/OLD/NEW/BOTH)")
  5. option (ZXING_USE_BUNDLED_ZINT "Use the bundled libzint for barcode creation/writing" ON)
  6. option (ZXING_C_API "Build the C-API" OFF)
  7. option (ZXING_EXPERIMENTAL_API "Build with experimental API" OFF)
  8. option (ZXING_EXAMPLES "Build the example barcode reader/writer applications" ON)
  9. option (ZXING_BLACKBOX_TESTS "Build the black box reader/writer tests" OFF)
  10. option (ZXING_UNIT_TESTS "Build the unit tests (don't enable for production builds)" OFF)
  11. option (ZXING_PYTHON_MODULE "Build the python module" OFF)
  12. set (ZXING_DEPENDENCIES "AUTO" CACHE STRING "Fetch from github or use locally installed (AUTO/GITHUB/LOCAL)")
  13. if (WIN32)
  14. option (BUILD_SHARED_LIBS "Build and link as shared library" OFF)
  15. else()
  16. option (BUILD_SHARED_LIBS "Build and link as shared library" ON)
  17. endif()
  18. if (MSVC)
  19. add_definitions (-DUNICODE -D_UNICODE -D_CRT_SECURE_NO_WARNINGS)
  20. option (ZXING_LINK_CPP_STATICALLY "MSVC only, link standard library statically (/MT and /MTd)" OFF)
  21. if (LINK_CPP_STATICALLY OR ZXING_LINK_CPP_STATICALLY)
  22. set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
  23. endif()
  24. endif()
  25. if (NOT CMAKE_BUILD_TYPE)
  26. set (DEFAULT_BUILD_TYPE "Release")
  27. message (STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
  28. set (CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE)
  29. set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
  30. endif()
  31. # provide backward compatibility for deprecated BUILD_... options
  32. if (DEFINED BUILD_READERS)
  33. set (ZXING_READERS ${BUILD_READERS})
  34. endif()
  35. if (DEFINED BUILD_WRITERS)
  36. set (ZXING_WRITERS ${BUILD_WRITERS})
  37. endif()
  38. if (DEFINED BUILD_EXAMPLES)
  39. message (WARNING "zxing-cpp cmake options BUILD_... are deprecated, please switch to ZXING_... variant")
  40. set (ZXING_EXAMPLES ${BUILD_EXAMPLES})
  41. endif()
  42. if (DEFINED BUILD_PYTHON_MODULE)
  43. message (WARNING "zxing-cpp cmake options BUILD_... are deprecated, please switch to ZXING_... variant")
  44. set (ZXING_PYTHON_MODULE ${BUILD_PYTHON_MODULE})
  45. endif()
  46. if (DEFINED BUILD_DEPENDENCIES)
  47. message (WARNING "zxing-cpp cmake options BUILD_... are deprecated, please switch to ZXING_... variant")
  48. set (ZXING_DEPENDENCIES ${BUILD_DEPENDENCIES})
  49. endif()
  50. if (NOT (ZXING_READERS OR ZXING_WRITERS))
  51. message(FATAL_ERROR "At least one of ZXING_READERS/ZXING_WRITERS must be enabled.")
  52. endif()
  53. set(ZXING_WRITERS_LIST OFF ON OLD NEW BOTH)
  54. set_property(CACHE ZXING_WRITERS PROPERTY STRINGS ${ZXING_WRITERS_LIST})
  55. if(NOT ZXING_WRITERS IN_LIST ZXING_WRITERS_LIST)
  56. message(FATAL_ERROR "ZXING_WRITERS must be one of ${ZXING_WRITERS_LIST}")
  57. endif()
  58. set(ZXING_DEPENDENCIES_LIST AUTO GITHUB LOCAL)
  59. set_property(CACHE ZXING_DEPENDENCIES PROPERTY STRINGS ${ZXING_DEPENDENCIES_LIST})
  60. if(NOT ZXING_DEPENDENCIES IN_LIST ZXING_DEPENDENCIES_LIST)
  61. message(FATAL_ERROR "ZXING_DEPENDENCIES must be one of ${ZXING_DEPENDENCIES_LIST}")
  62. endif()
  63. if (NOT DEFINED CMAKE_CXX_STANDARD)
  64. set (CMAKE_CXX_STANDARD 20)
  65. # Allow the fallback to earlier versions if the compiler does not support it.
  66. set(CMAKE_CXX_STANDARD_REQUIRED OFF)
  67. endif()
  68. if (NOT DEFINED CMAKE_CXX_EXTENSIONS)
  69. set (CMAKE_CXX_EXTENSIONS OFF)
  70. endif()
  71. add_subdirectory (core)
  72. enable_testing()
  73. include(zxing.cmake)
  74. if (ZXING_EXAMPLES)
  75. add_subdirectory (example)
  76. endif()
  77. if (ZXING_BLACKBOX_TESTS)
  78. add_subdirectory (test/blackbox)
  79. endif()
  80. if (ZXING_UNIT_TESTS)
  81. add_subdirectory (test/unit)
  82. endif()
  83. if (ZXING_PYTHON_MODULE)
  84. add_subdirectory (wrappers/python)
  85. endif()
  86. if (ZXING_C_API)
  87. add_subdirectory (wrappers/c)
  88. endif()