Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Add variable to project file in Qt creator



  • Hello there, I want to generate code coverage report for my Qt project.
    Code coverage tool asks me to add a variable with arguments to my .pro file, however when I add those variable there seems to be no effect.
    I have a build log with code coverage executed from Codeblocks IDE-which shows where all arguments should go:

    -------------- Build: Debug in Genome (compiler: GNU GCC Compiler)---------------
    [ 50.0%] ctc32 -i m g++.exe -Wall -fexceptions -g -Weffc++ -Wextra -std=gnu++14 -Og -g -std=c++1z -IC:\Boost\include -c E:\Projects\Genome\src\main.cpp -o obj\Debug\main.o
    [100.0%] ctc32 -i m g++.exe  -o bin\Debug\Genome.exe obj\Debug\main.o
    ---------------------------------------------------------------------------------
    

    Here variable to add is: ctc32 and arguments are: -i m and they need to be executed before g++ is called.

    • I added variables to project file but I don't know how to pass it to qmake so that it can be called just before compiler is called?

    • I tried to edit Make files directly but they are auto generated each time project is build.

    Thank you


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    How exactly did you add that ?

    Not to nitpick but ctc32 is not a variable it's an executable or a script.



  • Hello thanks for reply,
    Yes ctc32 is an executable and args -i m for instrumentation multi-condition code coverage.
    I added these lines to my project file.

    CodeCoverage {
     CTC32 += ctc32 -i m
    }
    
    QMAKE_CC  = CTC32$$QMAKE_CXX
    QMAKE_CXX = CTC32$$QMAKE_CXX
    

    I really don't understand how to tell Qt creator to call ctc32 before calling g++ (or in other words ctc32 will call g++). I had a look on qmake Variable Reference but this is the only thing I got.

    Thank you