Skip to content

Commit

Permalink
silence MSVC with definitions and options (GPSBabel#859)
Browse files Browse the repository at this point in the history
* deal with MSVC CRT security warnings in a consistent manner.

* correct cmake targets

* turn off some MSVC warnings for shapelib, zlib with cmake.

* fix msvc C4100 warning handling.

There was interference between our attempt to turn off the warning
with -wd4100 and win32-msvc mkspec changing the level of this
warning with -w34100.
  • Loading branch information
tsteven4 authored Feb 26, 2022
1 parent 3a79346 commit 369ccf8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ if(WIN32)
endif()

if(MSVC)
target_compile_definitions(gpsbabel PRIVATE _CRT_SECURE_NO_DEPRECATE)
target_compile_definitions(gpsbabel PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(gpsbabel PRIVATE _CRT_NONSTDC_NO_WARNINGS)
target_compile_options(gpsbabel PRIVATE /MP -wd4100 -wd4267)
endif()

Expand Down
17 changes: 14 additions & 3 deletions GPSBabel.pro
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,20 @@ win32 {
}

win32-msvc* {
DEFINES += _CRT_SECURE_NO_DEPRECATE
QMAKE_CFLAGS += /MP -wd4100 -wd4267
QMAKE_CXXFLAGS += /MP -wd4100 -wd4267
DEFINES += _CRT_SECURE_NO_WARNINGS
DEFINES += _CRT_NONSTDC_NO_WARNINGS
QMAKE_CFLAGS += /MP -wd4267
QMAKE_CXXFLAGS += /MP -wd4267
# The -wd (disable warning) and -w3 (change warning to level 3) options are exclusive.
# The win32-msvc makespec uses -w34100, which can interfer with -wd4100.
# Their are two qmake settings for warnings in CONFIG: warn_on and warn_off.
# This results in the warning showing with msbuild, but not with nmake, even if
# -wd4100 is included in QMAKE_CFLAGS and QMAKE_CXXFLAGS.
# Override win32-msvc, leaving these warnings at their default of level 4, which
# will not show up because we run at level 3.
# shapelib/shpopen.c can cause a C4100 error.
QMAKE_CFLAGS_WARN_ON -= -w34100
QMAKE_CXXFLAGS_WARN_ON -= -w34100
}

include(shapelib.pri)
Expand Down
13 changes: 0 additions & 13 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,6 @@ constexpr double KNOTS_TO_MPS(double a) {return a * kMPSPerKnot;}
#define CENTI_TO_MICRO(t) ((t) * 10000) /* Centiseconds to Microseconds */
#define MICRO_TO_CENTI(t) ((t) / 10000) /* Centiseconds to Microseconds */

#if __WIN32__
# ifndef fileno
# define fileno _fileno
# endif
# define strdup _strdup
#endif

#if __WIN32__
#if !defined _CRT_SECURE_NO_DEPRECATE
# define _CRT_SECURE_NO_DEPRECATE 1
#endif
#endif

/* Pathname separator character */
#if __WIN32__
# define GB_PATHSEP '\\'
Expand Down
5 changes: 5 additions & 0 deletions shapelib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ else()
# note gpsbabel has conditional code include "shapelib/shapefil.h",
# so it doesn't actually rely on the include directory being PUBLIC/INTERFACE
target_include_directories(shp PUBLIC shape)
if(MSVC)
target_compile_definitions(shp PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(shp PRIVATE _CRT_NONSTDC_NO_WARNINGS)
target_compile_options(shp PRIVATE /MP -wd4100 -wd4267)
endif()
list(APPEND LIBS shp)
elseif(GPSBABEL_WITH_SHAPELIB STREQUAL "custom")
message(STATUS "shapelib is enabled but but must be manually configured.")
Expand Down
5 changes: 5 additions & 0 deletions zlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ else()
target_compile_definitions(z PRIVATE HAVE_STDARG_H)
endif()
endif()
if(MSVC)
target_compile_definitions(z PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(z PRIVATE _CRT_NONSTDC_NO_WARNINGS)
target_compile_options(z PRIVATE /MP -wd4100 -wd4267)
endif()
target_include_directories(z PUBLIC zlib)
list(APPEND LIBS z)
elseif(GPSBABEL_WITH_ZLIB STREQUAL "custom")
Expand Down

0 comments on commit 369ccf8

Please sign in to comment.