如何在 pro 文件中定义配置?

发布于 2024-11-01 17:57:37 字数 113 浏览 0 评论 0原文

如何在 pro 文件中定义配置?

默认情况下,我们有两个配置,调试和发布。我想添加 2 个其他配置,但不在 pro.user 中!在专业文件中。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

许仙没带伞 2024-11-08 17:57:37

你的问题有点不清楚。听起来也许您当前正在从命令行使用“调试”和“发布”进行构建,并且您想要添加与此类似的自己的构建变体。

如果是这样的话......其机制是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
}

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
}
勿挽旧人 2024-11-08 17:57:37

如果我明白你在说什么,你可以将你想要的内容添加到 CONFIG 变量中:

CONFIG += user_setting
...
user_setting: message( "compiling with user_setting" )

请参阅 qmake 手册,其中讨论了 CONFIG 变量,特别是在本节末尾附近。

If I understand what you are saying, you add what you want to the CONFIG variable:

CONFIG += user_setting
...
user_setting: message( "compiling with user_setting" )

See the qmake manual where it talks about the CONFIG variable, especially near the end of the section.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文