cmake: fix Windows support

Fix Windows build by defining `ssize_t` when missing and adjusting the
install commands.

Add support for ENABLE_WERROR=1 while at it.

Tested with MSVC 2013 on Windows 7 x64.
This commit is contained in:
Peter Wu 2016-03-16 17:33:20 +01:00
parent 3a2a943fe9
commit d10f149161
4 changed files with 23 additions and 11 deletions

View File

@ -267,11 +267,15 @@ check_include_file("syslog.h" HAVE_SYSLOG_H)
check_include_file("time.h" HAVE_TIME_H) check_include_file("time.h" HAVE_TIME_H)
check_include_file("unistd.h" HAVE_UNISTD_H) check_include_file("unistd.h" HAVE_UNISTD_H)
include(CheckTypeSize)
# Checks for typedefs, structures, and compiler characteristics. # Checks for typedefs, structures, and compiler characteristics.
# XXX The AC_TYPE_* macros would define suitable types if standard headers do
# not define them. No equivalent in cmake...
# AC_TYPE_SIZE_T # AC_TYPE_SIZE_T
# AC_TYPE_SSIZE_T check_type_size("ssize_t" SIZEOF_SSIZE_T)
if(SIZEOF_SSIZE_T STREQUAL "")
# ssize_t is a signed type in POSIX storing at least -1.
# Set it to "int" to match the behavior of AC_TYPE_SSIZE_T (autotools).
set(ssize_t int)
endif()
# AC_TYPE_UINT8_T # AC_TYPE_UINT8_T
# AC_TYPE_UINT16_T # AC_TYPE_UINT16_T
# AC_TYPE_UINT32_T # AC_TYPE_UINT32_T
@ -292,7 +296,6 @@ include(CheckStructHasMember)
check_struct_has_member("struct tm" tm_gmtoff time.h HAVE_STRUCT_TM_TM_GMTOFF) check_struct_has_member("struct tm" tm_gmtoff time.h HAVE_STRUCT_TM_TM_GMTOFF)
# Check size of pointer to decide we need 8 bytes alignment adjustment. # Check size of pointer to decide we need 8 bytes alignment adjustment.
include(CheckTypeSize)
check_type_size("int *" SIZEOF_INT_P) check_type_size("int *" SIZEOF_INT_P)
check_type_size("time_t" SIZEOF_TIME_T) check_type_size("time_t" SIZEOF_TIME_T)
@ -322,11 +325,17 @@ endif()
set(WARNCFLAGS) set(WARNCFLAGS)
set(WARNCXXFLAGS) set(WARNCXXFLAGS)
if(ENABLE_WERROR) if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
extract_valid_c_flags(WARNCFLAGS -Werror) if(ENABLE_WERROR)
extract_valid_c_flags(WARNCXXFLAGS -Werror) set(WARNCFLAGS /WX)
endif() set(WARNCXXFLAGS /WX)
if(NOT CMAKE_C_COMPILER_ID STREQUAL "MSVC") endif()
else()
if(ENABLE_WERROR)
extract_valid_c_flags(WARNCFLAGS -Werror)
extract_valid_c_flags(WARNCXXFLAGS -Werror)
endif()
# For C compiler # For C compiler
extract_valid_c_flags(WARNCFLAGS extract_valid_c_flags(WARNCFLAGS
-Wall -Wall

View File

@ -5,6 +5,9 @@
/* Hint to the compiler that a function never returns */ /* Hint to the compiler that a function never returns */
#define NGHTTP2_NORETURN @HINT_NORETURN@ #define NGHTTP2_NORETURN @HINT_NORETURN@
/* Define to `int' if <sys/types.h> does not define. */
#cmakedefine ssize_t @ssize_t@
/* Define to 1 if you have the `std::map::emplace`. */ /* Define to 1 if you have the `std::map::emplace`. */
#cmakedefine HAVE_STD_MAP_EMPLACE 1 #cmakedefine HAVE_STD_MAP_EMPLACE 1

View File

@ -44,7 +44,7 @@ if(HAVE_CUNIT)
endif() endif()
install(TARGETS nghttp2 install(TARGETS nghttp2
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") DESTINATION "${CMAKE_INSTALL_LIBDIR}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libnghttp2.pc" install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libnghttp2.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

View File

@ -250,7 +250,7 @@ if(ENABLE_ASIO_LIB)
VERSION 1.0.0 SOVERSION 1) VERSION 1.0.0 SOVERSION 1)
install(TARGETS nghttp2_asio install(TARGETS nghttp2_asio
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") DESTINATION "${CMAKE_INSTALL_LIBDIR}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libnghttp2_asio.pc" install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libnghttp2_asio.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")