Qt World Summit: Register Today!

Using qmake to config project for gui or console

  • I'm trying to use the same project for both a console application and gui application. When processing qmake it should define the correct CONFIG and QT defines so it'll prepare the project for one of them.
    I thought I could create a variable of my own where I define the value as either console or gui, and then I'd use the eval() function. In my .pro file I added these lines:
    @APP_MODE = con_app
    eval(APP_MODE= con_app) {
    message("building for console");

    eval(APP_MODE = gui_app) {
    message("building for gui");
    Obviously, other than the messages there would be the proper CONFIG and QT defines for each. Unfortunately though, this seems not to be working. When running qmake in QtCreator, the general tab outputs both messages:
    @Project MESSAGE: console app
    Project MESSAGE: gui app
    Project MESSAGE: console app
    Project MESSAGE: gui app@
    Messages are also outputted twice, but I guess this is because qmake processes the .pro file twice or more times, not a big deal if it would properly evaluate APP_MODE as either con_app or gui_app.

    I then tried to use the contains() function instead of eval(), and this time it works, it correctly recognizes that APP_MODE contains either con_app or gui_app.

    What I'd like to know is if I am doing something wrong, and if it is a good approach for a "hybrid" .pro file.

Log in to reply