diff --git a/.gitignore b/.gitignore index 2a43f4cd9b9..791e16cc7b6 100644 --- a/.gitignore +++ b/.gitignore @@ -39,9 +39,13 @@ gui/*.qm doxyoutput/ # qmake generated +src/Makefile +build *.sdf ipch *.opensdf *.orig tags +Cppcheck.xcodeproj/*.mode1v3 +Cppcheck.xcodeproj/*.pbxuser \ No newline at end of file diff --git a/CMake/xmlto.cmake b/CMake/xmlto.cmake new file mode 100644 index 00000000000..ab7f0e3b77d --- /dev/null +++ b/CMake/xmlto.cmake @@ -0,0 +1,103 @@ +# - Convert XML docBook files to various formats +# This will convert XML docBook files to various formats like: +# man html txt dvi ps pdf +# macro XMLTO(outfiles infiles... MODES modes...) + +set ( XmlTo_FOUND false ) + +find_program ( XMLTO_EXECUTABLE + NAMES xmlto + DOC "path to the xmlto docbook xslt frontend" +) + +if ( XMLTO_EXECUTABLE ) + set ( XmlTo_FOUND true ) +endif ( XMLTO_EXECUTABLE ) + +if ( NOT XmlTo_FIND_QUIETLY ) + if ( XmlTo_FIND_REQUIRED ) + FATAL_ERROR ( "xmlto not found" ) + endif ( XmlTo_FIND_REQUIRED ) +endif ( NOT XmlTo_FIND_QUIETLY ) + +macro ( _XMLTO_FILE outfiles mode) + #special settings + set ( XMLTO_FILEEXT_man 1 ) + set ( XMLTO_MODE_html xhtml-nochunks ) + + if ( NOT XMLTO_MODE_${mode}) + set ( XMLTO_MODE_${mode} ${mode} ) + endif ( NOT XMLTO_MODE_${mode} ) + if ( NOT XMLTO_FILEEXT_${mode} ) + set ( XMLTO_FILEEXT_${mode} ${mode} ) + endif ( NOT XMLTO_FILEEXT_${mode} ) + + foreach ( dbFile ${ARGN} ) + #TODO: set XMLTO_FILEEXT_man to value from + if ( "${mode}" STREQUAL "man" ) + file ( READ "${dbFile}" _DB_FILE_CONTENTS ) + string ( REGEX MATCH "[^<]*" XMLTO_FILEEXT_${mode} "${_DB_FILE_CONTENTS}" ) + string ( REGEX REPLACE "^" "" XMLTO_FILEEXT_${mode} "${XMLTO_FILEEXT_${mode}}" ) + string ( REGEX REPLACE "[[:space:]]" "" XMLTO_FILEEXT_${mode} "${XMLTO_FILEEXT_${mode}}" ) + endif ( "${mode}" STREQUAL "man" ) + + get_filename_component ( dbFilePath ${CMAKE_CURRENT_BINARY_DIR}/${dbFile} PATH ) + get_filename_component ( dbFileWE ${dbFile} NAME_WE ) + get_filename_component ( dbFileAbsWE ${dbFilePath}/${dbFileWE} ABSOLUTE ) + + add_custom_command ( + OUTPUT ${dbFileAbsWE}.${XMLTO_FILEEXT_${mode}} + COMMAND ${XMLTO_EXECUTABLE} ${XMLTO_COMMAND_ARGS} -o ${CMAKE_CURRENT_BINARY_DIR} + ${XMLTO_MODE_${mode}} "${CMAKE_CURRENT_SOURCE_DIR}/${dbFile}" + MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${dbFile} + VERBATIM + ) + + set ( ${outfiles} + ${${outfiles}} + ${dbFileAbsWE}.${XMLTO_FILEEXT_${mode}} + ) + endforeach ( dbFile ) +endmacro ( _XMLTO_FILE outfiles ) + +macro ( XMLTO ) + set ( XMLTO_MODES ) + set ( XMLTO_FILES ) + set ( XMLTO_HAS_MODES false ) + set ( XMLTO_ADD_DEFAULT false ) + foreach ( arg ${ARGN} ) + if ( ${arg} STREQUAL "MODES" ) + set ( XMLTO_HAS_MODES true ) + elseif ( ${arg} STREQUAL "ALL" ) + set ( XMLTO_ADD_DEFAULT true ) + else ( ${arg} STREQUAL "MODES" ) + if ( XMLTO_HAS_MODES ) + set ( XMLTO_MODES ${XMLTO_MODES} ${arg} ) + else ( XMLTO_HAS_MODES ) + set ( XMLTO_FILES ${XMLTO_FILES} ${arg} ) + endif ( XMLTO_HAS_MODES ) + endif ( ${arg} STREQUAL "MODES" ) + endforeach ( arg ${ARGN} ) + if ( NOT XMLTO_MODES ) + set ( XMLTO_MODES html ) + endif ( NOT XMLTO_MODES ) + + foreach ( mode ${XMLTO_MODES} ) + _xmlto_file ( XMLTO_FILES_${mode} ${mode} ${XMLTO_FILES} ) + if ( XMLTO_ADD_DEFAULT ) + add_custom_target ( ${mode} ALL + DEPENDS ${XMLTO_FILES_${mode}} + VERBATIM + ) + else ( XMLTO_ADD_DEFAULT ) + add_custom_target ( ${mode} + DEPENDS ${XMLTO_FILES_${mode}} + VERBATIM + ) + endif ( XMLTO_ADD_DEFAULT ) + endforeach ( mode ) + + set ( XMLTO_MODES ) + set ( XMLTO_FILES ) +endmacro ( XMLTO ) + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000000..efa4e400ec7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,35 @@ +# Minimal CMake build file +# Builds: +# - static library from lib directory +# - commandline executable +# - test suite +# - Qt GUI + +# To build with CMake: +# - install CMake 2.6 or later +# - $ cmake . +# - $ make + +cmake_minimum_required (VERSION 2.6) + +PROJECT(CPPCHECK) + +# Building lib as static library is disabled due to bug +# #1299 CMake: The CheckClass is not used +# https://sourceforge.net/apps/trac/cppcheck/ticket/1299 +# Instead lib code is included directly into cli and gui targets +# ADD_SUBDIRECTORY(lib) + +ADD_SUBDIRECTORY(cli) + +# Exclude tests from command line targets but include them to VS IDE targets. +# There is 'make check' -target for compiling and running tests from +# command line. +IF (MSVC_IDE) + ADD_SUBDIRECTORY(test) +ELSE (MSVC_IDE) + ADD_SUBDIRECTORY(test EXCLUDE_FROM_ALL) +ENDIF (MSVC_IDE) + +ADD_SUBDIRECTORY(gui) +ADD_SUBDIRECTORY(man) diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt new file mode 100644 index 00000000000..9cdb87a4b74 --- /dev/null +++ b/cli/CMakeLists.txt @@ -0,0 +1,54 @@ +# Minimal CMake build file to build cppcheck command line executable + +project(cppcheck) + +SET(CHECKCLI_HDRS + cppcheckexecutor.h + threadexecutor.h +) + +SET(CHECKCLI_SRCS + cppcheckexecutor.cpp + threadexecutor.cpp + main.cpp +) + +# Add Windows resource file +if (WIN32) + SET(CHECKCLI_HDRS + ${CHECKCLI_HDRS} + resource.h + ) + + SET(CHECKCLI_SRCS + ${CHECKCLI_SRCS} + cppcheck.rc + ) +endif (WIN32) + +# Libraries to link +#set(CHECK_LIBS +# checklib +#) + +aux_source_directory(${CPPCHECK_SOURCE_DIR}/lib LIB_SRCS) + +# Windows needs additional shlwapi library +if (WIN32 AND NOT CYGWIN) +set(CHECK_LIBS + ${CHECK_LIBS} + shlwapi +) +endif (WIN32 AND NOT CYGWIN) + +if (CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS + ${CMAKE_CXX_FLAGS} + "-Wall -Wextra -pedantic" + ) +endif (CMAKE_COMPILER_IS_GNUCXX) + +include_directories (${CPPCHECK_SOURCE_DIR}/lib) +ADD_EXECUTABLE(cppcheck ${CHECKCLI_SRCS} ${CHECKCLI_HDRS} ${LIB_SRCS}) +TARGET_LINK_LIBRARIES(cppcheck ${CHECK_LIBS}) + diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt new file mode 100644 index 00000000000..0fb32182e04 --- /dev/null +++ b/gui/CMakeLists.txt @@ -0,0 +1,141 @@ +# Minimal CMake build file to build cppcheck Qt GUI + +# find and setup Qt4 for this project +find_package(Qt4) + +IF(QT4_FOUND) + +# Add needed Qt modules +set(QT_USE_QTMAIN TRUE) +set(QT_USE_QTXML TRUE) +include(${QT_USE_FILE}) + +include_directories (${CPPCHECK_SOURCE_DIR}/lib) +# Generated files (in build directory) need to know gui directory +include_directories (${CPPCHECK_SOURCE_DIR}/gui) + +# Header files - listed for mocking +SET(CHECK_HEADERS + aboutdialog.h + applicationdialog.h + applicationlist.h + checkthread.h + common.h + csvreport.h + fileviewdialog.h + mainwindow.h + projectfile.h + report.h + resultstree.h + resultsview.h + settingsdialog.h + threadhandler.h + threadresult.h + translationhandler.h + txtreport.h + xmlreport.h +) + +# Source files +SET(CHECKGUI_SRCS + aboutdialog.cpp + applicationdialog.cpp + applicationlist.cpp + checkthread.cpp + csvreport.cpp + fileviewdialog.cpp + main.cpp + mainwindow.cpp + projectfile.cpp + report.cpp + resultstree.cpp + resultsview.cpp + settingsdialog.cpp + threadhandler.cpp + threadresult.cpp + translationhandler.cpp + txtreport.cpp + xmlreport.cpp +) + +# Add Windows resource file +if (WIN32) + SET(CHECKGUI_SRCS + ${CHECKGUI_SRCS} + cppcheck-gui.rc + ) +endif (WIN32) + +# UI files +SET(CHECK_UIS + about.ui + application.ui + file.ui + main.ui + resultsview.ui + settings.ui +) + +# Translation files +SET(CHECK_TRANS + cppcheck_de.ts + cppcheck_fi.ts + cppcheck_pl.ts + cppcheck_se.ts + cppcheck_en.ts + cppcheck_nl.ts + cppcheck_ru.ts +) + +SET(CHECK_RCCS gui.qrc) + +aux_source_directory(${CPPCHECK_SOURCE_DIR}/lib LIB_SRCS) + +# Libraries to link +#set(CHECK_LIBS +# checklib +#) + +# Windows needs additional shlwapi library +if (WIN32 AND NOT CYGWIN) +set(CHECK_LIBS + ${CHECK_LIBS} + shlwapi + htmlhelp +) +endif (WIN32 AND NOT CYGWIN) + +if (CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS + ${CMAKE_CXX_FLAGS} + "-Wall" + ) +endif (CMAKE_COMPILER_IS_GNUCXX) + +# Generate rules for building source files from the resources +QT4_ADD_RESOURCES(CHECK_RCC_SRCS ${CHECK_RCCS}) + +# Process UI files +QT4_WRAP_UI(CHECK_UIS_H ${CHECK_UIS}) + +# Mock header files +QT4_WRAP_CPP(CHECK_MOC_SRCS ${CHECK_HEADERS}) + +# add translations ... +QT4_ADD_TRANSLATION(CHECK_QM ${CHECK_TRANS}) + +# Create folders for Visual Studio IDE +SOURCE_GROUP("Header Files" FILES ${CHECK_HEADERS}) +SOURCE_GROUP("Ui Files" ".ui$") +SOURCE_GROUP("Moc Files" "moc_.*cxx$") + +# Include binary directory where code from UI files gets created +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +ADD_EXECUTABLE(gui WIN32 ${CHECKGUI_SRCS} ${CHECK_MOC_SRCS} ${CHECK_HEADERS} + ${CHECK_UIS_H} ${CHECK_RCC_SRCS} ${LIB_SRCS}) +TARGET_LINK_LIBRARIES(gui ${CHECK_LIBS} ${QT_LIBRARIES}) + +ELSE(QT4_FOUND) +message("GUI not built since QT4 not found.") +ENDIF(QT4_FOUND) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 00000000000..eefeac42112 --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1,65 @@ +# Minimal CMake build file to build static cppcheck library +# This static library is used to build executables: +# - cli +# - tests +# - Qt GUI + +SET(CHECKLIB_HDRS + check.h + checkautovariables.h + checkbufferoverrun.h + checkclass.h + checkdangerousfunctions.h + checkexceptionsafety.h + checkheaders.h + checkmemoryleak.h + checkother.h + checkstl.h + checkunusedfunctions.h + classinfo.h + cppcheck.h + errorlogger.h + executionpath.h + filelister.h + filelister_unix.h + filelister_win32.h + mathlib.h + preprocessor.h + settings.h + token.h + tokenize.h +) + +SET(CHECKLIB_SRCS + checkautovariables.cpp + checkbufferoverrun.cpp + checkclass.cpp + checkdangerousfunctions.cpp + checkexceptionsafety.cpp + checkheaders.cpp + checkmemoryleak.cpp + checkother.cpp + checkstl.cpp + checkunusedfunctions.cpp + cppcheck.cpp + errorlogger.cpp + executionpath.cpp + filelister.cpp + filelister_unix.cpp + filelister_win32.cpp + mathlib.cpp + preprocessor.cpp + settings.cpp + token.cpp + tokenize.cpp +) + +if (CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS + ${CMAKE_CXX_FLAGS} + "-Wall -Wextra -pedantic" + ) +endif (CMAKE_COMPILER_IS_GNUCXX) + +ADD_LIBRARY(checklib STATIC ${CHECKLIB_SRCS} ${CHECKLIB_HDRS}) + diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 9c9badd04a5..83bf23ee415 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -223,7 +223,7 @@ unsigned int Tokenizer::sizeOfType(const Token *type) const if (type->str() == "double") return sizeof(long double); else if (type->str() == "long") - return sizeof(long long); + return sizeof(long); } return it->second; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000000..6131f29b69e --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,71 @@ +# Minimal CMake build file to build cppcheck test suite + +SET(CHECKTEST_HDRS + testsuite.h + tinyxml/tinystr.h + tinyxml/tinyxml.h +) + +SET(CHECKTEST_SRCS + testmemleak.cpp + testother.cpp + testpreprocessor.cpp + testautovariables.cpp + testredundantif.cpp + testbufferoverrun.cpp + testrunner.cpp + testcharvar.cpp + testsimplifytokens.cpp + testclass.cpp + teststl.cpp + testconstructors.cpp + testsuite.cpp + testcppcheck.cpp + testdangerousfunctions.cpp + testtoken.cpp + testdivision.cpp + testtokenize.cpp + testexceptionsafety.cpp + testunusedfunctions.cpp + testfilelister.cpp + testunusedprivfunc.cpp + testincompletestatement.cpp + testunusedvar.cpp + testmathlib.cpp + tinyxml/tinystr.cpp + tinyxml/tinyxml.cpp + tinyxml/tinyxmlerror.cpp + tinyxml/tinyxmlparser.cpp +) + +aux_source_directory(${CPPCHECK_SOURCE_DIR}/lib LIB_SRCS) + +# Libraries to link +#set(CHECK_LIBS +# checklib +#) + +# Windows needs additional shlwapi library +if (WIN32 AND NOT CYGWIN) +set(CHECK_LIBS + ${CHECK_LIBS} + shlwapi +) +endif (WIN32 AND NOT CYGWIN) + +if (CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS + ${CMAKE_CXX_FLAGS} + "-Wall -Wextra -pedantic" + ) +endif (CMAKE_COMPILER_IS_GNUCXX) + +include_directories (${CPPCHECK_SOURCE_DIR}/lib) +ADD_EXECUTABLE(test ${CHECKTEST_SRCS} ${CHECKTEST_HDRS} ${LIB_SRCS}) +TARGET_LINK_LIBRARIES(test ${CHECK_LIBS}) + +# Add custom 'make check' -target +# It compiles and runs tests +add_custom_target(check COMMAND test) +add_dependencies(check test) +