Menu

Build Experience - some ramblings

2019-10-20
2019-11-05
  • John Coffey

    John Coffey - 2019-10-20

    I wanted to give my feeback regarding building cppcheck and cppcheck-gui from a new user perspective. I finally got the gui to build - hopefully successfully, but it required quite a bit of trial and error to get it right and this was not fully addressed in the github project info page.

    My esperiences are a little unorganized and certainly incomplete here, but I wanted to capture and share them while they were fresh. Now that I have things working, I'll probaby just to a git pull and rebuild.

    My windows 10 setup comprises:

    QT

    QT 5.13.1 with a Visual Studio 2017 toolchain (although I am using Visual Studio 2019 which has ABI compatibility).

    my QT and Associated Visual Studio toolchain are installed in their default locations:

    C:\Qt\5.13.1\
    C:\Qt\5.13.1\msvc2017_64
    

    Note I added the charts optional component, as I noticed that it was an optional component listed in the gui/CMakeLists.txt build option for the GUI project. It is not clear why this is required.

    if (HAVE_RULES)
        target_link_libraries(cppcheck-gui pcre)
    endif()
    target_link_libraries(cppcheck-gui Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport)
    if(WITH_QCHART)
        target_compile_definitions (cppcheck-gui PRIVATE HAVE_QCHART )
        target_link_libraries(cppcheck-gui Qt5::Charts)
    endif()
    

    From the https://github.com/danmar/cppcheck repository page, I tried to build the QT GUI

    Visual Studio 2019 Community edition

    I already had the Extensions/Qt VS Tools plugin installed here, as I develop an internal application based on QT. I needed to use this as the qt build instructions above did not create it for me. The QT build instructions listed in the https://github.com/danmar/cppcheck repository page shown below did not work for me and also it is a bit confusing as the cmake instuctions mentioned above the qmake instructions indicate:

    cmake
    ...
    
    If you want to compile the GUI you can use the flag -DBUILD_GUI=ON
    
    For rules support (requires pcre) use the flag -DHAVE_RULES=ON
    
    For release builds it is recommended that you use: -DUSE_MATCHCOMPILER=ON
    

    and then

    qmake
    You can use the gui/gui.pro file to build the GUI.
    
    cd gui
    qmake
    make
    

    Microsoft VCPKG package manager

    I needed this to make sure that the dependencies for PCRE were successfully satisfied. After following the installation advice from https://github.com/microsoft/vcpkg it was simply a matter of typing vcpkg install pcre:x64-windows to download and build release and debug versoins of the pcre library. One interesting part of this is that these headers are made available system wide if the following vckpg option is run (it will prompt for admin privileges; presumably to install the headers somewhere globally accessible. The site says:

    Then, to hook up user-wide integration, run (note: requires admin on first use)
    
    PS> .\vcpkg integrate install
    Linux:~/$ ./vcpkg integrate install
    

    Issues with the code

    I needed to make sure that commas in the csv file were properly escaped and also the ID field was missing. Sometimes its easier to capture everything and filter the type of error in the CSV file. The ID field was ideal for this and was previously missing. Not sure if I should respect the "show ID" checkbox in the settings, probably not as that is just for the cppcheck GUI output not for the expot.

    void CsvReport::writeHeader()
    {
        // No header for CSV report
        // @JC added CSV header
        mTxtWriter << "File, Line, Severity, Id, Summary" << endl;
    }
    
    void CsvReport::writeError(const ErrorItem &error)
    {
        /*
        Error as CSV line
        gui/test.cpp,23,error,Mismatching allocation and deallocation: k
        */
    
        const QString file = QDir::toNativeSeparators(error.errorPath.back().file);
        QString line = QString("%1,%2,").arg(file).arg(error.errorPath.back().line);
        //@JC line += QString("%1,%2").arg(GuiSeverity::toString(error.severity)).arg(error.summary);
    
        // @JC error identifier added after severity
        // @JC not sure if I need to consider the hidden ID preferences field
        // @JC probably not as this is always present
        // @JC need to escape embedded commas, much easier to replace them with semicolons
        auto escapedSummary = error.summary;
        escapedSummary.replace(",", ";");
        line += QString("%1,%2,%3").arg(GuiSeverity::toString(
            error.severity)).arg(error.errorId).arg(escapedSummary);
    
        mTxtWriter << line << endl;
    }
    

    I just wanted to capture my diff between the current head of the master branch to show you that I needed to add the pcre components and I needed to manually modify the cppcheck.sln file to add in the gui project. Note that the gui x64 settings are not quite correct as the pcre x64 library (imported from vcpkg is pcre.lib and not pcre64.lib - strange but I wanted to make you aware of this discrepancy.

    $ git status
    On branch master
    Your branch is up to date with 'origin/master'.
    
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
            modified:   cppcheck.sln
            modified:   gui/csvreport.cpp
            modified:   lib/cppcheck.vcxproj
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
            externals/pcre.h
            externals/pcre.lib
            gui/.qmake.stash
            gui/gui.vcxproj
            gui/gui.vcxproj.filters
    
    no changes added to commit (use "git add" and/or "git commit -a")
    

    Misra

    Mi misra experience was not the best but eventually I got it to work. Not sure if there is some issue with the setup but initially I did not have python installed and I was unable to save the misra checkbox or the clang settings until I installed python,

     
  • versat

    versat - 2019-11-05

    Thanks for this detailed feedback (and sorry for such a late reply).
    For testing / development even on Windows I use Qt with Qt Creator for the GUI. I have never tried to build it with Visual Studio. I do not know how the other developers build the GUI.

    Regarding the CSV export:
    There seem to be different types of format that are used for CSV.
    And there is an RFC: https://tools.ietf.org/html/rfc4180
    There is an interesting discussion on stackoverflow:
    https://stackoverflow.com/questions/769621/dealing-with-commas-in-a-csv-file
    I like the answer from Corey Trager who is referencing the RFC4180.
    So, fields with a , should be enclosed by ". " in fields must be escaped with another " then.
    I guess this would be a good solution.
    Maybe you like to implement that and create a Pull Request on GitHub?

    Regarding the MISRA addon:
    Hmm, yeah it is a bit unlucky if one has to find out that Python is required.
    The setup does not install Python and i guess this is not planned. It would make maintaining the Python versions installed on a system even harder.
    I think it should maybe be communicated to the user in a better way that Python is required to run the addons. A good place would be the project file configuration window where the addons can be enabled i guess.
    I will create a ticket if there is not already one.
    Would that be acceptable or can you imagine a better place / way to tell the user about the Python requirements?

     

    Last edit: versat 2019-11-05
  • versat

    versat - 2019-11-05

    I have created ticket https://trac.cppcheck.net/ticket/9456 suggesting a better communication about the Python requirement for the addons.

     

Log in to post a comment.