Search code examples
qtqmake

how to define a config in pro file?


how to define a config in pro file ?

by default, we have two config, debug and release. I want to add 2 other config but not in pro.user ! in pro file.


Solution

  • Your question is a bit unclear. It sounds like maybe you're currently building with "debug" and "release", from the command line, and you want to add your own build variants similar to that.

    If that's the case... the mechanism for this is addExclusiveBuilds. Here is an example. I wouldn't recommend to mess around with it if you aren't comfortable reading qmake code.

    TEMPLATE = app
    SOURCES = main.cpp
    
    # Adds two build variants.
    # One of them builds the app with optimal compiler flags,
    # the other one builds the app with support for collecting coverage data.
    # For the first one, CONFIG will contain `optimized' and a Makefile.Optimized will be     generated.
    # For the second, CONFIG will contain `coverage' and a Makefile.Coverage will be generated.
    # There will also be a top-level Makefile which invokes both the sub-makefiles.
    addExclusiveBuilds(optimized, Optimized, coverage, Coverage)
    
    CONFIG(optimized, coverage|optimized) {
        message(I am in the optimized build variant)
        QMAKE_CXXFLAGS += -O3
    
        TARGET = myapp-optimized
    }
    else:CONFIG(coverage, coverage|optimized) {
        message(I am in the coverage build variant)
        QMAKE_CXXFLAGS += --coverage
        QMAKE_LFLAGS += --coverage
    
        TARGET = myapp-coverage
    }
    else {
        message(I am in the glue project which contains the build variants)
    
        # This will cause a `make' to build both optimized and coverage
        # variants by default.
        CONFIG += build_all
    }