Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: ZMQ_WIN32_WINNT autodetection broken when cross-compiling with mingw-w64 #4669

Open
fanquake opened this issue Mar 25, 2024 · 0 comments

Comments

@fanquake
Copy link
Contributor

When cross-compiling for Windows on Ubuntu, using mingw-w64, the functionality in the CMake build:

Value to set _WIN32_WINNT to for building [default=autodetect from build environment]

does not work. After configuring with the following:

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \
-DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++

<snip>
-- CURVE security is disabled
-- Detected _WIN32_WINNT from CMAKE_SYSTEM_VERSION: 
-- Looking for kqueue
<snip>

cmake --build build -j$(nproc) --verbose
....
[  2%] Building CXX object CMakeFiles/libzmq.dir/src/ws_engine.cpp.obj
In file included from /root/libzmq/src/precompiled.hpp:22,
                 from /root/libzmq/src/ws_encoder.cpp:3:
/root/libzmq/src/windows.hpp:21:19: error: operator '>=' has no left operand
   21 | #if (_WIN32_WINNT >= 0x0501)
      |                   ^~
/root/libzmq/src/windows.hpp:23:2: error: #error You need at least Windows XP target
   23 | #error You need at least Windows XP target
      |  ^~~~~
/usr/bin/x86_64-w64-mingw32-g++ -DFD_SETSIZE=16384 -DZMQ_BUILD_DRAFT_API -DZMQ_CUSTOM_PLATFORM_HPP -DZMQ_STATIC -D_CRT_SECURE_NO_WARNINGS -D_REENTRANT -D_THREAD_SAFE -D_WIN32_WINNT="" -D_WINSOCK_DEPRECATED_NO_WARNINGS @CMakeFiles/libzmq-static.dir/includes_CXX.rsp -std=c++11 -Wno-tautological-constant-compare -O3 -DNDEBUG -MD -MT CMakeFiles/libzmq-static.dir/src/ws_address.cpp.obj -MF CMakeFiles/libzmq-static.dir/src/ws_address.cpp.obj.d -o CMakeFiles/libzmq-static.dir/src/ws_address.cpp.obj -c /root/libzmq/src/ws_address.cpp
/usr/bin/x86_64-w64-mingw32-g++ -DFD_SETSIZE=16384 -DZMQ_BUILD_DRAFT_API -DZMQ_CUSTOM_PLATFORM_HPP -DZMQ_STATIC -D_CRT_SECURE_NO_WARNINGS -D_REENTRANT -D_THREAD_SAFE -D_WIN32_WINNT="" -D_WINSOCK_DEPRECATED_NO_WARNINGS @CMakeFiles/libzmq-static.dir/includes_CXX.rsp -std=c++11 -Wno-tautological-constant-compare -O3 -DNDEBUG -MD -MT CMakeFiles/libzmq-static.dir/src/ws_connecter.cpp.obj -MF CMakeFiles/libzmq-static.dir/src/ws_connecter.cpp.obj.d -o CMakeFiles/libzmq-static.dir/src/ws_connecter.cpp.obj -c /root/libzmq/src/ws_connecter.cpp
/usr/bin/x86_64-w64-mingw32-g++ -DFD_SETSIZE=16384 -DZMQ_BUILD_DRAFT_API -DZMQ_CUSTOM_PLATFORM_HPP -DZMQ_STATIC -D_CRT_SECURE_NO_WARNINGS -D_REENTRANT -D_THREAD_SAFE -D_WIN32_WINNT="" -D_WINSOCK_DEPRECATED_NO_WARNINGS @CMakeFiles/libzmq-static.dir/includes_CXX.rsp -std=c++11 -Wno-tautological-constant-compare -O3 -DNDEBUG -MD -MT CMakeFiles/libzmq-static.dir/src/ws_encoder.cpp.obj -MF CMakeFiles/libzmq-static.dir/src/ws_encoder.cpp.obj.d -o CMakeFiles/libzmq-static.dir/src/ws_encoder.cpp.obj -c /root/libzmq/src/ws_encoder.cpp
/usr/bin/x86_64-w64-mingw32-g++ -DDLL_EXPORT -DFD_SETSIZE=16384 -DZMQ_BUILD_DRAFT_API -DZMQ_CUSTOM_PLATFORM_HPP -D_CRT_SECURE_NO_WARNINGS -D_REENTRANT -D_THREAD_SAFE -D_WIN32_WINNT="" -D_WINSOCK_DEPRECATED_NO_WARNINGS -Dlibzmq_EXPORTS @CMakeFiles/libzmq.dir/includes_CXX.rsp -std=c++11 -Wno-tautological-constant-compare -O3 -DNDEBUG -MD -MT CMakeFiles/libzmq.dir/src/ws_decoder.cpp.obj -MF CMakeFiles/libzmq.dir/src/ws_decoder.cpp.obj.d -o CMakeFiles/libzmq.dir/src/ws_decoder.cpp.obj -c /root/libzmq/src/ws_decoder.cpp
In file included from /usr/share/mingw-w64/include/windows.h:10,
                 from /usr/share/mingw-w64/include/winsock2.h:23,
                 from /root/libzmq/src/windows.hpp:27:
/usr/share/mingw-w64/include/sdkddkver.h:192:19: error: operator '<=' has no left operand
  192 | #if (_WIN32_WINNT <= _WIN32_WINNT_NT4)
      |                   ^~
/usr/share/mingw-w64/include/sdkddkver.h:194:21: error: operator '<=' has no left operand
  194 | #elif (_WIN32_WINNT <= _WIN32_WINNT_WIN2K)
      |                     ^~
/usr/share/mingw-w64/include/sdkddkver.h:196:21: error: operator '<=' has no left operand
  196 | #elif (_WIN32_WINNT <= _WIN32_WINNT_WINXP)
      |                     ^~
/usr/share/mingw-w64/include/sdkddkver.h:198:21: error: operator '<=' has no left operand
  198 | #elif (_WIN32_WINNT <= _WIN32_WINNT_WS03)
      |                     ^~
/usr/share/mingw-w64/include/sdkddkver.h:200:21: error: operator '<=' has no left operand
  200 | #elif (_WIN32_WINNT <= _WIN32_WINNT_VISTA)
      |                     ^~
/usr/share/mingw-w64/include/sdkddkver.h:202:21: error: operator '<=' has no left operand
  202 | #elif (_WIN32_WINNT <= _WIN32_WINNT_WIN7)
      |                     ^~
/usr/share/mingw-w64/include/sdkddkver.h:204:21: error: operator '<=' has no left operand
  204 | #elif (_WIN32_WINNT <= _WIN32_WINNT_WIN8)
      |                     ^~
/usr/share/mingw-w64/include/sdkddkver.h:215:61: error: operator '!=' has no left operand
  215 | #if ((OSVER(NTDDI_VERSION) == NTDDI_WIN2K) && (_WIN32_WINNT != _WIN32_WINNT_WIN2K)) || \

After manually setting -DZMQ_WIN32_WINNT=VERSION, things mostly compile as expected (except for a different issue that requires passing -DZMQ_HAVE_IPC=OFF). Althought note that the output is still incorrect, as there mention of autodetection, and still no version printed i.e:

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \
-DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ \
-DZMQ_WIN32_WINNT=0x0601
<snip>
-- CURVE security is disabled
-- Detected _WIN32_WINNT from CMAKE_SYSTEM_VERSION: 
-- Looking for kqueue

Environment

  • libzmq version (commit hash if unreleased): 4a5ece5
  • OS: Ubuntu Noble
  • GCC x86_64-w64-mingw32-g++ (GCC) 13-win32
  • Mingw-w64: 11.0.1

Noticed while porting a project that cross-compiles using Autotools & mingw-w64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant