summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt77
-rw-r--r--ChangeLog12
-rw-r--r--libtiff/tif_config.h.cmake.in7
-rw-r--r--port/CMakeLists.txt2
-rw-r--r--port/libport.h4
5 files changed, 87 insertions, 15 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bdd443d6..d49508a0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -58,6 +58,7 @@ set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "tiff@lists.maptools.org")
include(GNUInstallDirs)
+include(CheckCCompilerFlag)
include(CheckCSourceCompiles)
include(CheckIncludeFile)
include(CheckTypeSize)
@@ -90,6 +91,68 @@ set(EXTRA_DIST
nmake.opt
libtiff-4.pc.in)
+# These are annoyingly verbose, produce false positives or don't work
+# nicely with all supported compiler versions, so are disabled unless
+# explicitly enabled.
+option(extra-warnings "Enable extra compiler warnings" OFF)
+
+# This will cause the compiler to fail when an error occurs.
+option(fatal-warnings "Compiler warnings are errors" OFF)
+
+# Check if the compiler supports each of the following additional
+# flags, and enable them if supported. This greatly improves the
+# quality of the build by checking for a number of common problems,
+# some of which are quite serious.
+if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
+ CMAKE_C_COMPILER_ID MATCHES "Clang")
+ set(test_flags
+ -Wall
+ -Winline
+ -W
+ -Wformat-security
+ -Wpointer-arith
+ -Wdisabled-optimization
+ -Wno-unknown-pragmas
+ -Wdeclaration-after-statement
+ -fstrict-aliasing)
+ if(extra-warnings)
+ list(APPEND test_flags
+ -Wfloat-equal
+ -Wmissing-prototypes
+ -Wunreachable-code)
+ endif()
+ if(fatal-warnings)
+ list(APPEND test_flags
+ -Werror)
+ endif()
+elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
+ set(test_flags)
+ if(extra-warnings)
+ list(APPEND test_flags
+ /W4)
+ else()
+ list(APPEND test_flags
+ /W3)
+ endif()
+ if (fatal-warnings)
+ list(APPEND test_flags
+ /WX)
+ endif()
+endif()
+
+foreach(flag ${test_flags})
+ string(REGEX REPLACE "[^A-Za-z0-9]" "_" flag_var "${flag}")
+ set(test_c_flag "C_FLAG${flag_var}")
+ CHECK_C_COMPILER_FLAG(${flag} "${test_c_flag}")
+ if (${test_c_flag})
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
+ endif (${test_c_flag})
+endforeach(flag ${test_flags})
+
+if(MSVC)
+ set(CMAKE_DEBUG_POSTFIX "d")
+endif()
+
# Check if LD supports linker scripts.
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map" "VERS_1 {
global: sym;
@@ -314,7 +377,6 @@ check_function_exists(memmove HAVE_MEMMOVE)
check_function_exists(memset HAVE_MEMSET)
check_function_exists(mmap HAVE_MMAP)
check_function_exists(setmode HAVE_SETMODE)
-check_function_exists(snprintf HAVE_SNPRINTF)
check_function_exists(strcasecmp HAVE_STRCASECMP)
check_function_exists(strchr HAVE_STRCHR)
check_function_exists(strrchr HAVE_STRRCHR)
@@ -325,10 +387,15 @@ check_function_exists(strtoull HAVE_STRTOULL)
check_function_exists(getopt HAVE_GETOPT)
check_function_exists(lfind HAVE_LFIND)
-# VS2013 has a usable _snprintf
-if(NOT MSVC_VERSION VERSION_LESS 1800 AND MSVC_VERSION VERSION_LESS 1900)
- check_function_exists(_snprintf HAVE__SNPRINTF)
-endif()
+# May be inlined, so check it compiles:
+check_c_source_compiles("
+#include <stdio.h>
+int main(void) {
+ char buf[10];
+ snprintf(buf, 10, \"Test %d\", 1);
+ return 0;
+}"
+ HAVE_SNPRINTF)
# CPU bit order
set(fillorder FILLORDER_MSB2LSB)
diff --git a/ChangeLog b/ChangeLog
index 3f91fa16..fe91d179 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2015-07-04 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
+
+ * cmake: Add d suffix to debug libraries with MSVC. Patch #3 of 3
+ by Roger Leigh posted to tiff list on Wed, 1 Jul 2015 15:58:20
+ +0100.
+
+ * cmake: Add extra warning flags. Patch #2 of 3 by Roger Leigh
+ posted to tiff list on Wed, 1 Jul 2015 15:58:20 +0100.
+
+ * cmake: Correct snprintf fallback for VS2015. Patch #1 of 3 by
+ Roger Leigh posted to tiff list on Wed, 1 Jul 2015 15:58:20 +0100.
+
2015-06-24 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
* CMakeLists.txt: Add CMake patchset by Roger Leigh as posted to
diff --git a/libtiff/tif_config.h.cmake.in b/libtiff/tif_config.h.cmake.in
index 61596c33..de0f3a3c 100644
--- a/libtiff/tif_config.h.cmake.in
+++ b/libtiff/tif_config.h.cmake.in
@@ -95,13 +95,6 @@
/* Define to 1 if you have the `snprintf' function. */
#cmakedefine HAVE_SNPRINTF 1
-/* Define to 1 if you have the `_snprintf' function. */
-#cmakedefine HAVE__SNPRINTF 1
-
-#if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
-#define snprintf _snprintf
-#endif
-
/* Define to 1 if you have the `sqrt' function. */
#cmakedefine HAVE_SQRT 1
diff --git a/port/CMakeLists.txt b/port/CMakeLists.txt
index 354ed4d7..8b221d1d 100644
--- a/port/CMakeLists.txt
+++ b/port/CMakeLists.txt
@@ -39,7 +39,7 @@ endif()
if(NOT HAVE_LFIND)
list(APPEND port_USED_FILES lfind.c)
endif()
-if(NOT HAVE_SNPRINTF AND NOT HAVE__SNPRINTF)
+if(MSVC AND NOT HAVE_SNPRINTF)
list(APPEND port_USED_FILES snprintf.c)
endif()
if(NOT HAVE_STRCASECMP)
diff --git a/port/libport.h b/port/libport.h
index 909ae1fc..8e73e0a3 100644
--- a/port/libport.h
+++ b/port/libport.h
@@ -1,4 +1,4 @@
-/* $Id: libport.h,v 1.3 2015-06-25 02:28:01 bfriesen Exp $ */
+/* $Id: libport.h,v 1.4 2015-07-04 22:09:27 bfriesen Exp $ */
/*
* Copyright (c) 2009 Frank Warmerdam
@@ -48,7 +48,7 @@ lfind(const void *key, const void *base, size_t *nmemb, size_t size,
int(*compar)(const void *, const void *));
#endif
-#if !defined(HAVE_SNPRINTF) && !defined(HAVE__SNPRINTF)
+#if !defined(HAVE_SNPRINTF)
int snprintf(char* str, size_t size, const char* format, ...);
#endif