I have the following directory structure:
- project
- test.pro
- test2
- test2.pro
test.pro looks like this:
# ...
SUBDIRS = test2
The problem is that when I run:
qmake test.pro
make
...it only builds test and not test2.
How come test2 isn't getting built as well? What do I have to do to tell one Qt project to build another one first?
Adding to SUBDIRS has no effect for any TEMPLATE other than subdirs, and you cannot have multiple TEMPLATEs in a single .pro file. In other words, you can't have a single .pro file to both build some binaries and invoke some subdirs projects.
You need one top-level .pro file which only contains subdirs. For example, your test.pro could be:
TEMPLATE = subdirs
SUBDIRS = test1 test2
... and you would then have subdirectories for test1 and test2.
If you don't want to reorganize your code into a subdirectory, you can also put the names of .pro files (instead of directory names) into SUBDIRS. For example, your test.pro could be:
TEMPLATE = subdirs
SUBDIRS = test1.pro test2
... where test1.pro may exist in the same directory as test.pro, and have the usual TEMPLATE=app stuff.
Related
I have a TEMPLATE = subdirs project with 6 subprojects which build in specified order.
I would like to copy the output file of project1 (it's target) to some folder.
This folder is passed with LIBS += -L to project2 and project2 may use this file as a static library.
I found some .pro file commands to copy target files wherever but they are performed at deploy step. I need this to be done at build step. Precisely after project1 got built and before project2 build starts. And would be better if that will be some code that could be kept in .pro file.
Create DestDir.pri in folder, where all of your projects located.
Insert next code:
isEmpty(DESTDIR) {
CONFIG(debug, debug|release) {
DESTDIR=$$PWD/Build/Debug
}
CONFIG(release, debug|release) {
DESTDIR=$$PWD/Build/Release
}
}
Include DestDir.pri to each pro file:
include(../DestDir.pri)
You can change DESTDIR variable to your path or set this variable via qmake command line utils - in both cases this code will locate your artefacts to common folder.
I have found one more way to achieve that:
copydata.commands = $(COPY_FILE) $$OUT_PWD/$(TARGET0) ~/my_libs/
first.depends = $(first) copydata
export(first.depends)
export(copydata.commands)
QMAKE_EXTRA_TARGETS += first copydata
It allows to control what library file (.so, .so.1, .so.1.0, .so.1.0.0) is copied and seems to be crossplatform, so I'll left it here too.
But I'll use Milovidov's solution as less complicated in my project.
I've got a top-level .pro file with subdirs template
TEMPLATE = subdirs
SUBDIRS += \
common/tests
common/tests contains .pro file, but qmake couldn't find it:
Could not find .pro file for sub dir "common/tests" in "/home/o.antonyan/Documents/mt3/main/src/common/tests"
But it's there:
ls /home/o.antonyan/Documents/mt3/main/src/common/tests
api interfaces Makefile tests_common.pro.user ui
dataformat.cpp local_enviroment.cpp tests_common.pro types
If I move this pro file to parent directory and modify topp-level qmake SUBDIRS += common then it works. The problem is only when subdirs contain relative path more than 1 level deep.
QMake version 3.0 Using Qt version 5.4.1 on GNU/Linux x86, Qt compiled from sources
From the docs:
It is recommended that the project file in each subdirectory has the same base name as the subdirectory itself, because that makes it possible to omit the file name. For example, if the subdirectory is called myapp, the project file in that directory should be called myapp.pro.
Try renaming tests_common.pro to tests.pro.
I had the same problem and found this solution for the top level .pro file:
TEMPLATE = subdirs
tests_common.file = tests/tests_common.pro
SUBDIRS += tests_common
But now I would prefere the answer of svlasov.
I have the following project structure:
/
general.pro
a/
a.pro
some files
b/
b.pro
some files
c/
Makefile
some files
general.pro is a TEMPLATE=subdirs style qmake-project. The two other project files are normal/common qmake project files (folder a and b). The third folder (folder c) contains a kernel module with the following Makefile: http://pastebin.com/Bv39D6KK
I'm wondering if that Makefile can be translated somehow to a qmake project file.
If not, is there a way to the the general.pro project file that there is a "c" folder containing a Makefile which should be ran too?
Regards
I really doubt, you can include Makefile in a .pro file.
Here is my thoughts about what you can do:
If c is your project, you could simply create one more .pro file for it.
If it is not, and you don't need to edit it, you could build it without including into subdirs (if it's a library, you are using in a or b, you still can build it, and then create a .pri file and add includes and libs etc).
If you need it for a build machine or for deploying, you could use build script.
You could use cmake.
Update:
It turns out, there is a solution.
Though, I could not make it work myself, I hope it helps. What you need is to add following lines to a top-level pro file:
mytarget.commands = make -C c
QMAKE_EXTRA_TARGETS += mytarget
PRE_TARGETDEPS += mytarget
Where c is a name of sub-directory, containing Makefile.
I have a project in Qt Creator which has several shared library projects and the main project which also contains the main function. What I want is to add a new project which shouldn't be a shared library but just a project with some header files where I keep definitions and error codes. What I wish is to be able to add the path of this project to other projects INCLUDEPATH in order to use those files in other projects.
To do so I created an empty project which .pro file looks like this:
HEADERS += \
myHeader.h
but when I build the whole project it complains that it doesn't find the main in this project with only one header.
Is it possible in QtCreator to achieve this?
Create a .pri file which has your INCLUDEPATH, etc; and then refer to it in your other projects' .pro files:
# Common.pri
INCLUDEPATH += ../myPath
INCLUDE += myHeader.h
# OtherProject.pro
!include( ./Common.pri ) {
error( Could not find the Common.pri file. )
}
INCLUDEPATH += ../myOtherPath
Remember to use the += operator in your .pro files otherwise they will overwrite the .pri file variables.
I'm starting to learn Qt. I'm moving from the Visual Studio world and I am looking for a way to organize my project's structure using QMake. I've found the 'subdirs' template but I have quite a hard time understanding it.
My project structure looks like this:
project_dir/
main.cpp
project.pro
logic/
logic.pro
some logic files
gui/
gui.pro
gui files
My project.pro looks like this
TEMPLATE = subdirs
SUBDIRS = logic \
gui
SOURCES += main.cpp
In the .pro files for the subdirectories I have appropriate SOURCES, HEADERS and RESOURCES variables set.
Please tell me what TARGET, TEMPLATE and other necessary values I should set in the .pro files.
Also, is there some good QMake tutorial other than the official one?
In addition to Troubadour's comment, I would note that the SUBDIRS target is only good for specifying subdirectories. Therefore, your extra line of
SOURCES += main.cpp
in your project.pro file is incorrect, and will likely fail to build your main.cpp file, at worst. At best, qmake will refuse to parse the file, since it has conflicting specifications in it.
I've used the SUBDIRS template a few times, and it does well if you can build parts into more-or-less independent libraries, apparently like you have with the logic and the gui separate. Here is one way to do this:
project_dir/
-project.pro
-common.pri
-logic/
----logic.pro
----some logic files
-gui/
----gui.pro
----gui files
-build/
----build.pro
----main.cpp
project.pro:
TEMPLATE = subdirs
SUBDIRS = logic \
gui
# build must be last:
CONFIG += ordered
SUBDIRS += build
common.pri:
#Includes common configuration for all subdirectory .pro files.
INCLUDEPATH += . ..
WARNINGS += -Wall
TEMPLATE = lib
# The following keeps the generated files at least somewhat separate
# from the source files.
UI_DIR = uics
MOC_DIR = mocs
OBJECTS_DIR = objs
logic/logic.pro:
# Check if the config file exists
! include( ../common.pri ) {
error( "Couldn't find the common.pri file!" )
}
HEADERS += logic.h
SOURCES += logic.cpp
# By default, TARGET is the same as the directory, so it will make
# liblogic.a (in linux). Uncomment to override.
# TARGET = target
gui/gui.pro:
! include( ../common.pri ) {
error( "Couldn't find the common.pri file!" )
}
FORMS += gui.ui
HEADERS += gui.h
SOURCES += gui.cpp
# By default, TARGET is the same as the directory, so it will make
# libgui.a (in linux). Uncomment to override.
# TARGET = target
build/build.pro:
TEMPLATE = app
SOURCES += main.cpp
LIBS += -L../logic -L../gui -llogic -lgui
# Will build the final executable in the main project directory.
TARGET = ../project
You use subdirs if the logic and gui folders actually repesent some sort of target, eg. a library, that can be built independently of anything else. If that's the case then just use
TEMPLATE = lib
TARGET = logic
CONFIG += dll
in logic.pro.
If they are not independent targets but are just folders that exist to organise the sources files then you can just use a .pri file in each instead and include them within the .pro using
include(logic/logic.pri)
include(gui/gui.pri)
Just remember that the file paths in the .pri files are relative to the .pro file and not the .pri. BTW, the use of a .pri file is optional as you can still list the files in those folders directly in the .pro file. The .pri file just makes it that bit neater and helps keep the .pro file shorter.