Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
433 views
in Technique[技术] by (71.8m points)

c++ - Finding compiler vendor / version using qmake

Is there any way to get the version and vendor of the compiler used by the user through qmake? What I need is to disable building some targets of my project when g++ 3.x is used and enable them when g++ 4.x is used.

Update: Most answers targeted the preprocessor. This is something that I want to avoid. I don't want a target to be build for a specific compiler version and I want this decision to be made by the build system.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In addition to ashcatch's answer, qmake allows you to query the command line and get the response back as a variable. So you could to something like this:

linux-g++ {
    system( g++ --version | grep -e "<4.[0-9]" ) {
        message( "g++ version 4.x found" )
        CONFIG += g++4
    }
    else system( g++ --version | grep -e "<3.[0-9]" ) {
        message( "g++ version 3.x found" )
        CONFIG += g++3
    }
    else {
        error( "Unknown system/compiler configuration" )
    }
}

Then later, when you want to use it to specify targets, you can use the config scoping rules:

SOURCES += blah blah2 blah3
g++4: SOURCES += blah4 blah5

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...