Easy cross platform way to detect architecture in Qt Pro or QMake system?



  • Hello,

    I am wondering how I can create a Qt Creator / Qmake .pro file which can detect whether I am building for a 32-bit or 64-bit environment

    See the following code below for my current, working .pro file. The section that I commented out is for 64-bit builds.

    *What I would love is that there is a way for the build system to detect the 64-bit section based on architecture and activate that section in the same way that I can activate the sections for debug versus release.

    Bonus if this can be cross-platform.

    Thank you for your time!*

    @
    #-------------------------------------------------

    Project created by QtCreator 2015-01-21T16:01:26

    #-------------------------------------------------

    QT += core gui xml network

    CONFIG += c++11

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = CoolApp
    TEMPLATE = app

    win32:RC_ICONS += Icons/CoolApp.ico

    VERSION += 1.0.1.0
    QMAKE_TARGET_COMPANY = "Standard Company"
    QMAKE_TARGET_DESCRIPTION = "My cool application."
    QMAKE_TARGET_COPYRIGHT = "Copyright 2015 Me."
    QMAKE_TARGET_PRODUCT = "Cool App"

    SOURCES += main.cpp
    qtprimaryapplicationwindow.cpp
    qtchoosecsvfiles.cpp
    qtviewconvertedfiles.cpp
    qtaboutapplicationdialog.cpp
    qtprocessingoptionsandoutput.cpp
    qtdeletablelistwidget.cpp
    qtprocessingoptionswidget.cpp
    qtapplicationsettings.cpp
    qtprocesscsvfiles.cpp
    qtapplicationupdate.cpp
    qtupdatedialog.cpp
    qtutilityfunctions.cpp

    HEADERS += qtprimaryapplicationwindow.h
    qtchoosecsvfiles.h
    qtviewconvertedfiles.h
    qtaboutapplicationdialog.h
    qtprocessingoptionsandoutput.h
    qtdeletablelistwidget.h
    qtprocessingoptionswidget.h
    qtapplicationsettings.h
    qtprocesscsvfiles.h
    qtapplicationupdate.h
    qtupdatedialog.h
    qtutilityfunctions.h

    FORMS += qtprimaryapplicationwindow.ui
    qtchoosecsvfiles.ui
    qtviewconvertedfiles.ui
    qtaboutapplicationdialog.ui
    qtprocessingoptionsandoutput.ui

    CONFIG(debug, debug|release) {

    LogoFiles.path = $$OUT_PWD/debug/Logos
    LogoFiles.files = Logos/*
    
    IconFiles.path = $$OUT_PWD/debug/Icons
    IconFiles.files = Icons/*
    
    LicenseFiles.path = $$OUT_PWD/debug/License
    LicenseFiles.files = License/*
    
    ConfigurationFiles.path = $$OUT_PWD/debug/Configuration
    ConfigurationFiles.files = Configuration/*
    

    } else {

    LogoFiles.path = $$OUT_PWD/release/Logos
    LogoFiles.files = Logos/*
    
    IconFiles.path = $$OUT_PWD/release/Icons
    IconFiles.files = Icons/*
    
    LicenseFiles.path = $$OUT_PWD/release/License
    LicenseFiles.files = License/*
    
    ConfigurationFiles.path = $$OUT_PWD/release/Configuration
    ConfigurationFiles.files = Configuration/*
    

    }

    #CONFIG(debug, debug|release) {

    LogoFiles.path = $$OUT_PWD/debug/Logos

    LogoFiles.files = Logos/*

    IconFiles.path = $$OUT_PWD/debug/Icons

    IconFiles.files = Icons/*

    LicenseFiles.path = $$OUT_PWD/debug/License

    LicenseFiles.files = License/*

    ConfigurationFiles.path = $$OUT_PWD/debug/Configuration

    ConfigurationFiles.files = Configuration/*

    #} else {

    LogoFiles.path = $$OUT_PWD/release/Logos

    LogoFiles.files = Logos/*

    IconFiles.path = $$OUT_PWD/release/Icons

    IconFiles.files = Icons/*

    LicenseFiles.path = $$OUT_PWD/release/License

    LicenseFiles.files = License/*

    ConfigurationFiles.path = $$OUT_PWD/release/Configuration

    ConfigurationFiles.files = Configuration/*

    #}

    INSTALLS += IconFiles LogoFiles LicenseFiles ConfigurationFiles
    @


  • Lifetime Qt Champion

    Hi,

    IIRC you can use

    @contains(QMAKE_TARGET.arch, x86_64) {
    // cool 64bit stuff
    }@

    for that

    Hope it helps



  • This works!

    What's great is that you can switch easily between 32-bit and 64-bit like so:

    @
    contains(QMAKE_TARGET.arch, x86_64) {
    // cool 64bit stuff
    }

    !contains(QMAKE_TARGET.arch, x86_64) {
    // cool 32bit stuff
    }
    @


  • Lifetime Qt Champion

    @
    contains(QMAKE_TARGET.arch, x86_64) {
    // cool 64bit stuff
    } else {
    // cool 32bit stuff
    }@

    Would be cleaner


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.