[SOLVED] qmake. including *.pri file due to condition



  • I'm trying to include source and header files by using "include *.pri" and due to some condition (also in the pri file)

    There are few following project's files:
    configure.pri
    @
    brand_number = 2

    isEqual(brand_number, "1"){
    project_name = project1
    }

    isEqual(brand_number, "2"){
    project_name = project2
    }

    message(project_name = $$project_name)
    @

    test_include_1/test_1.pri
    @
    SOURCES += test_include_1/test.cpp
    HEADERS += test_include_1/test.h
    INCLUDEPATH += test_include_1
    @

    test_include_2/test_2.pri
    @
    SOURCES += test_include_2/test.cpp
    HEADERS += test_include_2/test.h
    INCLUDEPATH += test_include_2
    @

    project1.pro
    @
    include(configure.pri)

    QT += core widgets
    TEMPLATE = app
    TARGET = $$project_name

    SOURCES += main.cpp
    mainwindow.cpp
    HEADERS += mainwindow.h
    FORMS += mainwindow.ui

    isEqual(brand_number,"1"){
    include(test_include_1/test_1.pri)
    message("include test_1.pri")
    }else:isEqual(brand_number,"2"){
    include(test_include_2/test_2.pri)
    message("include test_2.pri")
    }
    else{
    error("The parameter brand_number is incorrect!")
    }
    @

    Why "test_include_1/test_1.pri" is also included?!
    I see it in the project file's tree and "test_include_1/test_1.cpp" sometimes is included to Makefile. But sometimes is not.

    !http://oi61.tinypic.com/34grod4.jpg(File's tree in the QtCreator)!


  • Lifetime Qt Champion

    Hi,

    IIRC Qt Creator doesn't handle that the same way as qmake, it just shows what you have in your project not what the current configuration will use. Which is IMHO better, this way you don't need to fiddle your project every time you want to modify test_2 or test_1



  • [quote author="SGaist" date="1396905761"]Hi,

    IIRC Qt Creator doesn't handle that the same way as qmake, it just shows what you have in your project not what the current configuration will use. Which is IMHO better, this way you don't need to fiddle your project every time you want to modify test_2 or test_1[/quote]

    Hi SGaist,
    I wouldn't be care if QtCreator builds only one include during building always. But sometimes QtCreator builds both includes test_1 and test_2!

    And I've forgot to notice that in the real project the name of pri file is calculated dinamically.... Foolowing project file blows QtCreator's mind...
    @
    #configuration
    new_ui = 0
    brand_number = 1

    isEqual(brand_number,"0"){
    include1=test_a
    include2=
    }else:isEqual(brand_number,"1"){
    include1=test_b
    include2=
    }else:isEqual(brand_number,"2"){
    include1=
    include2=test_c
    }else:isEqual(brand_number,"3"){
    include1=
    include2=test_c
    #unknown brand number
    }else{
    error("Unknown brand number '$$brand_number' !")
    }

    message(project_name = $$project_name)
    message(new_ui = $$new_ui)
    message(brand_number = $$brand_number)
    message(include1 = $$include1)
    message(include2 = $$include2)

    QT += core widgets
    TEMPLATE = app
    TARGET = test_project

    SOURCES += main.cpp
    mainwindow.cpp
    HEADERS += mainwindow.h
    FORMS += mainwindow.ui

    isEqual(new_ui,"1"){
    include(new_ui/new_ui.pri)
    }else:!isEmpty(include1){
    include($$include1/$$include1".pri")
    }else:!isEmpty(include2){
    include($$include2/$$include2".pri")
    }
    else{
    error("The parameter brand_number is incorrect!")
    }
    @

    !http://oi59.tinypic.com/ac8j9v.jpg(What is the...)!



  • Oh!!! I've found the solution!
    Necessary to confuse QtCreator :)
    If the QtCreator cannot to calculate name of the included pri files then it doesn't include them. So we can use name of the included pri file like a variable and (!) this variable has to have few possible values in the project file.
    For example:
    @
    brand_number = 1

    isEqual(brand_number,"1"){
    included_file_path = test_a
    }else{
    included_file_path = undefined
    error("brand_number is incorrect!")
    }

    QT += core widgets
    TEMPLATE = app
    TARGET = test_project

    SOURCES += main.cpp
    mainwindow.cpp
    HEADERS += mainwindow.h
    FORMS += mainwindow.ui

    !isEmpty(included_file_path){
    include($$included_file_path/$$included_file_path".pri")
    }
    @

    If we delete line "included_file_path = undefined" then QtCreator calculates name of the pri file (because "included_file_path " can have only one value) and "included_file_path" will be included in the file tree every time and sometimes building will be failed...


  • Lifetime Qt Champion

    This looks a bit like a corner case. You should talk about it on the qt-creator mailing list, you'll find Qt Creator's developers/maintainers there



  • I now that it is corner case, but I have to provide with completed result and I'm compelled to resort to this way.

    Could you please advise where is it "qt-creator mailing list"? Is it some forum or just e-mail address?


  • Lifetime Qt Champion

    It's "here":http://lists.qt-project.org/mailman/listinfo/qt-creator

    Don't forget to register first


Log in to reply
 

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