Skip to content

Commit

Permalink
Now working with mingw w64
Browse files Browse the repository at this point in the history
  • Loading branch information
Noisyfox committed Jan 8, 2017
1 parent c672247 commit 7e13ad2
Show file tree
Hide file tree
Showing 15 changed files with 322 additions and 60 deletions.
195 changes: 158 additions & 37 deletions cmake/FindPCRE.cmake
Original file line number Diff line number Diff line change
@@ -1,37 +1,158 @@
# Copyright (C) 2007-2009 LuaDist.
# Created by Peter Kapec <[email protected]>
# Redistribution and use of this file is allowed according to the terms of the MIT license.
# For details see the COPYRIGHT file distributed with LuaDist.
# Note:
# Searching headers and libraries is very simple and is NOT as powerful as scripts
# distributed with CMake, because LuaDist defines directories to search for.
# Everyone is encouraged to contact the author with improvements. Maybe this file
# becomes part of CMake distribution sometimes.

# - Find pcre
# Find the native PCRE headers and libraries.
#
# PCRE_INCLUDE_DIRS - where to find pcre.h, etc.
# PCRE_LIBRARIES - List of libraries when using pcre.
# PCRE_FOUND - True if pcre found.

# Look for the header file.
FIND_PATH(PCRE_INCLUDE_DIR NAMES pcre.h)

# Look for the library.
FIND_LIBRARY(PCRE_LIBRARY NAMES pcre)

# Handle the QUIETLY and REQUIRED arguments and set PCRE_FOUND to TRUE if all listed variables are TRUE.
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_INCLUDE_DIR)

# Copy the results to the output variables.
IF(PCRE_FOUND)
SET(PCRE_LIBRARIES ${PCRE_LIBRARY})
SET(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR})
ELSE(PCRE_FOUND)
SET(PCRE_LIBRARIES)
SET(PCRE_INCLUDE_DIRS)
ENDIF(PCRE_FOUND)

MARK_AS_ADVANCED(PCRE_INCLUDE_DIRS PCRE_LIBRARIES)
#.rst:
# FindPCRE
# --------
#
# Find the native PCRE includes and library.
#
# IMPORTED Targets
# ^^^^^^^^^^^^^^^^
#
# This module defines :prop_tgt:`IMPORTED` target ``PCRE::PCRE``, if
# PCRE has been found.
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module defines the following variables:
#
# ::
#
# PCRE_INCLUDE_DIRS - where to find pcre.h, etc.
# PCRE_LIBRARIES - List of libraries when using pcre.
# PCRE_FOUND - True if pcre found.
#
# ::
#
# PCRE_VERSION_STRING - The version of pcre found (x.y.z)
# PCRE_VERSION_MAJOR - The major version of zlib
# PCRE_VERSION_MINOR - The minor version of zlib
# PCRE_VERSION_PATCH - The patch version of zlib
# PCRE_VERSION_TWEAK - The tweak version of zlib
#
# Backward Compatibility
# ^^^^^^^^^^^^^^^^^^^^^^
#
# The following variable are provided for backward compatibility
#
# ::
#
# PCRE_MAJOR_VERSION - The major version of zlib
# PCRE_MINOR_VERSION - The minor version of zlib
# PCRE_PATCH_VERSION - The patch version of zlib
#
# Hints
# ^^^^^
#
# A user may set ``PCRE_ROOT`` to a zlib installation root to tell this
# module where to look.

#=============================================================================
# Copyright 2001-2011 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)

set(_PCRE_SEARCHES)

# Search PCRE_ROOT first if it is set.
if(PCRE_ROOT)
set(_PCRE_SEARCH_ROOT PATHS ${PCRE_ROOT} NO_DEFAULT_PATH)
list(APPEND _PCRE_SEARCHES _PCRE_SEARCH_ROOT)
endif()

# Normal search.
set(_PCRE_SEARCH_NORMAL
PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Pcre;InstallPath]"
"$ENV{PROGRAMFILES}/pcre"
)
list(APPEND _PCRE_SEARCHES _PCRE_SEARCH_NORMAL)

set(PCRE_NAMES pcre pcredll)
set(PCRE_NAMES_DEBUG pcred)

# Try each search configuration.
foreach(search ${_PCRE_SEARCHES})
find_path(PCRE_INCLUDE_DIR NAMES pcre.h ${${search}} PATH_SUFFIXES include)
endforeach()

# Allow PCRE_LIBRARY to be set manually, as the location of the pcre library
if(NOT PCRE_LIBRARY)
foreach(search ${_PCRE_SEARCHES})
find_library(PCRE_LIBRARY_RELEASE NAMES ${PCRE_NAMES} ${${search}} PATH_SUFFIXES lib)
find_library(PCRE_LIBRARY_DEBUG NAMES ${PCRE_NAMES_DEBUG} ${${search}} PATH_SUFFIXES lib)
endforeach()

include(SelectLibraryConfigurations)
select_library_configurations(PCRE)
endif()

unset(PCRE_NAMES)
unset(PCRE_NAMES_DEBUG)

mark_as_advanced(PCRE_LIBRARY PCRE_INCLUDE_DIR)

if(PCRE_INCLUDE_DIR AND EXISTS "${PCRE_INCLUDE_DIR}/pcre.h")
file(STRINGS "${PCRE_INCLUDE_DIR}/pcre.h" PCRE_H REGEX "^#define PCRE_VERSION \"[^\"]*\"$")

string(REGEX REPLACE "^.*PCRE_VERSION \"([0-9]+).*$" "\\1" PCRE_VERSION_MAJOR "${PCRE_H}")
string(REGEX REPLACE "^.*PCRE_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" PCRE_VERSION_MINOR "${PCRE_H}")
string(REGEX REPLACE "^.*PCRE_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" PCRE_VERSION_PATCH "${PCRE_H}")
set(PCRE_VERSION_STRING "${PCRE_VERSION_MAJOR}.${PCRE_VERSION_MINOR}.${PCRE_VERSION_PATCH}")

# only append a TWEAK version if it exists:
set(PCRE_VERSION_TWEAK "")
if( "${PCRE_H}" MATCHES "PCRE_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+)")
set(PCRE_VERSION_TWEAK "${CMAKE_MATCH_1}")
set(PCRE_VERSION_STRING "${PCRE_VERSION_STRING}.${PCRE_VERSION_TWEAK}")
endif()

set(PCRE_MAJOR_VERSION "${PCRE_VERSION_MAJOR}")
set(PCRE_MINOR_VERSION "${PCRE_VERSION_MINOR}")
set(PCRE_PATCH_VERSION "${PCRE_VERSION_PATCH}")
endif()

# handle the QUIETLY and REQUIRED arguments and set PCRE_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE REQUIRED_VARS PCRE_LIBRARY PCRE_INCLUDE_DIR
VERSION_VAR PCRE_VERSION_STRING)

if(PCRE_FOUND)
set(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR})

if(NOT PCRE_LIBRARIES)
set(PCRE_LIBRARIES ${PCRE_LIBRARY})
endif()

if(NOT TARGET PCRE::PCRE)
add_library(PCRE::PCRE UNKNOWN IMPORTED)
set_target_properties(PCRE::PCRE PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${PCRE_INCLUDE_DIRS}")

if(PCRE_LIBRARY_RELEASE)
set_property(TARGET PCRE::PCRE APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(PCRE::PCRE PROPERTIES
IMPORTED_LOCATION_RELEASE "${PCRE_LIBRARY_RELEASE}")
endif()

if(PCRE_LIBRARY_DEBUG)
set_property(TARGET PCRE::PCRE APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(PCRE::PCRE PROPERTIES
IMPORTED_LOCATION_DEBUG "${PCRE_LIBRARY_DEBUG}")
endif()

if(NOT PCRE_LIBRARY_RELEASE AND NOT PCRE_LIBRARY_DEBUG)
set_property(TARGET PCRE::PCRE APPEND PROPERTY
IMPORTED_LOCATION "${PCRE_LIBRARY}")
endif()
endif()
endif()
43 changes: 41 additions & 2 deletions cmake/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ if (${with_crypto_library} STREQUAL "openssl")
find_package(OpenSSL REQUIRED)
set(USE_CRYPTO_OPENSSL 1)
set(LIBCRYPTO
${ZLIB_LIBRARIES}
${OPENSSL_CRYPTO_LIBRARY})

include_directories(${ZLIB_INCLUDE_DIR})
include_directories(${OPENSSL_INCLUDE_DIR})

list ( APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})

elseif(${with_crypto_library} STREQUAL "polarssl")
find_package(polarssl REQUIRED)
set(USE_CRYPTO_POLARSSL 1)
Expand All @@ -14,6 +21,10 @@ elseif(${with_crypto_library} STREQUAL "mbedtls")
set(USE_CRYPTO_MBEDTLS 1)
endif()

find_package(PCRE REQUIRED)
include_directories(${PCRE_INCLUDE_DIR})
list ( APPEND CMAKE_REQUIRED_INCLUDES ${PCRE_INCLUDE_DIR})


# Platform checks
include ( CheckFunctionExists )
Expand Down Expand Up @@ -102,8 +113,32 @@ check_function_exists ( inet_ntop HAVE_DECL_INET_NTOP )
check_symbol_exists ( PTHREAD_PRIO_INHERIT "pthread.h" HAVE_PTHREAD_PRIO_INHERIT )
check_symbol_exists ( PTHREAD_CREATE_JOINABLE "pthread.h" HAVE_PTHREAD_CREATE_JOINABLE )
check_symbol_exists ( EINPROGRESS "sys/errno.h" HAVE_EINPROGRESS )
check_symbol_exists ( WSAEWOULDBLOCK "winerrno.h" HAVE_WSAEWOULDBLOCK )

check_symbol_exists ( WSAEWOULDBLOCK "winerror.h" HAVE_WSAEWOULDBLOCK )

# winsock2.h and ws2_32 should provide these
if(HAVE_WINSOCK2_H)
set(HAVE_GETHOSTNAME ON)
set(HAVE_SELECT ON)
set(HAVE_SOCKET ON)
set(HAVE_INET_NTOA ON)
set(HAVE_RECV ON)
set(HAVE_SEND ON)
set(HAVE_RECVFROM ON)
set(HAVE_SENDTO ON)
set(HAVE_GETHOSTBYNAME ON)
set(HAVE_GETSERVBYNAME ON)
else(HAVE_WINSOCK2_H)
check_function_exists(gethostname HAVE_GETHOSTNAME)
check_function_exists(select HAVE_SELECT)
check_function_exists(socket HAVE_SOCKET)
check_function_exists(inet_ntoa HAVE_INET_NTOA)
check_function_exists(recv HAVE_RECV)
check_function_exists(send HAVE_SEND)
check_function_exists(recvfrom HAVE_RECVFROM)
check_function_exists(sendto HAVE_SENDTO)
check_function_exists(gethostbyname HAVE_GETHOSTBYNAME)
check_function_exists(getservbyname HAVE_GETSERVBYNAME)
endif(HAVE_WINSOCK2_H)

find_library ( HAVE_LIBPCRE pcre )
find_library ( HAVE_LIBRT rt )
Expand Down Expand Up @@ -152,7 +187,11 @@ elseif(${HAVE_WSAEWOULDBLOCK})
set (CONNECT_IN_PROGRESS WSAEWOULDBLOCK)
endif()

#SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")



set (HAVE_IPv6 1)

ADD_DEFINITIONS(-DHAVE_CONFIG_H)
ADD_DEFINITIONS(-D__USE_MINGW_ANSI_STDIO=1)
8 changes: 4 additions & 4 deletions config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
#define CONNECT_IN_PROGRESS @CONNECT_IN_PROGRESS@

/* Override libev default fd conversion macro. */
#undef EV_FD_TO_WIN32_HANDLE
#define EV_FD_TO_WIN32_HANDLE(fd) (fd)

/* Override libev default fd close macro. */
#undef EV_WIN32_CLOSE_FD
#define EV_WIN32_CLOSE_FD(fd) closesocket(fd)

/* Override libev default handle conversion macro. */
#undef EV_WIN32_HANDLE_TO_FD
#define EV_WIN32_HANDLE_TO_FD(handle) (handle)

/* Reset max file descriptor size. */
#undef FD_SETSIZE
#define FD_SETSIZE 2048

/* Define to 1 if you have the <arpa/inet.h> header file. */
#cmakedefine HAVE_ARPA_INET_H 1
Expand Down
10 changes: 5 additions & 5 deletions libcork/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ add_c_library(
ds/managed-buffer.c
ds/ring-buffer.c
ds/slice.c
posix/directory-walker.c
posix/env.c
posix/exec.c
posix/files.c
# posix/directory-walker.c
# posix/env.c
# posix/exec.c
# posix/files.c
posix/process.c
posix/subprocess.c
# posix/subprocess.c
pthreads/thread.c
LIBRARIES
threads
Expand Down
28 changes: 28 additions & 0 deletions libcork/core/timestamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,34 @@ cork_timestamp_format_parts(const cork_timestamp ts, struct tm *tm,
return 0;
}

#ifdef __MINGW32__
static struct tm *__cdecl gmtime_r(const time_t *_Time, struct tm *_Tm)
{
struct tm *p = gmtime(_Time);
if (!p)
return NULL;
if (_Tm) {
memcpy(_Tm, p, sizeof(struct tm));
return _Tm;
} else
return p;
}

static struct tm *__cdecl localtime_r(const time_t *_Time, struct tm *_Tm)
{
struct tm *p = localtime(_Time);
if (!p)
return NULL;
if (_Tm) {
memcpy(_Tm, p, sizeof(struct tm));
return _Tm;
} else
return p;
}

#endif


int
cork_timestamp_format_utc(const cork_timestamp ts, const char *format,
struct cork_buffer *dest)
Expand Down
2 changes: 2 additions & 0 deletions libcork/include/libcork/config/mingw32.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@ static inline int mingw_mkdir(const char *path, int mode)
}
#define mkdir mingw_mkdir

#define S_ISLNK(x) 0


#endif /* LIBCORK_CONFIG_MINGW32_H */
4 changes: 2 additions & 2 deletions libcork/include/libcork/core/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
* format_index and args_index are 1-based.
*/

#if CORK_CONFIG_HAVE_GCC_ATTRIBUTES
#if CORK_CONFIG_HAVE_GCC_ATTRIBUTES && !(defined(__CYGWIN__)||defined(__MINGW32__))
#define CORK_ATTR_PRINTF(format_index, args_index) \
__attribute__((format(printf, format_index, args_index)))
#else
Expand Down Expand Up @@ -137,7 +137,7 @@
* it's internal to the current library.
*/

#if CORK_CONFIG_HAVE_GCC_ATTRIBUTES && !defined(__CYGWIN__)
#if CORK_CONFIG_HAVE_GCC_ATTRIBUTES && !(defined(__CYGWIN__)||defined(__MINGW32__))
#define CORK_EXPORT __attribute__((visibility("default")))
#define CORK_IMPORT __attribute__((visibility("default")))
#define CORK_LOCAL __attribute__((visibility("hidden")))
Expand Down
Loading

0 comments on commit 7e13ad2

Please sign in to comment.