Unverified Commit 17bfe1a1 authored by shiyu1994's avatar shiyu1994 Committed by GitHub
Browse files

Check existence of inet_pton for win32 in CMakeLists.txt (fixes #5019) (#5159)



* check existence of inet_pton for win32 in CMakeLists.txt (fix #5019)

* remove extra spaces

* add check for inet_pton in configure.win

* Update CMakeLists.txt
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>

* Update src/network/socket_wrapper.hpp
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>

* Update src/network/socket_wrapper.hpp
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>

* Update CMakeLists.txt
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>

* Update R-package/configure.win
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>

* Update CMakeLists.txt
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>

* fix comments in CMakeLists.txt

* include check for WIN64

* remove WIN64 flag checks

* fix #ifdef

* Update R-package/configure.win
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>
parent 7b51ee1c
......@@ -324,6 +324,18 @@ if(WIN32 AND MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++")
endif()
# Check if inet_pton is already available, to avoid conflicts with the implementation in LightGBM.
# As of 2022, MinGW started including a definition of inet_pton.
if(WIN32)
include(CheckSymbolExists)
list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32")
check_symbol_exists(inet_pton "ws2tcpip.h" WIN_INET_PTON_FOUND)
if(WIN_INET_PTON_FOUND)
add_definitions(-DWIN_HAS_INET_PTON)
endif()
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "ws2_32")
endif()
if(MSVC)
set(
variables
......
......@@ -70,6 +70,30 @@ then
LGB_CPPFLAGS="${LGB_CPPFLAGS} -DMM_MALLOC=1"
fi
#############
# INET_PTON #
#############
ac_inet_pton="no"
cat > conftest.cpp <<EOL
#include <ws2tcpip.h>
int main() {
void* p = inet_pton;
return 0;
}
EOL
${CXX} ${CXXFLAGS} ${CPPFLAGS} -o conftest conftest.cpp 2>/dev/null && ./conftest && ac_inet_pton="yes"
rm -f ./conftest
rm -f ./conftest.cpp
echo "checking whether INET_PTON works...${ac_inet_pton}"
if test "${ac_inet_pton}" = "yes";
then
LGB_CPPFLAGS="${LGB_CPPFLAGS} -DWIN_HAS_INET_PTON=1"
fi
# Generate Makevars.win from Makevars.win.in
sed -e \
"s/@LGB_CPPFLAGS@/$LGB_CPPFLAGS/" \
......
......@@ -55,11 +55,8 @@ const int INVALID_SOCKET = -1;
#endif
#ifdef _WIN32
#ifndef _UCRT
// Recent MinGW has inet_pton, which then causes compiler error in
// combination with this replacement.
#ifndef _MSC_VER
// not using visual studio in windows
// existence of inet_pton is checked in CMakeLists.txt and configure.win, then stored in WIN_HAS_INET_PTON
#ifndef WIN_HAS_INET_PTON
inline int inet_pton(int af, const char *src, void *dst) {
struct sockaddr_storage ss;
int size = sizeof(ss);
......@@ -84,7 +81,6 @@ inline int inet_pton(int af, const char *src, void *dst) {
}
#endif
#endif
#endif
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment