Is there a way to use the .pro file in Qt to call another Makefile? For example, in a makefile, you could use:
make -f /other/path/Makefile
Is there anything like using the pro file for Qt?
Something like this should work:
QMAKE_EXTRA_TARGETS += other
PRE_TARGETDEPS += other
other.commands = make -f /other/path/Makefile
this will cause make -f /other/path/Makefile to be called as part of the make process, and will also give you the ability to type make other to just run that command.
Related
I want to build my resources with qmake as follows [Qt 5.5]:
imageTarget.target = images.rcc
imageTarget.depends = $$PWD/images.qrc
imageTarget.commands = rcc -binary -no-compress $$PWD/images.qrc -o $$OUT_PWD/images.rcc
QMAKE_EXTRA_TARGETS += imageTarget
When I run qmake for my .pro file, it generates the make rule for target images.rcc target as expected:
images.rcc: /path/to/images.qrc
rcc -binary -no-compress /path/to/images.qrc -o /output/path/to/images.rcc
So far so good.
However, what I would expect is that running qmake would also generate the output file images.rcc and it does not.
But when I go into the makefile directory and type in the command "make images.rcc", then the images.rcc is generated. Am I missing a point? How can I make target in the qmake step without the need of extra make?
With
QMAKE_EXTRA_TARGETS += imageTarget
you just define a new target - but it is not automatically built when running make.
Try to add
PRE_TARGETDEPS += images.rcc
This should automatically build a new images.rcc when running make if images.qrc has changed.
qmllint is a syntax checker for QML files written by KDAB which is shipped as a plugin with Qt 5.4. It's usage is based on command line like:
$ qmllint myFile.qml
Is it possible to use it directly in Qt Creator?
QtCreator
You can actually set custom commands in QtCreator to be run without cluttering your qmake file manually because that will effect all the other people in your project, too.
So, if you want to make sure that you only do it for yourself and not clutter it for others, using QtCreator's shiny GUI, I would suggest to follow this:
Projects (left pane)
Build & Run
Build Steps
Add Build Step
Here is the screen how exactly you can set up the command with the corresponding arguments:
With QtCreator's GUI, you can easily change the order with the same concept without touching your project file should you prefer that. There are use cases for that like:
You would not want to run any steps, not even qmake, before the qml file is properly validated
You only have C++ files, so there is no such a thing as "linkage".
etc.
qmake
There are other "generic" approaches useful outside QtCreator, although you asked about this IDE, like putting the command into variables like:
QMAKE_PRE_LINK
QMAKE_PRE_LINK = qmllint $$PWD/path/to/myFile.qml
QMAKE_POST_LINK
QMAKE_POST_LINK = qmllint $$PWD/path/to/myFile.qml
System command execution from your qmake project file
system("qmllint $$PWD/path/to/myFile.ml")
Adding custom targets with QMAKE_EXTRA_TARGETS
qmllinttarget.commands = qmllint $$PWD/path/to/myFile.qml
QMAKE_EXTRA_TARGETS += qmllinttarget
I believe the point in this question is not to have a check for a single file with known name, but to run qmllint on all qml files of a project. Ideally this should be done before building anything, because a build with erroneous qml files is likely to have no real value.
Extending lpapp's answer and playing around with qmake a bit, I came to this solution:
ALL_PWD_QML_FILES = $$files($${_PRO_FILE_PWD_}/*.qml , true)
# a command that creates an empty file with a given name.
win32 {
MY_TOUCH_CMD = copy NUL
} else {
MY_TOUCH_CMD = touch
}
qmllint.output = .qmllint/${QMAKE_FILE_BASE}.qmllint
qmllint.input = ALL_PWD_QML_FILES
qmllint.commands = qmllint ${QMAKE_FILE_NAME} && $${MY_TOUCH_CMD} ${QMAKE_FILE_OUT}
qmllint.CONFIG += no_link recursive target_predeps
QMAKE_EXTRA_COMPILERS += qmllint
This assumes that all qml files are either in the same directory as the .pro file or in subdirectories.
It will run qmllint on all qml files before the actual build, but only if any qml file has changed since a previous build.
Tested on Windows with Qt 5.11 and MSVC.
You can use QMAKE_POST_LINK variable in your .pro file like :
QMAKE_POST_LINK = qmllint $$PWD/QMLFiles/myFile.qml
This runs qmllint on your QML file when you build your project.
After my release build is finished I would like to run a script.
I found this question How to execute shell command after compile finished from .pro in QT? but the answer doesn't work for me. I tried adding various modifications of this to my .pro file:
CONFIG(release, debug|release) {
mytarget.target = ./MyScript.sh
mytarget.commands = touch $$mytarget.target
QMAKE_EXTRA_TARGETS +=mytarget
QMAKE_POST_LINK += mytarget
}
But this always results with ":-1: error: mytarget: No such file or directory". Path is correct and 'MyScript.sh' works fine from command line.
Since this works for other people I guess I’m doing something wrong. I use Qt 4.7.2 on Mac.
Path is relative to build directory. If your script is not in your build directory,you have to change path.
Try using ../MyScript.sh
Why are you using target? If your only intent is to execute MyScript.sh after the build, you need only
QMAKE_POST_LINK += ./MyScript.sh
I have a building environment where I add some prepending and appending lines to each Makefile generated.
It would be nice if I could put this lines into the qmake generated file via my project file (.pro).
Of cause I can do this via some easy shell scripting but it would be much nicer to do it from inside of the project file. Is there any qmake command to use?
Does anyone have any idea how to do this?
Example:
include $(ROOT)/prepend.mk
$(LIB):$(OBJ)
#echo ...
include $(ROOT)/append.mk
Customizing Makefile Output
.pro file:
QMAKE_EXTRA_TARGETS += extra_target
extra_target.commands = #echo Hello, World
Run qmake.
Run make extra_target:
Hello, World
See the documentation for additional options.
I've a project with following files
TestProject/api/apiheader1.h
TestProject/api/apiheader2.h
TestProject/src/apiimplementaton.cpp
TestProject/inc/apiimplementation.h
TestProject/TestProject.pro
When the project TestProject.pro is built headers apiheader1.h, apiheader2.h needs to be copied to /usr/include/TestLib/. Is it possible to do this by specifying it in project file TestProject.pro.?
Any pointers / links will be helpful.
You can add this to the pro file... in qmake you can add extra targets...The copyheaders will get run once the target is built..
QMAKE_EXTRA_TARGETS += copyheaders
POST_TARGETDEPS += copyheaders
copyheaders.commands += mkdir -p /usr/include/TestlLib
copyheaders.commands += cp -f PATH_TO_HEADERS/apiheader1.h /usr/include/TestLib
copyheaders.commands += cp -f PATH_TO_HEADERS/apiheader2.h /usr/include/TestLib
Are you sure that you want to move the files? Moving source files around feels wrong.
As for doing it using qmake, you can use the system() function to simply cp the files in question. http://pepper.troll.no/s60prereleases/doc/qmake-function-reference.html#system-command