[SOLVED]How to set options with qmake?
-
I don't know about how to do it the way you want, but I can suggest a slightly different one.
If you run
@qmake CONFIG+=myfeature@Then you can test for myfeature in a project file and conditionally include source code or add definitions like this:
@myfeature {
# rules to execute when myfeature IS defined:
DEFINES += MY_FEATURE_ENABLED
HEADERS += src/additional_feature.h
SOURCES += src/additional_feature.cpp
} else {
# rules to execute when myfeature NOT defined
DEFINES += MY_FEATURE_DISABLED
}@Actually, I use it in my project to enable/disable SVG support. But be careful about naming myfeature - don't name it like any of the files in mkspecs/features folder of Qt source.
-
Another option is to write a very simple configure script that writes out to a .pri file that is included by your .pro file. Sometimes it can also be useful to have such a script generate a header file that contains useful #defines or other declarations. For one project I have done something like this:
@
#!/bin/bashif [ "$1" = "crypto" ]; then
echo Enabling cryptographic support
echo "#define MAPS_CRYPTO" > src/mapscore/mapscore_config.h
echo "CONFIG += crypto" > src/mapscore/mapscore_config.pri
echo Wrote src/mapscore/mapscore_config.h and src/mapscore/mapscore_config.pri
elif [ "$1" = "nocrypto" ]; then
echo Disabling cryptographic support
echo "#undef MAPS_CRYPTO" > src/mapscore/mapscore_config.h
echo "CONFIG -= crypto" > src/mapscore/mapscore_config.pri
echo Wrote src/mapscore/mapscore_config.h and src/mapscore/mapscore_config.pri
else
echo "usage: configure [mode]"
echo "modes:"
echo " crypto enable cryptographic support"
fi
@Then in the .pro file I include the .pri file with:
@include( mapscore_config.pri )@
-
[quote author="ZapB" date="1301298762"]Another option is to write a very simple configure script that writes out to a .pri file that is included by your .pro file. Sometimes it can also be useful to have such a script generate a header file that contains useful #defines or other declarations.[/quote]
This way isn't very portable: you'll have to write separate scripts for separate platforms (e.g., Linux vs Windows). You can workaround this by writing your configure script in some interpreted language, available for all target platforms (Perl, Python, PHP, etc.). But it will introduce additional dependency and anybody who wishes to compile your app will need to install this language (if it's not already included on their platform).Anyway, this option is still good if you only target similar platforms.
-
You're right, by the way, cmake might be an option, too. Everything depends on how advanced the conditional rules have to be. My solution is good for trivial tests, like include this if condition is true. If you need some advanced tests, like include this if condition is true and this library is available (+ test for library fetures) or the other library is available and additional conditions are set, then it's better to write a configure script or use a build system like cmake.
-
Thanks guys, the way Lёppa posted at the beginning is what i was looking for.
what i did was:@webp_support {
# rules to execute when myfeature IS defined:
DEFINES += WEBP_SUPPORT
#HEADERS += src/additional_feature.h
#SOURCES += src/additional_feature.cpp
} else {
# rules to execute when myfeature NOT defined
#DEFINES += MY_FEATURE_DISABLED
}@and in main.cpp added:
@#ifdef WEBP_SUPPORT
//if i do qmake CONFIG+=webp_support
qDebug()<<"webp support";
#else
qDebug()<<"not webp support";
#endif@to test it