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

CDRIVER-2080 detect socket API parameters for legacy platforms #427

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 59 additions & 12 deletions CMakeLists.txt
Expand Up @@ -177,26 +177,73 @@ if (MINGW)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_RAND_S")
endif ()


function(mongoc_get_accept_args ARG2 ARG3)
SET(VAR 0)
foreach (ARG2_VAL "struct sockaddr" "void")
foreach (ARG3_VAL "socklen_t" "size_t" "int")

MATH(EXPR VAR "${VAR}+1")

FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/accept_test${VAR}.cxx
"#include <sys/types.h>
#include <sys/socket.h>

int main ()
{
int a = 0;
${ARG2_VAL} *b = 0;
${ARG3_VAL} *c = 0;
accept (a, b, c);
return 0;
}
")

TRY_COMPILE(RES ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/accept_test${VAR}.cxx CMAKE_FLAGS
"-Werror -DCMAKE_CXX_LINK_EXECUTABLE='echo not linking now...'" OUTPUT_VARIABLE LOG2)

if (RES)
message(STATUS "Detected accept args is ${ARG2_VAL} and ${ARG3_VAL}")
set(${ARG2} ${ARG2_VAL} PARENT_SCOPE)
set(${ARG3} ${ARG3_VAL} PARENT_SCOPE)
return ()
endif ()

endforeach()
endforeach()

endfunction()


# Reasonable default. CheckCompiler.m4 checks thoroughly for HP-UX's sake.
set (MONGOC_SOCKET_ARG2 "struct sockaddr")
set (MONGOC_SOCKET_ARG3 "socklen_t")

include(CheckTypeSize)
if (MSVC)
SET(CMAKE_EXTRA_INCLUDE_FILES "ws2tcpip.h")
else()

if (NOT WIN32)

mongoc_get_accept_args(MONGOC_SOCKET_ARG2 MONGOC_SOCKET_ARG3)

include(CheckTypeSize)
SET(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
endif ()
CHECK_TYPE_SIZE(socklen_t HAVE_SOCKLEN)
SET(CMAKE_EXTRA_INCLUDE_FILES)
CHECK_TYPE_SIZE(socklen_t HAVE_SOCKLEN)
SET(CMAKE_EXTRA_INCLUDE_FILES)

if (HAVE_SOCKLEN)
set(MONGOC_HAVE_SOCKLEN 1)
else()
set(MONGOC_HAVE_SOCKLEN 0)
endif()

if (HAVE_SOCKLEN)
set(MONGOC_HAVE_SOCKLEN 1)
set (MONGOC_SOCKET_ARG3 "socklen_t")
else()
set(MONGOC_HAVE_SOCKLEN 0)
set (MONGOC_SOCKET_ARG3 "int")
# WIN32
set(MONGOC_HAVE_SOCKLEN 1)
endif()


message(STATUS "accept arguments type is: ${MONGOC_SOCKET_ARG2} and ${MONGOC_SOCKET_ARG3}")

set (SOURCE_DIR "${PROJECT_SOURCE_DIR}/")

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/build/cmake)
Expand Down