Skip to content

Added a feature test to auto enable/disable CPPHTTPLIB_USE_NON_BLOCKI… - #2578

Open
TobiasWallner wants to merge 1 commit into
yhirose:masterfrom
TobiasWallner:auto_getaddrinfo
Open

Added a feature test to auto enable/disable CPPHTTPLIB_USE_NON_BLOCKI…#2578
TobiasWallner wants to merge 1 commit into
yhirose:masterfrom
TobiasWallner:auto_getaddrinfo

Conversation

@TobiasWallner

Copy link
Copy Markdown

Summary

Add CMake feature detection for CPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO on Windows.

When HTTPLIB_USE_NON_BLOCKING_GETADDRINFO is enabled, CMake now checks whether GetAddrInfoExCancel is available before exporting CPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO through the httplib::httplib target. If the symbol is not available, the non-blocking getaddrinfo support is disabled automatically.

Motivation

Some Windows machines/toolchains do not provide GetAddrInfoExCancel, which causes downstream projects using cpp-httplib via CMake to fail compilation when CPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO is exported unconditionally.

Previously, consumers had to work around this by manually removing the interface compile definition from httplib::httplib. With this change, cpp-httplib configures itself correctly out of the box.

Testing

Verified on a Windows machine where GetAddrInfoExCancel is unavailable:

  • CMake reports GetAddrInfoExCancel - not found
  • HTTPLIB_IS_USING_NON_BLOCKING_GETADDRINFO is set to FALSE
  • CPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO is not present on the consumer compile line
  • compiled-library mode builds successfully

@yhirose

yhirose commented Sep 7, 2026

Copy link
Copy Markdown
Owner

@sum01 @jimmy-park @Tachi107 this PR looks good to me. Could you please take a look at it?

@yhirose

yhirose commented Sep 8, 2026

Copy link
Copy Markdown
Owner

@TobiasWallner could you take a look at the CI failures of test / windows with SSL and test /windows without SSL? (You don't need to worry about other failures.)

Comment thread CMakeLists.txt

if(NOT HTTPLIB_HAVE_GETADDRINFOEXCANCEL)
set(HTTPLIB_IS_USING_NON_BLOCKING_GETADDRINFO FALSE)
message(STATUS "GetAddrInfoExCancel is unavailable; disabling non-blocking getaddrinfo.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it probably be better to use either WARNING or even FATAL_ERROR here?

I'm not sure what people would prefer personally, but having the build stop makes some sense to me, as it's an explicitly enabled option that will not work/be supported.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, i would use a warning, because the user might still want to compile it and provide the function by itself or link something that cmake does not see at this point.

@yhirose

yhirose commented Sep 14, 2026

Copy link
Copy Markdown
Owner

@TobiasWallner, since the master branch has progressed quite a bit, please run rebase master.

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

Successfully merging this pull request may close these issues.

4 participants