mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-05-18 19:37:35 +02:00
- CMake: added option to turn fail compilation if warning occurs, and warning level 4 with MSVC.
- Fixed some warnings
This commit is contained in:
parent
7b62ceacee
commit
700b38020e
@ -4,6 +4,7 @@ ENABLE_TESTING()
|
|||||||
|
|
||||||
OPTION(JSONCPP_WITH_TESTS "Compile and run JsonCpp test executables" ON)
|
OPTION(JSONCPP_WITH_TESTS "Compile and run JsonCpp test executables" ON)
|
||||||
OPTION(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON)
|
OPTION(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON)
|
||||||
|
OPTION(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF)
|
||||||
|
|
||||||
# Ensures that CMAKE_BUILD_TYPE is visible in cmake-gui on Unix
|
# Ensures that CMAKE_BUILD_TYPE is visible in cmake-gui on Unix
|
||||||
IF(NOT WIN32)
|
IF(NOT WIN32)
|
||||||
@ -61,9 +62,27 @@ MESSAGE(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINO
|
|||||||
CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/src/lib_json/version.h.in"
|
CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/src/lib_json/version.h.in"
|
||||||
"${PROJECT_SOURCE_DIR}/include/json/version.h" )
|
"${PROJECT_SOURCE_DIR}/include/json/version.h" )
|
||||||
|
|
||||||
|
macro(UseCompilationWarningAsError)
|
||||||
|
if ( MSVC )
|
||||||
|
# Only enabled in debug because some old versions of VS STL generate
|
||||||
|
# warnings when compiled in release configuration.
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ")
|
||||||
|
endif( MSVC )
|
||||||
|
endmacro()
|
||||||
|
|
||||||
# Include our configuration header
|
# Include our configuration header
|
||||||
INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/include )
|
INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/include )
|
||||||
|
|
||||||
|
if ( MSVC )
|
||||||
|
# Only enabled in debug because some old versions of VS STL generate
|
||||||
|
# unreachable code warning when compiled in release configuration.
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 ")
|
||||||
|
endif( MSVC )
|
||||||
|
|
||||||
|
IF(JSONCPP_WITH_WARNING_AS_ERROR)
|
||||||
|
UseCompilationWarningAsError()
|
||||||
|
ENDIF(JSONCPP_WITH_WARNING_AS_ERROR)
|
||||||
|
|
||||||
# Build the different applications
|
# Build the different applications
|
||||||
ADD_SUBDIRECTORY( src )
|
ADD_SUBDIRECTORY( src )
|
||||||
|
|
||||||
|
@ -1805,7 +1805,7 @@ Path::makePath( const std::string &path,
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Path::addPathInArg( const std::string &path,
|
Path::addPathInArg( const std::string &/*path*/,
|
||||||
const InArgs &in,
|
const InArgs &in,
|
||||||
InArgs::const_iterator &itInArg,
|
InArgs::const_iterator &itInArg,
|
||||||
PathArgument::Kind kind )
|
PathArgument::Kind kind )
|
||||||
@ -1826,8 +1826,8 @@ Path::addPathInArg( const std::string &path,
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Path::invalidPath( const std::string &path,
|
Path::invalidPath( const std::string &/*path*/,
|
||||||
int location )
|
int /*location*/ )
|
||||||
{
|
{
|
||||||
// Error: invalid path.
|
// Error: invalid path.
|
||||||
}
|
}
|
||||||
|
@ -480,10 +480,10 @@ Runner::runCommandLine( int argc, const char *argv[] ) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||||
// Hook MSVCRT assertions to prevent dialog from appearing
|
// Hook MSVCRT assertions to prevent dialog from appearing
|
||||||
static int
|
static int
|
||||||
msvcrtSilentReportHook( int reportType, char *message, int *returnValue )
|
msvcrtSilentReportHook( int reportType, char *message, int * /*returnValue*/ )
|
||||||
{
|
{
|
||||||
// The default CRT handling of error and assertion is to display
|
// The default CRT handling of error and assertion is to display
|
||||||
// an error dialog to the user.
|
// an error dialog to the user.
|
||||||
@ -517,9 +517,11 @@ msvcrtSilentReportHook( int reportType, char *message, int *returnValue )
|
|||||||
void
|
void
|
||||||
Runner::preventDialogOnCrash()
|
Runner::preventDialogOnCrash()
|
||||||
{
|
{
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||||
// Install a hook to prevent MSVCRT error and assertion from
|
// Install a hook to prevent MSVCRT error and assertion from
|
||||||
// popping a dialog.
|
// popping a dialog
|
||||||
|
// This function a NO-OP in release configuration
|
||||||
|
// (which cause warning since msvcrtSilentReportHook is not referenced)
|
||||||
_CrtSetReportHook( &msvcrtSilentReportHook );
|
_CrtSetReportHook( &msvcrtSilentReportHook );
|
||||||
#endif // if defined(_MSC_VER)
|
#endif // if defined(_MSC_VER)
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ namespace JsonTest {
|
|||||||
if ( static_cast< U >( expected ) != actual )
|
if ( static_cast< U >( expected ) != actual )
|
||||||
{
|
{
|
||||||
result.addFailure( file, line, expr );
|
result.addFailure( file, line, expr );
|
||||||
result << "Expected: " << expected << "\n";
|
result << "Expected: " << static_cast< U >( expected ) << "\n";
|
||||||
result << "Actual : " << actual;
|
result << "Actual : " << actual;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user