如何在pro文件中定义配置?
默认情况下,我们有两个配置,调试和发布。我想添加2个其他配置但不在 pro.user 中添加!在专业文件。
答案 0 :(得分:5)
你的问题有点不清楚。听起来您可能正在使用命令行中的“debug”和“release”进行构建,并且您希望添加与此类似的构建变体。
如果是这样的话......其机制是addExclusiveBuilds
。这是一个例子。如果您不习惯阅读qmake代码,我建议不要乱用它。
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
}
答案 1 :(得分:0)
如果我理解你在说什么,你可以在CONFIG
变量中添加你想要的内容:
CONFIG += user_setting
...
user_setting: message( "compiling with user_setting" )
请参阅qmake manual,其中涉及CONFIG
变量,尤其是在该部分的末尾附近。