Qt Creator: Enforce a release-only build in the qmake .pro file?
-
Using Qt Creator 17.0.2 on Linux Ubuntu with different Qt versions (5.15.13 and 6.4.x and greater, up to 6.9.3):
I have a SUBDIRS project to build some static libraries for which I would like to only allow release builds.
I have added these lines in the.pro
files that are referenced by theSUBDIRS
project:CONFIG -= debug debug_and_release CONFIG += release
Then I check this:
CONFIG(debug,debug|release):error("Only release builds of this library are allowed!")
My default build directory template in "Preferences->Build & Run->Default Build Properties" looks like this:
../build/%{Project:Name}/Qt-%{Qt:Version}/%{BuildConfig:Name}
So even though I check the build configuration in the
.pro
file, I get both Debug and Release versions of the libraries if I made the mistake of clicking the wrong box when I configure the project (i.e. the first time it is opened in Qt Creator when you are prompted to select your kit(s)). It also looks as if the actual libraries are not the same size, so probably not interchangeable.I can set this up for my own development environment, but there are other developers in this project who might have trouble getting this right. That is why I'd like to have the
.pro
file take care of this. -
I found a usable workaround, but am open to other suggestions!
The project file
Libs.pro
builds the three subprojects, one per library. I just wrapped everything in a test fordebug
:CONFIG(release,debug|release) { TEMPLATE = subdirs PROJECT_DIR = $$clean_path($${top_srcdir}/../) THIRD_DIR = $${PROJECT_DIR}/3rd_party SUBDIRS = \ $${THIRD_DIR}/A/A_lib.pro \ $${THIRD_DIR}/B/B_lib.pro \ $${THIRD_DIR}/C/C_lib.pro } else { error("Only release builds are allowed for these libraries! Please close Qt Creator, delete the 'Libs.pro.user' file and check your kit selection carefully.") }
Works for me.
-