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
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...).
I have a project setup with a couple of Apps with a shared library, this is all built nicely using a SUBDIRS project, where the apps depend on the shared library.
TEMPLATE = subdirs
SUBDIRS = app1 app2 sharedLib
app1.depends = sharedLib
app2.depends = sharedLib
Each app also contains a number of tests, with CONFIG += testcase set.
This creates a check target so we can run all unit test from the top level .pro using make check.
The problem is that some of the app tests require the presence of the code within the sharedLib, therefore it needs to be discoverable according to each platforms library lookup rules.
On Windows one option is to have the sharedLib location on the PATH, on linux we can add the sharedLib location to LD_LIBRARY_PATH, on mac DYLD_LIBRARY_PATH.
One solution is to just set the location of the built shared lib before running make check:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:build/sharedDll/
make check
and this works, but it seems a little redundant as it is the build scripts themselves that are building the shared library so they know the path to the sharedLib binary location, which can be referenced from within .pro/pri files at:
$$TOP_BUILDDIR/sharedLib/release
So, is there anyway to set the PATH/LD_LIBRARY_PATH/DYLD_LIBRARY_PATH from within the project files for the purposes of the make check command?
If you are using gcc, you can use rpath parameter of gcc.
-rpath=dir
Add a directory to the runtime library search path. This is used
when linking an ELF executable with shared objects. All -rpath
arguments are concatenated and passed to the runtime linker, which
uses them to locate shared objects at runtime.
QMAKE_CXXFLAGS += -rpath=/the/absolute/path
If you use that technique, it will not be necessary to edit LD_LIBRARY_PATH
In Qt 5.5, the following qmake statement prepends the path $$TOP_BUILDDIR/sharedLib/release to LD_LIBRARY_PATH for the target check:
check.commands = LD_LIBRARY_PATH=$$TOP_BUILDDIR/sharedLib/release:\$$LD_LIBRARY_PATH $$check.commands
I drew inspiration for this solution from the files testcast.prf and qt_functions.prf (especially the functions qtAddTargetEnv() and qtAddToolEnv()), both located in $$[QT_INSTALL_PREFIX]/mkspecs/features.
I learned that qmake has a variable for searching for libs in a custom dir, it's called QMAKE_LIBDIR.
Instead of manually adding a lib path to LD_LIBRARY_PATH, you can set this in your .pro file, and then link the libraries you need with:
QMAKE_LIBDIR = /path_to_your_libs
-L/path_to_your_libs -l<whatever_lib_you_need>
I've got problem trying to specify the build directory (the directory that is to store all the files prior to copying them to the DESTDIR path).
I've got the following values in my .pro file:
DESTDIR = E:/Development/project/build/core/debug
OUT_PWD = E:/Development/project/build/core/debug
OBJECTS_DIR = $$DESTDIR/.obj
MOC_DIR = $$DESTDIR/.moc
RCC_DIR = $$DESTDIR/.qrc
UI_DIR = $$DESTDIR/.ui
Now, all the files eventually end up in that location, however during build, the compiler is always using the "E:/Development/build/MinGW_32bit-Debug/src/core" folder (note the missing project path). This is annoying, because I want to use the /Project/build directory as this location (which is not tracked in my git repo).
Ideally, I'd like this path to be: E:\Development\project\build\src\core\debug.
The reason I want to do this is that the build process has the same location to include the compiled libs from (it's a subdirs project).
I've had a look in the Tools > Options > Build & Run > General settings, and the default build directory is: build/build-%{CurrentProject:Name}-%{CurrentKit:FileSystemName}-%{CurrentBuild:Name}
I've had a look in my project.pro.user file, and found the following line:
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">E:/Development/build/MinGW_32bit-Debug</value>
However I'm unable to change this value. If I edit this line in the file directly, as soon as I open Qt Creator again, the change has reverted back.
Is this a Qt Creator thing, or is it a qmake thing? Would I better off using a different build system such as CMake?
The build directory is "specified" by starting qmake or cmake in the build directory. There's no point to setting it in the .pro file itself.
Qt Creator stores the build directories for a project in the .user file. Any changes made to this file outside of Qt Creator, while the project is open in the Creator, will be lost. Creator loads the file when opening the project, or creates a new one if it doesn't exist.
When the Creator starts the build by invoking qmake or cmake, it starts that process in the build directory. That's also how you should be building the project manually from the command line.
Finally, it makes very little sense to override the destinations of the intermediate build results. They are somewhere within the build directory, and that's all that matters. You're not using these files directly for anything anyway.
The customary way to build a qmake project:
mkdir project-build
cd project-build
qmake ~/project-src
make -j
The build folder should not be within the source tree!
I've recently started keeping them in $TEMP / %TEMP%: manually purging the stale builds of all sort of test projects got old after a while :)
I want to build qt application that will gather all the necessary binaries for standalone execution on install.
I know that can be done in lines of:
QT_DIR=C:/Qt/4.8.4
dlls_to_move.files += $$DIR/bin/QtCore.dll
however that seems clumsy. Is there a way to retrieve Qt binary folder actually used, like project directory that can be retrieved with $$PWD?
From qmake Advanced Usage:
The special $$[...] operator can be used to access various configuration options that were set when Qt was built:
So I think you'd want to do this in your project file:
dlls_to_move.files += $$[QT_INSTALL_BINS]/QtCore.dll
My Qt project have two source files with the same name but in different folder.
The pro file is:
SOURCES = A/Test.cpp
SOURCES += B/Test.cpp
It can generate Visual Studio solution file via Qt Visual Studio addon, but it won't work because the generated object file have the same name: Test.obj.
That will cause LNK2001 unresolved external symbol because one of Test.obj is overwritten.
How to write proper pro file to deal with that?
Before Qt 5
You can try adding that line to your .pro file:
CONFIG += object_with_source
But as the option name implies, the .obj files will not be created in the out-of-source / "shadow build" directory.
Qt 5 and older
That option has been replaced by object_parallel_to_source in Qt 5, which should work with the shadow building.
You should consider splitting your solution in multiple projects, but it depends if each one of those folders could represent a project by its own.
If you choose this solution, you will have to write one .pro file per project. The usual way to go is to write a 'generic' *.pri file which is included from every *.pro file:
folder1.pro
TEMPLATE=lib
TARGET=folder1
include( ../common.pri )
folder2.pro
TEMPLATE=lib
TARGET=folder2
include( ../common.pri )
common.pri (in parent directory)
SOURCES += *.cpp
HEADERS += *.h
# etc.
Obviously the contents of each pro file depends on your solution.
If you don't want to split the source files in multiple projects, the easier solution would be to rename one the conflicting files, I guess.
I recently came across this issue, too. Splitting the project into subprojects made everything much more complicated, and -at least on my first attempt- flat-out didn't work. Then I tried CONFIG += object_with_source and CONFIG += object_parallel_to_source, but both did't seem to work with my Qt version.
So this is how I solved it (for Visual Studio 2010; I don't know if works the same with other versions):
If the project were an ordinary Visual Studio project, not one generated by QMake, you could solve it as described here: Visual Studio 2010 & 2008 can't handle source files with identical names in different folders? (changing the output dir of object files to a relative dir by appending %(RelativeDir) in the project settings "C/C++" > "Output Files" > "Object File Name").
Obviously, you don't want to do this by hand everytime you create a new Visual Studio project with QMake, so why not automatize it? After all Visual Studio project files are but ordinary XML files. Looking at the diff before and after setting the options reveals it's saved in a single unique tag called ObjectFileName.
So I wrote this Python script:
import sys
filename = sys.argv[1]
f = open(filename, "r", -1, "utf-8-sig")
lines = f.readlines()
f.close()
f = open(filename, "w", -1, "utf-8-sig")
for line in lines:
line = line.replace("</ObjectFileName>", "%(RelativeDir)\</ObjectFileName>")
f.write(line)
f.close()
..and use it like this in my bat-file that I always call to create the Visual Studio project:
qmake -tp vc myproject.pro
#cd ../scripts
unflatten_vcproj_obj_output.py "../src/myproject.vcxproj"
#pause
Not a beautiful solution, but it works.
One solution is to rename the files:
A/a_Test.cpp
B/b_Test.cpp
It's a bit ugly, but its simple and the class names can stay the same.