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.
Related
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 am sorry if the question was already asked but after some research I couldn't find an answer. I want to copy the .exe of a project into a folder automatically.
I am using Qt creator 5.0.1 MSCV2010 and it always makes two outputs: release and debug.
For example, I want the /release/project.exe to be in /release/exec/project.exe.
I saw I can copy file like .dll with in a .pro with:
INSTALLS =
But it only work with files which already exist, or the .exe is generated after the compilation. I think I can specify this into:
projects settings->Build compilation->step Make : jom.exe in C:\path\to\project-release
But I don't know what argument is needed,
Regards
On Windows you can use DLLDESTDIR variable which specifies where to copy the target dll or exe. Just add this to your .pro :
CONFIG(release, debug|release): DLLDESTDIR += $$PWD/../exec
On Linux you can use QMAKE_POST_LINK variable which contains the command to execute after linking the TARGET together. So it is like:
CONFIG(release, debug|release): QMAKE_POST_LINK += $$quote(cp project $$PWD/../exec)
Here project is the name of the target file which you provide by TARGET = project
These will copy the executable binary to a directory named exec one level upper than the program working directory. You can have your arbitrary path.
add a custom build step with the command an parameters
for windows (assuming you are doing this for the release build):
xcopy
Release\<target.exe> path\to\destination\file.exe /Y
%{buildDir}
This should work. I couldn't find any variable that points the target_path. So I defined it:
### to copy target file to build folder
CONFIG(debug, debug|release) {
TARGET_PATH = $$OUT_PWD/debug
}
CONFIG(release, debug|release) {
TARGET_PATH = $$OUT_PWD/release
}
win32: QMAKE_POST_LINK += copy /y "$$shell_path($$TARGET_PATH/app_name.exe)" "$$shell_path($$PWD/../build/)"
unix: QMAKE_POST_LINK += cp "$$shell_path($$TARGET_PATH/app_name)" "$$shell_path($$PWD/../build/)"
Here are the lines I added in my .pro to set a custom build dir.
BASEPATH = ../some/path/
CONFIG(debug, debug|release) {
BUILDDIR = $${BASEPATH}/debug
} else {
BUILDDIR = $${BASEPATH}/release
}
OBJECTS_DIR = $${BUILDDIR}/obj
MOC_DIR = $${BUILDDIR}/moc
RCC_DIR = $${BUILDDIR}/rcc
UI_DIR = $${BUILDDIR}/ui
MAKEFILE = $${BUILDDIR}/Makefile
However, it fails with the error :
error : No rule to make target `../project/project.pro', needed by `Makefile'. Stop.
It works well if I remove the MAKEFILE=... line but I don't want the Makefile to be output in the same dir than the source files.
So am I looking for some impossible thing or is MAKEFILE the wrong variable to edit ?
Thanks.
Have you heard of shadow build?
Shadow building means building a project in a separate directory, the
build directory. The build directory is different from the source
directory. One of the benefits of shadow building is that it keeps
your source directory clean, which makes it faster to switch between
build configurations. Therefore, shadow building is the best practice
if you need many build configurations for a single set of source
files.
If you are building your projects with Qt Creator then see its manual: Editing Build Configurations. However if you are building it on the command line then see this question and answer on SO: Manually configuring shadow build in qmake
You can separate them by adding source files to a separate src folder. This Question may help you too:-
How to specify different Debug/Release output directories in QMake .pro file
Works fine for me. That is .pro file:
linux-g++-64: {
BPATH_ = ../BUILD_DIR
OBJECTS_DIR = $${BPATH_}
MOC_DIR = $${BPATH_}
RCC_DIR = $${BPATH_}
UI_DIR = $${BPATH_}
MAKEFILE = $${BPATH_}/Makefile
TARGET = $${BPATH_}/$${TARGET}
message(Code only for Linux! TARGET = $${TARGET})
}
Run the following command from the source folder:
make -f ../BUILD_DIR/Makefile
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'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.