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
Related
I am struggling to change the build path on Qt creator 4.0.
I've tried everything, but it keeps compiling in a folder in my documents, when my project is actually on my desktop.
Does anyone have a fix ? Thanks
You can either add somthing like this into your .pro file;
DESTDIR = %{sourceDir}/outDir
OBJECTS_DIR = %{sourceDir}/outDir/obj
MOC_DIR = %{sourceDir}/outDir/moc
RCC_DIR = %{sourceDir}/outDir/rcc
UI_DIR = %{sourceDir}/outDir/ui
This should re-direct all the build files into a folder called "outDir" within your source folder (i.e. where your .pro file lives). Note you can use "../" or any absolute path if you really want.
Alternatively you can change the settings in your .pro.user file (which are not part of the config controlled files). To do this you need to edit the build settings in qt creator. You will find an output path that you can change in there. Note you will need to change the path for release and debug builds and also do this for every different build config (e.g. arm-gcc, mingw-gcc, etc...).
In my pro file I do somthing like:
QMAKE_POST_LINK += $$QMAKE_COPY $$quote($$PWD/*.xml) $$quote($$OUT_PWD) $$escape_expand(\\n\\t)
To copy files into the target area ready for deployment. This could be a default config file or some other resource.
When I build the code this works fine, the file is copied. However if I then modify the the config file (lets just call is config.xml) and re-build then since no source files are changed, the build returns "nothing to do ..." and therefore there is no post-linker stage and my updated config.xml file is not copied to the target area.
So to test my changes I have to modify a source file and then re-build... its a bit annoying and when I forget it often causes a few minutes of wasted time...
I'm not sure if I understood well what you want to achieve, but is it something like this (from my personal project)?
unix:!macx {
LIBS += -ltag -L$$OUT_PWD/../Core/ -lmiam-core
target.path = /usr/bin
desktop.path = /usr/share/applications
desktop.files = $$PWD/../../debian/usr/share/applications/miam-player.desktop
icon64.path = /usr/share/icons/hicolor/64x64/apps
icon64.files = $$PWD/../../debian/usr/share/icons/hicolor/64x64 /apps/application-x-miamplayer.png
appdata.path = /usr/share/appdata
appdata.files = $$PWD/../../fedora/miam-player.appdata.xml
INSTALLS += desktop \
target \
icon64 \
appdata
}
So when you do:
qmake
make
make install
The install target will execute the 4 parts in INSTALL.
Edit: you can also add extra build steps in QtCreator:
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 am working on QTCreator (3.0.x) targeting an embedded linux device. Everything is fine except the fact that I am not able to add some custom file to deploy step...
In .pro file I set:
target.path = /home/root
INSTALLS += target
and I am able to deploy my executable to the remote device...
Now what if I would like to add some custom files to the deployment process?
I'd tried to add the following lines to my .pro file:
mypackage.files = /path/to/my/files/on/my/pc/*
mypackage.path = /home/root
INSTALLS += mypackage
but it doesn't work...
How can I do that?
I would try to use wildcard/glob in the following way:
$$files(glob) — Returns a list of files which match the specified glob pattern
mypackage.files = $$files(/path/to/my/files/on/my/pc/*)
But in this special case, it would be much easier to just specify the directory since you seem to be grabbing all the files anyhow, so this is what I would write personally:
mypackage.files = /path/to/my/files/on/my/pc
I have two sub directories docroot and config in my Qt project. Files in these directories shall be copied to the build directory whenever I build / debug the project.
As of https://stackoverflow.com/a/3991210/356726 this is possible by using INSTALLS (QtDoc), which seems to be much easier than running copy command (e.g here). A similar approach is described here.
config.path = $${DESTDIR}/config
config.files = config/*
docroot.path = $${DESTDIR}/docroot
docroot.files = docroot/*
INSTALLS += config docroot
However, when I run a build in Qt Creator nothing happens. This here says I need to run make install . Can I somehow trigger / do this from within Qt Creator automatically whenever I build. I would need always the latest version of the files.
EDIT: Eventually I have used $$OUT_PWD instead of $$DESTDIR
Original comment from Logan here:
"Just a note: I used $$OUT_PWD instead of $$DESTDIR to make it work. For reference $$OUT_PWD is the folder that the program is built to, and $$PWD is the folder that the program is Being built from -in other words it's where the .pro file is."
What you need is a custom build step.
Switch to Projects Mode: press Ctrl+5.
On Build Settings tab under Build Steps click on Add Build Step.
Choose Make from the menu.
Write install into Make arguments: text input box.
(The version where I checked these is Qt Creator 2.4.1.)
I was using Shadow Build on Window 7 and I ran into the same problem than you.
Moreover, after setting my INSTALLS and running make install I was having the following message :
Nothing to be done for `install'.
The reason is that you have to set $$DESTDIR yourself.
In my case I wanted to copy *.qml files, that's how I achieved it:
# if you are using Shadow build, you need to get the output folder
CONFIG(release, debug|release): DESTDIR = $$OUT_PWD/release
CONFIG(debug, debug|release): DESTDIR = $$OUT_PWD/debug
# if you are using normal build (non-shadow) that would have worked as well.
CONFIG(release, debug|release): DESTDIR = release
CONFIG(debug, debug|release): DESTDIR = debug
QmlFiles.path = $$DESTDIR/Qml
QmlFiles.files += $$files(Qml/*.qml)
INSTALLS += QmlFiles
EDIT :
I figure out that $$OUT_PWD can be use to find the Shadow Build Output path. So, I fixed the code which finally come close to what you were using.