Parsa Mousavi
Parsa Mousavi

Reputation: 1212

QMake : "Extra characters after test expression error" when using the "system()" function

I want to check the compiler versions present in the system and based on that , I want to define some macros.What I've added to the .pro file is as follows :

7 linux-g++ {
8    system( g++ --version | grep -e "\7.[0-9]" ) {
9        message( "g++ version 7.x found" )
10        QMAKE_CXX = x86_64-linux-gnu-g++-7
11    }
12    else system( g++ --version | grep -e "\<8.[0-9]" ) {
13        message( "g++ version 8.x found" )
14        QMAKE_CXX += x86_64-linux-gnu-g++-8
15        DEFINES += HAS_FILESYSTEM_SPEC
16    }
17    else system( g++ --version | grep -e "\<10.[0-9]" ) {
18        message( "g++ version 10.x found" )
19        QMAKE_CXX += x86_64-linux-gnu-g++-10
20        DEFINES += HAS_FILESYSTEM_SPEC
21    }
22    else {
23        error( "Unknown system/compiler configuration" )
24    }
25 }

But after that I got the following error:

Extra characters after test expression.

For the lines 12 and 17.

Upvotes: 0

Views: 771

Answers (1)

wthung
wthung

Reputation: 167

By below sample:

VERSION = $$system(g++ --version)
contains( VERSION, 7.[0-9].[0-9] ) {
    message(g++ 7.x version)
}
else {
    message(not g++ 7.x version)

    contains( VERSION, 4.[0-9].[0-9] ) {
        message(g++ 4.x version)
    }
    else {
        message(not g++ 4.x version)
    }
}

We got the output when our g++ version is 4.9.3.

Project MESSAGE: not g++ 7.x version
Project MESSAGE: g++ 4.x version

See: https://doc.qt.io/qt-5/qmake-function-reference.html#system-replace

Upvotes: 1

Related Questions