Skip to content

Commit

Permalink
Python: Fix wrapper build on MSVC not having __cplusplus for BitHacks
Browse files Browse the repository at this point in the history
The `BitHacks.h` header needs the `__cplusplus` define to determine
whether to include `<bit>`. The MSVC compiler only defines this when it
is passed the `/Zc:__cplusplus` flag. The main library was already
setting this flag, but it not set when building the Python wrapper,
causing compilation to fail because `countr_zero` and `popcount` are
being used without `<bit>` being included.

Fixes #612
  • Loading branch information
EchterAgo committed Sep 7, 2023
1 parent 81b405b commit 3ace3c1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions wrappers/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ zxing_add_package(pybind11 pybind11 ${pybind11_git_repo} ${pybind11_git_rev})
pybind11_add_module(zxingcpp zxing.cpp)
target_link_libraries(zxingcpp PRIVATE ZXing::ZXing)

if (MSVC)
target_compile_options(zxingcpp PRIVATE /Zc:__cplusplus)
endif()

if (BUILD_READERS AND BUILD_WRITERS)
add_test(NAME PythonTest COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test.py -v)
set_property(TEST PythonTest PROPERTY ENVIRONMENT PYTHONPATH=$<TARGET_FILE_DIR:zxingcpp>)
Expand Down

0 comments on commit 3ace3c1

Please sign in to comment.