modifying AndroidManifext.xml with CMake variable
-
Hi -
I've brought this subject up before, but I need to go a bit further.
I need to introduce version numbering into my application, which will run on desktops and Android devices. I'd like to have a single place where I can define my version number (as a string is fine), and have it used in all environments.
I know that for Android, the version number comes from the AndroidManifest.xml file, but I'm hazy on the syntax. For example:
-
what exactly is the meaning of the -- and %% in these fields? If this is documented somewhere, please feel free to refer me.
-
can I populate this field with a CMake variable, such as:
set(MYAPP_VERSION_NBR "1.0.3")
and if so, how?
- if #2 is in fact possible, can I also use the value to set the value within my app as well, so that I can use it in the desktop builds?
QCoreApplication::setApplicationVersion(/* what would I put in here? */)
Thanks for any enlightment on this overall issue.
-
-
Well, I put something together that works, partly based on this article:
CMakeLists.txt snippet:
# we set the version numbers here now. set (NGA_PRODUCT_ID "123") set (NGA_VERSION_MAJOR "1") set (NGA_VERSION_MINOR "0") # configure a header file to pass some of the CMake settings # to the source code configure_file ( "${PROJECT_SOURCE_DIR}/versionnumber.h.in" "${PROJECT_BINARY_DIR}/versionnumber.h" )
A new file:
// versionnumber.h.in // the configured options and settings for version numbers #define NGA_PRODUCT_ID @NGA_PRODUCT_ID@ #define NGA_VERSION_MAJOR @NGA_VERSION_MAJOR@ #define NGA_VERSION_MINOR @NGA_VERSION_MINOR@
main.cpp (for now):
#include "versionnumber.h" int main(int argc, char *argv[]) { // macros below are defined in versionnumber.h.in QString version = QString::number(NGA_PRODUCT_ID) + "." + QString::number(NGA_VERSION_MAJOR) + "." + QString::number(NGA_VERSION_MINOR); QCoreApplication::setApplicationVersion(version); ...
It works, but I'm not thrilled with it, because I'm bypassing the entry in the manifest file. If someone can show me how to use the CMake variables in the manifest file, I'd appreciate it. I also wasn't able to define those CMake variables as strings (tried various combinations of quotation marks), so I have to convert the numbers at runtime, which is a bit of a hack.
Any suggestions are welcome. Thanks...
-