0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-26 23:01:04 +08:00

Problem: No static analysis under Windows

Solution: Enable VS static analyzer and core guideline checks
This commit is contained in:
Simon Giesecke 2018-05-16 09:12:26 +02:00 committed by Simon Giesecke
parent edd9a0c5c8
commit 2b31e50b01
2 changed files with 67 additions and 2 deletions

View File

@ -302,9 +302,32 @@ macro (zmq_check_cxx_flag_prepend flag)
endif ()
endmacro ()
OPTION (ENABLE_ANALYSIS "Build with static analysis (make take very long)" OFF)
if (MSVC)
zmq_check_cxx_flag_prepend ("/W3")
if (ENABLE_ANALYSIS)
zmq_check_cxx_flag_prepend ("/W4")
zmq_check_cxx_flag_prepend ("/analyze")
# C++11/14/17-specific, but maybe possible via conditional defines
zmq_check_cxx_flag_prepend ("/wd26440") # Function '...' can be declared 'noexcept'
zmq_check_cxx_flag_prepend ("/wd26432") # If you define or delete any default operation in the type '...', define or delete them all
zmq_check_cxx_flag_prepend ("/wd26439") # This kind of function may not throw. Declare it 'noexcept'
zmq_check_cxx_flag_prepend ("/wd26447") # The function is declared 'noexcept' but calls function '...' which may throw exceptions
zmq_check_cxx_flag_prepend ("/wd26433") # Function '...' should be marked with 'override'
zmq_check_cxx_flag_prepend ("/wd26409") # Avoid calling new and delete explicitly, use std::make_unique<T> instead
# Requires GSL
zmq_check_cxx_flag_prepend ("/wd26429") # Symbol '...' is never tested for nullness, it can be marked as not_null
zmq_check_cxx_flag_prepend ("/wd26446") # Prefer to use gsl::at()
zmq_check_cxx_flag_prepend ("/wd26481") # Don't use pointer arithmetic. Use span instead
zmq_check_cxx_flag_prepend ("/wd26472") # Don't use a static_cast for arithmetic conversions. Use brace initialization, gsl::narrow_cast or gsl::narow
zmq_check_cxx_flag_prepend ("/wd26448") # Consider using gsl::finally if final action is intended
zmq_check_cxx_flag_prepend ("/wd26400") # Do not assign the result of an allocation or a function call with an owner<T> return value to a raw pointer, use owner<T> instead
zmq_check_cxx_flag_prepend ("/wd26485") # Expression '...': No array to pointer decay (bounds.3)
else()
zmq_check_cxx_flag_prepend ("/W3")
endif()
if (MSVC_IDE)
set (MSVC_TOOLSET "-${CMAKE_VS_PLATFORM_TOOLSET}")
@ -941,8 +964,17 @@ if (MSVC)
set( CMAKE_STATIC_LINKER_FLAGS /ignore:4221 )
set (PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
set (PDB_NAME "libzmq${MSVC_TOOLSET}-mt-gd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}")
function(enable_vs_guideline_checker target)
set_target_properties(${target} PROPERTIES
VS_GLOBAL_EnableCppCoreCheck true
VS_GLOBAL_CodeAnalysisRuleSet CppCoreCheckRules.ruleset
VS_GLOBAL_RunCodeAnalysis true)
endfunction()
if (BUILD_SHARED)
add_library (libzmq SHARED ${sources} ${public_headers} ${html-docs} ${readme-docs} ${CMAKE_CURRENT_BINARY_DIR}/NSIS.template.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
if(ENABLE_ANALYSIS)
enable_vs_guideline_checker (libzmq)
endif()
set_target_properties (libzmq PROPERTIES
PUBLIC_HEADER "${public_headers}"
RELEASE_POSTFIX "${MSVC_TOOLSET}-mt-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"

View File

@ -11,6 +11,15 @@ environment:
MSVCVERSION: "v120"
MSVCYEAR: "vs2013"
matrix:
- platform: Win32
configuration: Release
WITH_LIBSODIUM: ON
ENABLE_CURVE: ON
ENABLE_ANALYSIS: ON
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_GENERATOR: "Visual Studio 15 2017"
MSVCVERSION: "v141"
MSVCYEAR: "vs2017"
- platform: Win32
configuration: Release
WITH_LIBSODIUM: ON
@ -95,17 +104,41 @@ install:
clone_folder: C:\projects\libzmq
before_build:
- cmd: set LIBZMQ_SRCDIR=%cd%
- cmd: set LIBZMQ_BUILDDIR=C:\projects\build_libzmq
# TODO this does not work with sonarcloud.io, as it misses the sonar-cxx plugin
# - cmd: curl -L https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.1.0.1141-windows.zip -o sonar-scanner-cli-3.1.0.1141-windows.zip
# - cmd: unzip sonar-scanner-cli-3.1.0.1141-windows.zip
# - cmd: set BUILDLOG="%LIBZMQ_SRCDIR%\build.log"
- cmd: md "%LIBZMQ_BUILDDIR%"
- cd "%LIBZMQ_BUILDDIR%"
- cmd: cmake -D CMAKE_INCLUDE_PATH="%SODIUM_INCLUDE_DIR%" -D CMAKE_LIBRARY_PATH="%SODIUM_LIBRARY_DIR%" -D WITH_LIBSODIUM="%WITH_LIBSODIUM%" -D ENABLE_DRAFTS="ON" -D ENABLE_CURVE="%ENABLE_CURVE%" -D API_POLLER="%API_POLLER%" -D POLLER="%POLLER%" -D CMAKE_C_FLAGS_RELEASE="/MT" -D CMAKE_C_FLAGS_DEBUG="/MTd" -D WITH_LIBSODIUM="%WITH_LIBSODIUM%" -D LIBZMQ_WERROR="ON" -G "%CMAKE_GENERATOR%" "%APPVEYOR_BUILD_FOLDER%"
- cmd: cmake -D CMAKE_INCLUDE_PATH="%SODIUM_INCLUDE_DIR%" -D CMAKE_LIBRARY_PATH="%SODIUM_LIBRARY_DIR%" -D WITH_LIBSODIUM="%WITH_LIBSODIUM%" -D ENABLE_DRAFTS="ON" -D ENABLE_ANALYSIS="%ENABLE_ANALYSIS%" -D ENABLE_CURVE="%ENABLE_CURVE%" -D API_POLLER="%API_POLLER%" -D POLLER="%POLLER%" -D CMAKE_C_FLAGS_RELEASE="/MT" -D CMAKE_C_FLAGS_DEBUG="/MTd" -D WITH_LIBSODIUM="%WITH_LIBSODIUM%" -G "%CMAKE_GENERATOR%" "%APPVEYOR_BUILD_FOLDER%"
- cmd: cd "%LIBZMQ_SRCDIR%"
build:
parallel: true
project: C:\projects\build_libzmq\ZeroMQ.sln
verbosity: minimal
# TODO this does not work with sonarcloud.io, as it misses the sonar-cxx plugin
# build_script:
# - cmd: msbuild %LIBZMQ_BUILDDIR%\ZeroMQ.sln /verbosity:detailed >%BUILDLOG%
after_build:
# TODO this does not work with sonarcloud.io, as it misses the sonar-cxx plugin
# - cmd: cd "%LIBZMQ_SRCDIR%"
# - cmd: dir
# - cmd: sonar-scanner-3.1.0.1141-windows\bin\sonar-scanner
# -Dsonar.scm.provider=git
# -Dsonar.projectKey=libzmq-msvc
# -Dsonar.organization=sigiesec-github
# -Dsonar.sources=include,src,tests,unittests
# -Dsonar.host.url=https://sonarcloud.io
# -Dsonar.login=%SONARQUBE_TOKEN%
# -Dsonar.cxx.compiler.parser="Visual C++"
# -Dsonar.cxx.compiler.reportPath=build.log
# -Dsonar.cxx.compiler.charset=UTF-8
# -Dsonar.cxx.compiler.regex=^(?<filename>.*)\\((?<line>[0-9]+)\\):\\x20warning\\x20(?<id>C\\d\\d\\d\\d):(?<message>.*)$
- cmd: cd %LIBZMQ_BUILDDIR%\bin\%Configuration%"
- cmd: if "%WITH_LIBSODIUM%"=="ON" copy "%SODIUM_LIBRARY_DIR%\libsodium.dll" .
- cmd: 7z a -y -bd -mx=9 libzmq.zip *.exe *.dll