Skip to content

Commit

Permalink
Define guard macros to prevent windows.h from conflicting with winsoc…
Browse files Browse the repository at this point in the history
…k2.h
  • Loading branch information
hcho3 committed Oct 23, 2024
1 parent c06994b commit 7fc10d3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ if(USE_CUDA)

find_package(CUDAToolkit REQUIRED)
find_package(CCCL CONFIG)
if(NOT CCCL_FOUND)
if(CCCL_FOUND)
message(STATUS "Standalone CCCL found.")
else()
message(STATUS "Standalone CCCL not found. Attempting to use CCCL from CUDA Toolkit...")
find_package(CCCL CONFIG
HINTS ${CUDAToolkit_LIBRARY_DIR}/cmake)
Expand All @@ -238,6 +240,10 @@ if(USE_CUDA)
target_link_libraries(CCCL::CCCL INTERFACE libcudacxx::libcudacxx CUB::CUB Thrust)
endif()
endif()
# Define guard macros to prevent windows.h from conflicting with winsock2.h
if(WIN32)
target_compile_definitions(CCCL::CCCL INTERFACE NOMINMAX WIN32_LEAN_AND_MEAN _WINSOCKAPI_)
endif()
endif()

if(FORCE_COLORED_OUTPUT AND (CMAKE_GENERATOR STREQUAL "Ninja") AND
Expand Down
3 changes: 2 additions & 1 deletion include/xgboost/collective/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ inline auto ThrowAtError(StringView fn_name, std::int32_t errsv = LastError()) {
using SocketT = SOCKET;
#else
using SocketT = int;
#define INVALID_SOCKET -1
#endif // defined(_WIN32)

#if !defined(xgboost_CHECK_SYS_CALL)
Expand Down Expand Up @@ -276,7 +277,7 @@ class TCPSocket {
SockDomain domain_{SockDomain::kV4};
#endif

constexpr static HandleT InvalidSocket() { return -1; }
constexpr static HandleT InvalidSocket() { return INVALID_SOCKET; }

explicit TCPSocket(HandleT newfd) : handle_{newfd} {}

Expand Down
6 changes: 6 additions & 0 deletions include/xgboost/windefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
#endif // !defined(NOMINMAX)

// A macro used inside `windows.h` to avoid conflicts with `winsock2.h`
#if !defined(WIN32_LEAN_AND_MEAN)
#define WIN32_LEAN_AND_MEAN
#endif // !defined(WIN32_LEAN_AND_MEAN)
// Stop windows.h from including winsock.h
#if !defined(_WINSOCKAPI_)
#define _WINSOCKAPI_
#endif // !defined(_WINSOCKAPI_)

#if !defined(xgboost_IS_MINGW)

Expand Down

0 comments on commit 7fc10d3

Please sign in to comment.