From d10f149161eb4fdb4b9ceedd59eaf9ea3cd6d505 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 16 Mar 2016 17:33:20 +0100 Subject: [PATCH] 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. --- CMakeLists.txt | 27 ++++++++++++++++++--------- cmakeconfig.h.in | 3 +++ lib/CMakeLists.txt | 2 +- src/CMakeLists.txt | 2 +- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5da6999a..3378b187 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -267,11 +267,15 @@ check_include_file("syslog.h" HAVE_SYSLOG_H) check_include_file("time.h" HAVE_TIME_H) check_include_file("unistd.h" HAVE_UNISTD_H) +include(CheckTypeSize) # 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_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_UINT16_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 size of pointer to decide we need 8 bytes alignment adjustment. -include(CheckTypeSize) check_type_size("int *" SIZEOF_INT_P) check_type_size("time_t" SIZEOF_TIME_T) @@ -322,11 +325,17 @@ endif() set(WARNCFLAGS) set(WARNCXXFLAGS) -if(ENABLE_WERROR) - extract_valid_c_flags(WARNCFLAGS -Werror) - extract_valid_c_flags(WARNCXXFLAGS -Werror) -endif() -if(NOT CMAKE_C_COMPILER_ID STREQUAL "MSVC") +if(CMAKE_C_COMPILER_ID MATCHES "MSVC") + if(ENABLE_WERROR) + set(WARNCFLAGS /WX) + set(WARNCXXFLAGS /WX) + endif() +else() + if(ENABLE_WERROR) + extract_valid_c_flags(WARNCFLAGS -Werror) + extract_valid_c_flags(WARNCXXFLAGS -Werror) + endif() + # For C compiler extract_valid_c_flags(WARNCFLAGS -Wall diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index 3e39463d..fb798f4e 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -5,6 +5,9 @@ /* Hint to the compiler that a function never returns */ #define NGHTTP2_NORETURN @HINT_NORETURN@ +/* Define to `int' if does not define. */ +#cmakedefine ssize_t @ssize_t@ + /* Define to 1 if you have the `std::map::emplace`. */ #cmakedefine HAVE_STD_MAP_EMPLACE 1 diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 17777ec1..06253935 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -44,7 +44,7 @@ if(HAVE_CUNIT) endif() install(TARGETS nghttp2 - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") + DESTINATION "${CMAKE_INSTALL_LIBDIR}") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libnghttp2.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e5b99d8c..1933e4c7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -250,7 +250,7 @@ if(ENABLE_ASIO_LIB) VERSION 1.0.0 SOVERSION 1) install(TARGETS nghttp2_asio - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") + DESTINATION "${CMAKE_INSTALL_LIBDIR}") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libnghttp2_asio.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")