CMake macro to only run lupdate - qt

For a couple of reasons we need the ability to run lupdate on our sources, run a script on the resulting ts files, and then run lrelease. We're using CMake for our builds so a CMake macro would be nice.
But the only ones I see either just run lrelease, or run lupdate followed by lrelease. Is there one I'm missing to just run lupdate?
Thanks.

You should use this guide:
https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/How-To-Build-Qt4-Software
You could add some options in CMake to call only 'lupdate' depending on your requirements.
Note that QT4_ADD_TRANSLATION must be changed to QT5_ADD_TRANSLATION if you are working with Qt 5.

Related

Detect incomplete translation files in Qt

I want to be able to detect if translations are missing for any language during my release build.
I'm using CMake to build the application and CMake is also running lupdate and lrelease. In this process I would like to display a warning if some translations are missing in the TS files. As far as I can see lupdate and lrelease does not allow detection of missing translations, I have checked the output when running the commands with -help option. According to the Qt docs:
Both lupdate and lrelease may be used with TS translation source files
which are incomplete. Missing translations will be replaced with the
native language phrases at runtime.
This is very fine, but I would really like some indication that the files are incomplete.
Any ideas?

find out what qmake executable is used inside a pro file

I need to call qmake in one of the make target commands. The question is how can I figure out which qmake has been called when executing this qmake. Like when in a bash script you ask for the executable.
Obviously I'm in an environment with multiple Qt installations, including defaults of Ubuntu 14.04 and qmake is the decider of which libraries are going to be fed into compilation (I'm not 100% sure on the later).
Any help is greatly appreciated!
I think this might be what you're looking for: http://doc.qt.io/qt-5/qmake-language.html#accessing-qmake-properties
$$[QT_INSTALL_BINS]/qmake should be the path.
Simply add a line that prints the version:
qmake --version

qmake touch function on windows

The qmake manual documents a touch function to update the time stamp of a file, see: touch(filename, reference_filename). It is recommended here to update the timestamp on a file, e.g.:
version.commands = touch $$version.target
Note: the qmake manual documents two parameters, e.g.:
version.commands = touch $$version.target $$version.depends
However, I can't get the touch function to work on Windows using either call. I suspect that qmake is simply calling the linux touch command, since it works fine on Fedora 23.
A workaround is to create a touch.cmd command file on Windows, e.g.:
#COPY /B %1+,, %1
and use the following in the .pro file:
version.commands = $$system(touch $$version.target)
But I would prefer to use the qmake touch function...
What is the correct way to invoke it in a .pro file so that it works on Windows?
In using qmake, it's critical to remember what things are happening on invocation of qmake and what's happening during the subsequent make/nmake call.
Anything that's specified after version.commands = is going to be executed when make gets invoked.
On the other hand, touch() is a qmake function that will get invoked when you run qmake.
Looking in the Qt source code dev branch as of today, there are just 4 uses of touch() within Qt itself, all in the qtbase/mkspecs/features directory, and none in the context of a .commands construct.

run a "source" bash shell script in qmake

I want to use the intel compiler for Qt, but using the intel compiler implies running the script
$ source /opt/intel/bin/compilervars.sh intel64
Of course, I could add this to ~/.bashrc, but this would not run it in QtCreator, where it still complains about missing icpc. So I want it to be a part of the main mkspec qmake file.
How can I execute that full bash command in qmake?
Short Answer: Using QMAKE_EXTRA_TARGETS and PRE_TARGET_DEPS, you can execute source /opt/intel/bin/compilersvars.sh intel64, but simply sourcing them will not solve your issue.
Long Answer: The QMake file is converted into a Makefile. Make then executes the Makefile. The problem you will run into is that Make executes each command in its own shell. Thus, simply sourcing the script will only affect one command, the command that executes the script.
There are a couple of possible ways to make things work:
Execute the script before starting Qt-Creator. I've actually done this for some projects where I needed to have special environment variables setup. To make my life easier, I created a shell command to setup the environment and then launch Qt-Creator.
Within Qt-Creator, modify the Build Environment for the project I've also used this trick. In your case, simply look at the environment setup by the script and change the "Build Environment" settings under the project tab for your project to match those setup by the script.
It might also be possible to modify QMake's compiler commands, but I am not sure you can make it execute two commands instead of one (source the script then execute the compiler). Further more, this will make the project very un-transportable to other systems.
You can create a shell script that does more or less the following:
#! /usr/bin/env sh
# Remove the script's path from the PATH variable to avoid recursive calls
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export PATH=${PATH/$SCRIPT_DIR:/}
# Set the environment up
source /opt/intel/bin/compilervars.sh intel64
# Call make with the given arguments
make "$#"
Save it into a file named "make" in an empty directory somewhere, make it executable, then change the build environment in QT Creator to prepend PATH with the script's directory:
PATH=[dir-of-make-script]:${Env:PATH}
You can do this either in the project settings or once and for all in the kit settings.
Like this, QT Creator will be fooled into calling your make script which sets up your environment before calling the actual make binary. I use a similar technique under Windows with Linux cross-toolchains and it has been working well so far.

GNU make --jobs option in QMAKE

I am using qmake to generate MinGW32 Makefiles for a small Qt C++ app we are developing. My problem: all those dual/quad core CPUs are sitting there idly while only one thread is doing the building. In order to parallelize things I tried passing --jobs 4 to make, but the problem is that qmake generates a generic makefile inside of which make gets called again with -f .
Is it possible to force qmake to add options to make when generating the makefile? Or maybe there's another way of setting the option outside of qmake altogether? I can't edit that specific Makefile since it's autogenerated each build.
Abusing $MAKE to pass options does not work in all cases. Oftentimes, (e.g. in the configure script of Qt on Unix), it's enclosed in double quotes ("$MAKE") to allow the command to contain spaces. I know because I used the same trick before it stopped working. Qt Support then suggested (rightfully) to use $MAKEFLAGS as in
set MAKEFLAGS=-j4
make
This works for me:
set MAKE_COMMAND=mingw32-make -j%NUMBER_OF_PROCESSORS%
The generic Makefile uses $(MAKE) when invoking make, so you can overwrite it using environment variables. Something like this should do it:
qmake
make MAKE="mingw32-make -j4"
Replace the values of MAKE as required of course :)

Resources