简体   繁体   English

Qt Creator(不是CMake)如何为不同的构建配置指定不同的文件?

[英]Qt Creator (not CMake) how to specify different files for different build configurations?

I have project in QT Creator (as.pro file, not as CMake).我在 QT Creator 中有项目(as.pro 文件,而不是 CMake)。 Now I want to add tests (gtest) as another build configuration, so I've added build configuration "debug_tests" (Projects -> Add -> Debug with name debug_tests).现在我想添加测试(gtest)作为另一个构建配置,所以我添加了构建配置“debug_tests”(项目->添加->调试,名称为debug_tests)。 Now I want to add specific main file for "debug_tests" and exclude from build my normal main file when the build configuration is choosen.现在我想为“debug_tests”添加特定的主文件,并在选择构建配置时从构建我的正常主文件中排除。 So I've tried:所以我试过:

test_debug:{
    message("Running tests:")
    SOURCES += \
        tests/MultiCellArticleModelTests.cpp \
        tests/main_tests.cpp
    LIBS += \
        -lgtest    
}

But it is not working, it is working when I do like that:但它不起作用,当我这样做时它正在起作用:

!debug_and_release:{
    message("Running tests:")
    SOURCES += \
        tests/MultiCellArticleModelTests.cpp \
        tests/main_tests.cpp
    LIBS += \
        -lgtest
}

But it is not good solution if I want to add more configurations.但如果我想添加更多配置,这不是一个好的解决方案。

Another solution which I see is to just add defines to compilation and have ifdef in my code.我看到的另一个解决方案是将定义添加到编译中并在我的代码中包含ifdef

Usually, tests are in their own sub-projects rather than part of some scope in your main source tree.通常,测试位于它们自己的子项目中,而不是主源代码树中某些 scope 的一部分。

This allows you to keep them cleanly separated from your main code and you can run them easily.这使您可以将它们与主代码完全分开,并且可以轻松运行它们。 You can even call make check to run the whole test suite that you created for your library/application.您甚至可以调用make check来运行您为库/应用程序创建的整个测试套件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM