Skip to content

Commit f6f6844

Browse files
committed
Attempt to fix Windows build
1 parent c3c0688 commit f6f6844

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,20 @@ FetchContent_MakeAvailable(fpcap)
3535
pybind11_add_module(_fpcap src/bindings.cpp)
3636
target_link_libraries(_fpcap PRIVATE fpcap::fpcap)
3737

38-
# Disable MSVC C++20 module scanning (we don't use C++ modules and the scanner
39-
# fails on Windows because it lacks platform architecture defines)
40-
set_target_properties(_fpcap PROPERTIES CXX_SCAN_FOR_MODULES OFF)
38+
if(MSVC)
39+
# Disable MSVC C++20 module scanning (we don't use C++ modules and the scanner
40+
# fails on Windows because it lacks platform architecture defines)
41+
set_target_properties(_fpcap PROPERTIES CXX_SCAN_FOR_MODULES OFF)
42+
43+
# Fix "No Target Architecture" error: Python.h pulls in winnt.h which needs
44+
# _AMD64_/_X86_/_ARM64_ defined. MSVC defines _M_AMD64 intrinsically, but the
45+
# macro-to-define chain in winnt.h can fail with certain header include orders
46+
# (Python.h + C++20 + recent Windows SDK). Define the architecture explicitly.
47+
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
48+
target_compile_definitions(_fpcap PRIVATE _AMD64_)
49+
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
50+
target_compile_definitions(_fpcap PRIVATE _X86_)
51+
endif()
52+
endif()
4153

4254
install(TARGETS _fpcap LIBRARY DESTINATION .)

0 commit comments

Comments
 (0)