Can qmake handle dependencies of generated source files?
We have a prf file like this:
idl_h.name = Generate .H file for ${QMAKE_FILE_BASE}.idl
idl_h.input = IDLS # variable containing our input files
idl_h.variable_out = HEADERS
idl_h.commands = <command that takes .idl and genrates .h>
idl_h.output = $$IDL_GEN_DIR/${QMAKE_FILE_BASE}.h
QMAKE_EXTRA_COMPILERS += idl_h
This generation works fine and creates .h files at make time. The problem is that the input files ($$IDLS) depend on each other, and are not always built in the correct order. We have something like app.idl, containing:
#include "common.idl"
It seems the following should work
idl_h.depend_command = g++ -EE ... $$IDL_GEN_DIR/${QMAKE_FILE_BASE}.h
but apparently the depend_command is not actually executed.
Another idea would be to parse the dependencies out of the original idl:
idl_h.depends = $$system(cat ${QMAKE_FILE_IN} | grep "^#include" | sed -re 's/#include\s+["<]([^.]+)\.idl[">]/\1.h/')
but it seems my qmake syntax is failing me.
Try adding
idl_h.dependency_type = TYPE_C
to your prf, and drop the .depend_command and .depends
Related
I want to add a path to my translations folder in the .pro file, which can be accessed from C++ / QML parts as well as used inside the .pro file.
I came across the DEFINES+= function and made it work with an example for the number PI. This define can be called from C++ using qDebug()<
Now i have a translations folder two directorys above the .pro file which is called translations. Therefor i tried to use something like this:
DEFINES += "TRANSPATH=\"../../translations\""
But when I try to access it via qDebug i get the errors
- expected primary expression
and
- expected unqualified id before "." token
In my .pro file I want to access the TRANSPATH as well, but using it like
TRANSLATIONS += \
$$(TRANSPATH)/test_TEST.ts \
../../translations/de_DE.ts \
../../translations/zh_CN.ts
}
only leads to this error:
Updating '../../../../../../../test_TEST.ts'...
Found 63 source text(s) (63 new and 0 already existing)
Cannot create /test_TEST.ts: Zugriff verweigert
Updating '../../translations/de_DE.ts'...
Found 63 source text(s) (0 new and 63 already existing)
I tried to find other examples online but haven´t found anything helpfull.
In the TRANSLATIONS += part i had changed the wording to:
TRANSPATH/test_TEST.ts
{TRANSPATH}/test_TEST.ts
$$TRANSPATH/test_TEST.ts
$${TRANSPATH}/test_TEST.ts
but nothing worked. This is the first time I´m trying to DEFINE something, maybe I´m doing it wrong? Please help
Example code / .pro file:
# this file will be loaded from the main import path
MAIN_QML_FILE = main.qml
INCLUDEPATH += ./Plugins
INCLUDEPATH += ./qml
DEFINES += "PI=\"3.1415926\""
DEFINES += "TRANSPATH=\"../../translations\""
QT += core
# this is only seen by the linguist tools (lupdate)
lupdate_only{
SOURCES = \
../../qml/Widgets/SomeFiles/*.qml
TRANSLATIONS += \
$$(TRANSPATH)/test_TEST.ts \
../../translations/de_DE.ts \
../../translations/zh_CN.ts
}
TRANSPATH should lead to the same folder as the ../../translations/de_DE.ts
path does. The path would be reused from C++ for a custom QTranslator object.
First, this error from qmake:
Cannot create /test_TEST.ts: Zugriff verweigert
comes from here:
$$(TRANSPATH)/test_TEST.ts
You're referencing an undefined variable, i.e. TRANSPATH. When you do this:
DEFINES += "TRANSPATH=\"../../translations\""
you're not defining a variable: you're appending a define to the compiler command line, using -D flag (you can check this in the compilation output pane, in creator).
So, just have a qmake variable:
TRANSPATH = ../../translations
Now you can use it elsewhere in your pro file, e.g.
TRANSLATIONS += \
$$(TRANSPATH)/test_TEST.ts \
../../translations/de_DE.ts \
../../translations/zh_CN.ts
}
You can use it in DEFINES, too, but take care of escaping:
DEFINES += "TRANSPATH=\\\"$$TRANSPATH\\\""
In your compiler out you will find
-DTRANSPATH=\"..\..\translations\"
along with the other flags.
Now you can safely do
qDebug() << TRANSPATH;
in your source code.
Is there a way to tell qmake to add to Makefile an include directive to include other Makefile.
I need at the beginning of generated Makefile added one line:
include custom.inc
Maybe there is just a way to output text to Makfiles from qmake but I could not find.
You can use the undocumented QMAKE_EXTRA_INCLUDES variable, like
QMAKE_EXTRA_INCLUDES += /path/to/your/file.mk
you can define a new target into make file and then tell what that target does:
mytarget.target = .buildfile
mytarget.commands = make -f AnotherMakeFile
QMAKE_EXTRA_TARGETS += mytarget
PRE_TARGETDEPS += .buildfile
last 2 statements add your target .buildfile to Makefile and mytarget to Qt compiling process
here you can get further info: http://qt-project.org/doc/qt-4.8/qmake-environment-reference.html
I haven't found a way to include a Makefile, but I have had a similar problem where I wanted one file to contain a common set of build variables. The solution I came up with was to use the QMake command include(filename.pro) (see QMake reference page). This causes QMake to include another project file. In my case, that contained all of the common settings.
I have doubts about my Qt .pro file... I had seen another post about a similar question in this link, but i used the contains() function and didn't work.
In the my case, i have a file called mainconfig.h where i define some project configurations flags, i really create defines there, like: "#define MY_CONFIG_DEFINE". Those flags define what menu options will be shown etc. My problem is: all files are always compiled, even when i don't use its because i defined some flag in "mainconfig.h" file. I would like to avoid compile some files than i will not use, defining some variables in my .pro file and doing conditional commands, including only the files than i want to.
Can someone help me?
I tried this in my .pro file:
# This variable defines the current project ADRIANO_PROJECT = PROJECT_TYPE_1
ADRIANO_PROJECT = PROJECT_TYPE_1
(...)
FORMS += ui/form1.ui \
contains(ADRIANO_PROJECT, PROJECT_TYPE_1) {
ui/myform1.ui \
ui/myform2.ui \
}
ui/form2.ui \
ui/form3.ui
(...)
# This is only a example, ok?
Sorry my english and thanks.
IMHO your syntax is wrong. Try this instead:
ADRIANO_PROJECT = PROJECT_TYPE_1
FORMS += ui/form1.ui \
ui/form2.ui \
ui/form3.ui
contains(ADRIANO_PROJECT, PROJECT_TYPE_1) {
FORMS + = ui/myform1.ui \
ui/myform2.ui
}
Before compile my program ,I need to compile a 3rd party library,but it is not writen in QT ,it has a Makefile to build itself . so if I write a pro file like this:
TEMPLATE = subdirs
SUBDIRS += image myapp
(image directory is the 3rd party library)
then qmake,make
it always report "Cannot find file: image.pro"
if I write a pro file inside image, it will create a Makefile which will overwrite the original Makefile.
any suggestions?
Thanks in advance
You could try several things, depending on what you want:
Use QMAKE_MAKEFILE to rename the qmake-generated makefile so that is won't overwrite the other one.
do some fancy stuff to create something like a QMAKE_PRE_BUILD sort of thing (this variable does not exist in qmake):
makefile.target = Makefile
makefile.depends += prebuild
prebuild.target = prebuild
prebuild.depends = FORCE
prebuild.commands = #echo before build (to replace)
QMAKE_EXTRA_TARGETS += makefile
QMAKE_EXTRA_TARGETS += prebuild
Source: http://forum.qtfr.org/viewtopic.php?id=10686 (read post two and three (google translate) and keep in mind that "défaut" wich means defect gets translated as default :) )
These should be able to solve the problem you're having.
In order to keep my Qt project somewhat organized (using Qt Creator), I've got one .pro file and multiple .pri files. Just recently I added a class to one of my .pri files that has the same filename as a class that already existed in a separate .pri file.
The file structure and makefiles generated by qmake appear to be oblivious to the filename collision that ensues. The generated moc_* files all get thrown into the same subdirectory (either release or debug, depending) and one ends up overwriting the other. When I try to make the project, I get several warnings that look like this:
Makefile.Release:318: warning: overriding commands for target `release/moc_file.cpp`
And the project fails to link.
Here is a simple example of what I'm talking about.
Directory structure:
+ project_dir
| + subdir1
| | - file.h
| | - file.cpp
| + subdir2
| | - file.h
| | - file.cpp
| - main.cpp
| - project.pro
| - subdir1.pri
| - subdir2.pri
Contents of project.pro:
TARGET = project
TEMPLATE = app
include(subdir1.pri)
include(subdir2.pri)
SOURCES += main.cpp
Contents of subdir1.pri:
HEADERS += subdir1/file.h
SOURCES += subdir1/file.cpp
Contents of subdir2.pri:
HEADERS += subdir2/file.h
SOURCES += subdir2/file.cpp
Is there a way to tell qmake to generate a system that puts the moc_* files from separate .pri files into separate subdirectories?
In subdir1.pri try appending
MOC_DIR = "subdir1/MOCFiles"
Also for subdir2.pri give
MOC_DIR = "subdir2/MOCFiles"
It isn't tested. Just check it out. Hope it will work.
Edit 1 : Where MOCFiles is your desired folder for your moc files to get into.
Edit 2 : I just stopped mentioning with the MOC files directory since that has been asked specifically in the question. But additionally you may also have to add the following to each of the pri files. (Make sure that the folders are different for different *.pri files)
RCC_DIR = "subdir1/RCCFiles"
UI_DIR = "subdir1/UICFiles"
OBJECTS_DIR = "subdir1/ObjFiles"
I believe having multiple pri files can work without collisions by having the same file names. Since you have accepted an answer (which states it is not possible), make the above changes and give a try. Do let know if it isn't working.
Best thing to do is to make sure that all files have a unique name. There are other tools besides qmake which will also break when you try to do what you're doing; you also potentially make it confusing for yourself (e.g. understanding what #include "file.h" does is more difficult).
I have tried this before. The short answer is to name them differently somehow. Another answer would be to treat each subdirectory as a separate library, with its own .pro file, and use a subdirs type to compile all the library directories.
If you really want to investigate a full answer, you can specify the tool to be used for moc. In this situation, you might be able to mangle the name so that a slightly different name is used for the two different files. However, you would then also need to make sure each differently-named file is added to the list of files to compile and link, and the originally-named moc file is not (or your build will fail).