How to install first project after build in qmake subfolder template? - qt

I have a qtcreator project with subfolder template. The folders looks like this:
mainProject/
mainProject.pro
staticLib/
(bunch of .cpp and .h files)
staticLib.pro
testApp/
main.cpp
testApp.pro
And the mainProject.pro file:
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = staticLib \
testApp
testApp.depends = staticLib
I would like to install the static library so I added the install option in the staticLib.pro file:
headersDataFiles.path = $$LIBPATH/include
headersDataFiles.files = $$PWD/*.h
INSTALLS += headersDataFiles
libraryFiles.path = $$LIBPATH/lib
Debug:libraryFiles.files = $$OUT_PWD/debug/*.a
Release:libraryFiles.files = $$OUT_PWD/release/*.a
INSTALLS += libraryFiles
The problem is when I build the project in Qtcreator, it builds the static lib and then the application without running make install first, so the build for the app fails. And Qtcreator only lets me add build steps after qmake_all (which build both projects without installing the lib first).
So the question is, is there any way I could build staticLib project, install it and then build testApp?
EDIT: The testApp project can always be linked to the library from the output directory of the first project. But I would like to move the .a and headers files to other folder to keep the project organized. The testApp building failure it's not the problem. Sorry for the misunderstood.

I don't like the idea of adding steps in Qt creator (if it's no the only way, of course) as they are not persistent over different dev environments AFAIK. For example, you will need to add this step in Qt Creator each time you download/clone code from repository on another machine.
The way we've done it on Windows (however, it should work for other platforms also) is via the QMAKE_POST_LINK and $$QMAKE_COPY (pre-define qmake cross-platform copy command):
FILES_TO_COPY = $$DESTDIR/staticLib.a <path to your header1> <path to your header2>
or if you prefer:
FILES_TO_COPY = $$DESTDIR/staticLib.a
FILES_TO_COPY += <path to your header1>
FILES_TO_COPY += <path to your header2>
You can use vars like $$PWD, to not hardcode full path to headers, and then
DESTINATION_DIR = $$shell_quote($$shell_path("/put/it/here/"))
for (FILE, FILES_TO_COPY)
{
FILE_PATH = $$shell_quote($$shell_path($$FILE))
QMAKE_POST_LINK += $$QMAKE_COPY $$FILE_PATH $$DESTINATION_DIR $$escape_expand(\\n)
}
UPD: If you have all needed headers in one directory, you can use QMAKE_COPY_DIR instead of QMAKE_COPY.
Also, if you plan to build it on one specific platform, you could omit the $$shel_quote/$$shell_path and just write the correct paths.

Or if install is what you want, you can just add
QMAKE_POST_LINK=$(MAKE) install
to your .pro file

Related

Qt is there something better then QMAKE_POST_LINK for post build actions?

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:

Configuring Qt builds with Jenkins

I have several Qt projects that are dependent upon a Qt library that I've developed.
The project files (.pro) for projects which use the library define the LIBS and PRE_TARGETDEPS paths. For example: -
PRE_TARGETDEPS += ../ProjectLibrary_Qt_5_2_1_clang_64bit-Debug/projectlibrary.dylib
LIBS += -L../ProjectLibrary_Qt_5_2_1_clang_64bit-Debug -lProjectLibrary
As you can see, there is a defined path to the linked library and they have been building with Shadow Builds, via Qt Creator. The file hierarchy is like this: -
Projects
ProjectLibrary_Qt_5_2_1_clang_64bit-Debug
ProjectLib.dylib (the built library)
DependentProject
DependentProject.pro
(dylib is an OSX extension, but it could equally be .lib for Windows, or .so for linux)
However, Jenkins creates a different folder structure:-
jobs
ProjectLib
workspace
Project.dylib
DependentProject
workspace
DependentProject.pro
Now there is an extra directory (workspace), which would need this reflected in the .pro file and the names of the folders are different.
Obviously, If I just call qmake on the .pro with a Jenkins build, the path to the library is going to be wrong.
So, do I need to create a separate .pro just to be able to reflect the paths when building with Jenkins, or is there another way to handle specifying the location of libraries in the project file, for Jenkins, without having to change the directory structures?
Solution 1) Based on your current build configration
Modify your .pro file like this :
isEmpty(PROJECT_PATH) {
PROJECT_PATH=../ProjectLibrary_Qt_5_2_1_clang_64bit-Debug
}
LIBS += -L$${PROJECT_PATH} -lProjectLibrary
Then in Jenkins , you should pass PROJECT_PATH={path to your project} to qmake
Solution 2)
Using git submodule to fetch ProjectLibrary as a part of your building project. Then you don't need to build the ProjectLibrary by Qt Creator manually.

Custom deploy in QTCreator

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

Using Qt Creator to develop an Apache2 module

I'm developing an Apache2 module as a subproject of a larger project. The source file is (for example) module_example.c. Apache2 modules are compiled with apxs2, thus:
% apxs2 -c module_example.c
I've successfully added rules (patterned on how ODB works) to my Qt Creator .pro file to find and use apxs2, like this:
APXS_FLAGS =
APXS_FILES += module_example.c
for(dir, APXS_FILES) {
APXS_PWD_FILES += $$PWD/$${dir}
}
apxs.name = apxs2 -c ${QMAKE_FILE_IN}
apxs.input = APXS_PWD_FILES
apxs.output = ${QMAKE_FILE_BASE}.so
apxs.commands = apxs2 $$APXS_FLAGS -c ${QMAKE_FILE_IN}
apxs.depends = $$APXS_PWD_FILES
apxs.clean = module_${QMAKE_FILE_BASE}.so
QMAKE_EXTRA_COMPILERS += apxs
QtCreator correctly compiles the module using apxs2 (although it leaves the binaries in the source directory instead of the build directory, which isn't ideal), but then also tries to compile it with GCC (which fails). How do I tell Qt Creator to use my "extra compiler" instead of the normal one? Changing the extension to something else (module_example.apxs, for example) doesn't appear to be an option, because apxs2 has no option to specify the extension of C source files. Any ideas?
It's not Qt Creator that does it, but qmake. You need to remove module_example.c from SOURCES. The problem is in the part of the .pro file you're not showing.
If you wish to easily access the file from Qt Creator, add it to OTHER_FILES. It will be shown in the project structure in the IDE, but won't be compiled by default.
Also, it's up to you to tell apxs to output to the build path. You need ${OUT_PWD}.

QTCreator copy files to output directory with INSTALLS

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.

Resources