mirror of https://github.com/getdnsapi/getdns.git
Add support for building on Windows.
This should support both native Visual Studio builds and MinGW builds.
This commit is contained in:
parent
ffe626f5f3
commit
7a0a2f712d
|
@ -30,6 +30,7 @@ set(GETDNS_COMPILATION_COMMENT "${PACKAGE_NAME} ${GETDNS_VERSION} configured on
|
||||||
|
|
||||||
set(GETDNS_LIBVERSION "11:2:1")
|
set(GETDNS_LIBVERSION "11:2:1")
|
||||||
|
|
||||||
|
include(CheckCSourceRuns)
|
||||||
include(CheckFunctionExists)
|
include(CheckFunctionExists)
|
||||||
include(CheckLibraryExists)
|
include(CheckLibraryExists)
|
||||||
include(CheckIncludeFile)
|
include(CheckIncludeFile)
|
||||||
|
@ -68,6 +69,7 @@ include_directories(
|
||||||
if (WIN32 OR MINGW OR MSYS OR CYGWIN)
|
if (WIN32 OR MINGW OR MSYS OR CYGWIN)
|
||||||
set(HOSTOS "windows")
|
set(HOSTOS "windows")
|
||||||
set(GETDNS_ON_WINDOWS 1)
|
set(GETDNS_ON_WINDOWS 1)
|
||||||
|
set(USE_WINSOCK 1)
|
||||||
elseif (APPLE)
|
elseif (APPLE)
|
||||||
set(HOSTOS "macos")
|
set(HOSTOS "macos")
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DARWIN_C_SOURCE")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DARWIN_C_SOURCE")
|
||||||
|
@ -116,13 +118,19 @@ try_compile(HAVE_ATTR_UNUSED
|
||||||
)
|
)
|
||||||
|
|
||||||
# Compiler flags
|
# Compiler flags
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
add_compile_options(/W4 /WX)
|
# The Visual Studio C compiler is C90 with some of C99 and C11.
|
||||||
|
# So full on warnings are not appropriate.
|
||||||
|
add_compile_options(/W2)
|
||||||
else()
|
else()
|
||||||
add_compile_options(-Wall -Wextra)
|
add_compile_options(-Wall -Wextra)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Windows. Uh-oh.
|
||||||
|
if (DEFINED GETDNS_ON_WINDOWS)
|
||||||
|
set(extra_libraries "ws2_32;crypt32")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Check for include files
|
# Check for include files
|
||||||
check_include_file(assert.h HAVE_ASSERT_H)
|
check_include_file(assert.h HAVE_ASSERT_H)
|
||||||
check_include_file(inttypes.h HAVE_INTTYPES_H)
|
check_include_file(inttypes.h HAVE_INTTYPES_H)
|
||||||
|
@ -160,8 +168,14 @@ check_include_file(winsock2.h HAVE_WINSOCK2_H)
|
||||||
check_include_file(ws2tcpip.h HAVE_WS2TCPIP_H)
|
check_include_file(ws2tcpip.h HAVE_WS2TCPIP_H)
|
||||||
|
|
||||||
# Check for include declarations
|
# Check for include declarations
|
||||||
check_symbol_exists(inet_pton arpa/inet.h HAVE_DECL_INET_PTON)
|
if (DEFINED GETDNS_ON_WINDOWS)
|
||||||
check_symbol_exists(inet_ntop arpa/inet.h HAVE_DECL_INET_NTOP)
|
set(CMAKE_REQUIRED_LIBRARIES ${extra_libraries})
|
||||||
|
check_symbol_exists(inet_pton ws2tcpip.h HAVE_DECL_INET_PTON)
|
||||||
|
check_symbol_exists(inet_ntop ws2tcpip.h HAVE_DECL_INET_NTOP)
|
||||||
|
else()
|
||||||
|
check_symbol_exists(inet_pton arpa/inet.h HAVE_DECL_INET_PTON)
|
||||||
|
check_symbol_exists(inet_ntop arpa/inet.h HAVE_DECL_INET_NTOP)
|
||||||
|
endif()
|
||||||
check_symbol_exists(sigemptyset signal.h HAVE_DECL_SIGEMPTYSET)
|
check_symbol_exists(sigemptyset signal.h HAVE_DECL_SIGEMPTYSET)
|
||||||
check_symbol_exists(sigfillset signal.h HAVE_DECL_SIGFILLSET)
|
check_symbol_exists(sigfillset signal.h HAVE_DECL_SIGFILLSET)
|
||||||
check_symbol_exists(sigaddset signal.h HAVE_DECL_SIGADDSET)
|
check_symbol_exists(sigaddset signal.h HAVE_DECL_SIGADDSET)
|
||||||
|
@ -169,8 +183,7 @@ check_symbol_exists(strptime time.h HAVE_DECL_STRPTIME)
|
||||||
|
|
||||||
# Check for functions
|
# Check for functions
|
||||||
check_function_exists(fcntl HAVE_FCNTL)
|
check_function_exists(fcntl HAVE_FCNTL)
|
||||||
check_function_exists(inet_pton HAVE_INET_PTON)
|
check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
|
||||||
check_function_exists(inet_ntop HAVE_INET_NTOP)
|
|
||||||
check_function_exists(ioctlsocket HAVE_IOCTLSOCKET)
|
check_function_exists(ioctlsocket HAVE_IOCTLSOCKET)
|
||||||
check_function_exists(sigemptyset HAVE_SIGEMPTYSET)
|
check_function_exists(sigemptyset HAVE_SIGEMPTYSET)
|
||||||
check_function_exists(sigfillset HAVE_SIGFILLSET)
|
check_function_exists(sigfillset HAVE_SIGFILLSET)
|
||||||
|
@ -215,8 +228,6 @@ check_function_exists(EVP_MD_CTX_new HAVE_EVP_MD_CTX_NEW)
|
||||||
|
|
||||||
check_function_exists(HMAC_CTX_new HAVE_HMAC_CTX_NEW)
|
check_function_exists(HMAC_CTX_new HAVE_HMAC_CTX_NEW)
|
||||||
|
|
||||||
check_function_exists(TLS_client_method HAVE_TLS_CLIENT_METHOD)
|
|
||||||
|
|
||||||
check_function_exists(OpenSSL_version_num HAVE_OPENSSL_VERSION_NUM)
|
check_function_exists(OpenSSL_version_num HAVE_OPENSSL_VERSION_NUM)
|
||||||
check_function_exists(OpenSSL_version HAVE_OPENSSL_VERSION)
|
check_function_exists(OpenSSL_version HAVE_OPENSSL_VERSION)
|
||||||
|
|
||||||
|
@ -231,6 +242,7 @@ check_symbol_exists(SSL_dane_enable "openssl/ssl.h" HAVE_SSL_DANE_ENABLE)
|
||||||
check_symbol_exists(SSL_CTX_set1_curves_list "openssl/ssl.h" HAVE_DECL_SSL_CTX_SET1_CURVES_LIST)
|
check_symbol_exists(SSL_CTX_set1_curves_list "openssl/ssl.h" HAVE_DECL_SSL_CTX_SET1_CURVES_LIST)
|
||||||
check_symbol_exists(SSL_set1_curves_list "openssl/ssl.h" HAVE_DECL_SSL_SET1_CURVES_LIST)
|
check_symbol_exists(SSL_set1_curves_list "openssl/ssl.h" HAVE_DECL_SSL_SET1_CURVES_LIST)
|
||||||
check_symbol_exists(SSL_set_min_proto_version "openssl/ssl.h" HAVE_DECL_SSL_SET_MIN_PROTO_VERSION)
|
check_symbol_exists(SSL_set_min_proto_version "openssl/ssl.h" HAVE_DECL_SSL_SET_MIN_PROTO_VERSION)
|
||||||
|
check_symbol_exists(TLS_client_method "openssl/ssl.h" HAVE_TLS_CLIENT_METHOD)
|
||||||
check_symbol_exists(X509_get_notAfter "openssl/x509.h" HAVE_X509_GET_NOTAFTER)
|
check_symbol_exists(X509_get_notAfter "openssl/x509.h" HAVE_X509_GET_NOTAFTER)
|
||||||
check_symbol_exists(X509_get0_notAfter "openssl/x509.h" HAVE_X509_GET0_NOTAFTER)
|
check_symbol_exists(X509_get0_notAfter "openssl/x509.h" HAVE_X509_GET0_NOTAFTER)
|
||||||
|
|
||||||
|
@ -291,6 +303,20 @@ if (USE_POLL_DEFAULT_EVENTLOOP)
|
||||||
set(DEFAULT_EVENTLOOP "poll_eventloop")
|
set(DEFAULT_EVENTLOOP "poll_eventloop")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Custom checks
|
||||||
|
set(STRPTIME_TEST_SOURCE "\n
|
||||||
|
#define _XOPEN_SOURCE 600\n
|
||||||
|
#include <time.h>\n
|
||||||
|
int main(void) { struct tm tm; char *res;\n
|
||||||
|
res = strptime(\"2010-07-15T00:00:00+00:00\", \"%t%Y%t-%t%m%t-%t%d%tT%t%H%t:%t%M%t:%t%S%t\", &tm);\n
|
||||||
|
if (!res) return 2;\n
|
||||||
|
res = strptime(\"20070207111842\", \"%Y%m%d%H%M%S\", &tm);\n
|
||||||
|
if (!res) return 1; return 0; }")
|
||||||
|
|
||||||
|
if (HAVE_STRPTIME)
|
||||||
|
check_c_source_runs("${STRPTIME_TEST_SOURCE}" STRPTIME_WORKS)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Main library
|
# Main library
|
||||||
|
|
||||||
set(getdns_SOURCES
|
set(getdns_SOURCES
|
||||||
|
@ -370,12 +396,10 @@ set(getdns_LIBS
|
||||||
)
|
)
|
||||||
|
|
||||||
if (NOT HAVE_SSL_DANE_ENABLE)
|
if (NOT HAVE_SSL_DANE_ENABLE)
|
||||||
set(getdns_SOURCES
|
list(APPEND getdns_SOURCES
|
||||||
${getdns_SOURCES}
|
|
||||||
src/ssl_dane/danessl.c
|
src/ssl_dane/danessl.c
|
||||||
)
|
)
|
||||||
set(getdns_INCLUDES
|
list(APPEND getdns_INCLUDES
|
||||||
${getdns_INCLUDES}
|
|
||||||
PRIVATE src/ssl_dane
|
PRIVATE src/ssl_dane
|
||||||
)
|
)
|
||||||
set(USE_DANESSL 1)
|
set(USE_DANESSL 1)
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#cmakedefine HAVE_WINSOCK2_H 1
|
#cmakedefine HAVE_WINSOCK2_H 1
|
||||||
#cmakedefine HAVE_WS2TCPIP_H 1
|
#cmakedefine HAVE_WS2TCPIP_H 1
|
||||||
#cmakedefine GETDNS_ON_WINDOWS 1
|
#cmakedefine GETDNS_ON_WINDOWS 1
|
||||||
|
#cmakedefine USE_WINSOCK 1
|
||||||
|
|
||||||
#cmakedefine HAVE_SSL 1
|
#cmakedefine HAVE_SSL 1
|
||||||
#cmakedefine USE_DANESSL 1
|
#cmakedefine USE_DANESSL 1
|
||||||
|
@ -114,14 +115,24 @@
|
||||||
|
|
||||||
#cmakedefine HAVE_DECL_INET_PTON 1
|
#cmakedefine HAVE_DECL_INET_PTON 1
|
||||||
#cmakedefine HAVE_DECL_INET_NTOP 1
|
#cmakedefine HAVE_DECL_INET_NTOP 1
|
||||||
|
#cmakedefine HAVE_WIN_DECL_INET_PTON 1
|
||||||
|
#cmakedefine HAVE_WIN_DECL_INET_NTOP 1
|
||||||
#cmakedefine HAVE_DECL_SIGEMPTYSET 1
|
#cmakedefine HAVE_DECL_SIGEMPTYSET 1
|
||||||
#cmakedefine HAVE_DECL_SIGFILLSET 1
|
#cmakedefine HAVE_DECL_SIGFILLSET 1
|
||||||
#cmakedefine HAVE_DECL_SIGADDSET 1
|
#cmakedefine HAVE_DECL_SIGADDSET 1
|
||||||
#cmakedefine HAVE_DECL_STRPTIME 1
|
#cmakedefine HAVE_DECL_STRPTIME 1
|
||||||
|
|
||||||
|
#if defined(HAVE_DECL_INET_PTON) || defined(HAVE_WIN_DECL_INET_PTON)
|
||||||
|
#undef HAVE_DECL_INET_PTON
|
||||||
|
#define HAVE_DECL_INET_PTON 1
|
||||||
|
#endif
|
||||||
|
#if defined(HAVE_DECL_INET_NTOP) || defined(HAVE_WIN_DECL_INET_NTOP)
|
||||||
|
#undef HAVE_DECL_INET_NTOP
|
||||||
|
#define HAVE_DECL_INET_NTOP 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#cmakedefine HAVE_FCNTL 1
|
#cmakedefine HAVE_FCNTL 1
|
||||||
#cmakedefine HAVE_INET_PTON 1
|
#cmakedefine HAVE_GETTIMEOFDAY 1
|
||||||
#cmakedefine HAVE_INET_NTOP 1
|
|
||||||
#cmakedefine HAVE_IOCTLSOCKET 1
|
#cmakedefine HAVE_IOCTLSOCKET 1
|
||||||
#cmakedefine HAVE_SIGEMPTYSET 1
|
#cmakedefine HAVE_SIGEMPTYSET 1
|
||||||
#cmakedefine HAVE_SIGFILLSET 1
|
#cmakedefine HAVE_SIGFILLSET 1
|
||||||
|
@ -142,6 +153,8 @@
|
||||||
#cmakedefine DEFAULT_EVENTLOOP "@DEFAULT_EVENTLOOP@"
|
#cmakedefine DEFAULT_EVENTLOOP "@DEFAULT_EVENTLOOP@"
|
||||||
#cmakedefine USE_POLL_DEFAULT_EVENTLOOP 1
|
#cmakedefine USE_POLL_DEFAULT_EVENTLOOP 1
|
||||||
|
|
||||||
|
#cmakedefine STRPTIME_WORKS 1
|
||||||
|
|
||||||
#ifdef HAVE___FUNC__
|
#ifdef HAVE___FUNC__
|
||||||
#define __FUNC__ __func__
|
#define __FUNC__ __func__
|
||||||
#else
|
#else
|
||||||
|
@ -174,6 +187,8 @@
|
||||||
# else
|
# else
|
||||||
# define PRIsz "Iu"
|
# define PRIsz "Iu"
|
||||||
# endif
|
# endif
|
||||||
|
# include <BaseTsd.h>
|
||||||
|
typedef SSIZE_T ssize_t;
|
||||||
# else
|
# else
|
||||||
# define PRIsz "Iu"
|
# define PRIsz "Iu"
|
||||||
# endif
|
# endif
|
||||||
|
@ -193,6 +208,10 @@
|
||||||
# ifndef strdup
|
# ifndef strdup
|
||||||
# define strdup _strdup
|
# define strdup _strdup
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
/* Windows doesn't have strcasecmp and strncasecmp. */
|
||||||
|
# define strcasecmp _stricmp
|
||||||
|
# define strncasecmp _strnicmp
|
||||||
#else
|
#else
|
||||||
# define PRIsz "zu"
|
# define PRIsz "zu"
|
||||||
#endif
|
#endif
|
||||||
|
@ -263,14 +282,6 @@ void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
|
||||||
unsigned char *SHA512(void* data, unsigned int data_len, unsigned char *digest);
|
unsigned char *SHA512(void* data, unsigned int data_len, unsigned char *digest);
|
||||||
#endif /* COMPAT_SHA512 */
|
#endif /* COMPAT_SHA512 */
|
||||||
|
|
||||||
#ifndef HAVE_DECL_INET_PTON
|
|
||||||
int inet_pton(int af, const char* src, void* dst);
|
|
||||||
#endif /* HAVE_INET_PTON */
|
|
||||||
|
|
||||||
#ifndef HAVE_DECL_INET_NTOP
|
|
||||||
const char *inet_ntop(int af, const void *src, char *dst, size_t size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_WINSOCK
|
#ifdef USE_WINSOCK
|
||||||
# ifndef _CUSTOM_VSNPRINTF
|
# ifndef _CUSTOM_VSNPRINTF
|
||||||
# define _CUSTOM_VSNPRINTF
|
# define _CUSTOM_VSNPRINTF
|
||||||
|
@ -443,6 +454,18 @@ int ub_resolve_event(struct ub_ctx* ctx, const char* name, int rrtype,
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_DECL_INET_PTON
|
||||||
|
int inet_pton(int af, const char* src, void* dst);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_DECL_INET_NTOP
|
||||||
|
const char *inet_ntop(int af, const void *src, char *dst, size_t size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_GETTIMEOFDAY
|
||||||
|
int gettimeofday(struct timeval* tv, void* tz);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue