CMakeLists.txt 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. cmake_minimum_required(VERSION 3.18)
  2. project(ZXingPython)
  3. # check if we are called from the top-level ZXing project
  4. get_directory_property(hasParent PARENT_DIRECTORY)
  5. if (NOT hasParent)
  6. # Build with C++20 by default (which enables position independent DataMatrix detection).
  7. set(CMAKE_CXX_STANDARD 20)
  8. set(CMAKE_CXX_EXTENSIONS OFF)
  9. # Allow the fallback to earlier versions if the compiler does not support it.
  10. set(CMAKE_CXX_STANDARD_REQUIRED OFF)
  11. option (BUILD_SHARED_LIBS "Link python module to shared lib" OFF)
  12. option (ZXING_READERS "Build with reader support (decoders)" ON)
  13. set (ZXING_WRITERS "NEW" CACHE STRING "Build with old and/or new writer (encoder) backend (OFF/ON/OLD/NEW)")
  14. set (ZXING_DEPENDENCIES "AUTO" CACHE STRING "Fetch from github or use locally installed (AUTO/GITHUB/LOCAL)")
  15. option (ZXING_EXPERIMENTAL_API "Build with experimental API" ON)
  16. option (ZXING_USE_BUNDLED_ZINT "Use the bundled libzint for barcode creation/generation" ON)
  17. set(CORE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/core)
  18. if(IS_SYMLINK ${CORE_PATH})
  19. # This is needed because otherwise GCC resolves the symlink which causes paths to randomly
  20. # be prefixed by /core or by /wrappers/python/core depending on include order.
  21. set(CORE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../core)
  22. endif()
  23. if(EXISTS ${CORE_PATH})
  24. add_subdirectory(${CORE_PATH} ZXing EXCLUDE_FROM_ALL)
  25. include(${CMAKE_CURRENT_SOURCE_DIR}/zxing.cmake)
  26. else()
  27. message(FATAL_ERROR "Unable to locate zxing source code")
  28. endif()
  29. endif()
  30. find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED) # see https://github.com/pybind/pybind11/issues/4785
  31. set(PYBIND11_FINDPYTHON ON) # see https://github.com/pybind/pybind11/issues/4785
  32. zxing_add_package(pybind11 pybind11 https://github.com/pybind/pybind11.git v2.13.6)
  33. # build the python module
  34. pybind11_add_module(zxingcpp zxing.cpp)
  35. target_link_libraries(zxingcpp PRIVATE ZXing::ZXing)
  36. if (ZXING_READERS AND ZXING_WRITERS)
  37. add_test(NAME PythonTest COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test.py -v)
  38. set_property(TEST PythonTest PROPERTY ENVIRONMENT PYTHONPATH=$<TARGET_FILE_DIR:zxingcpp>)
  39. endif()
  40. if (NOT DEFINED ZXING_PYTHON_INSTALL_BINDIR)
  41. set(ZXING_PYTHON_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}")
  42. endif()
  43. if (NOT DEFINED ZXING_PYTHON_INSTALL_LIBDIR)
  44. set(ZXING_PYTHON_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
  45. endif()
  46. install(TARGETS zxingcpp
  47. COMPONENT python
  48. RUNTIME DESTINATION "${ZXING_PYTHON_INSTALL_BINDIR}"
  49. LIBRARY DESTINATION "${ZXING_PYTHON_INSTALL_LIBDIR}"
  50. ARCHIVE DESTINATION "${ZXING_PYTHON_INSTALL_LIBDIR}")