Can I define a project directory? - directory

When I run Cmake I transmit a directory with a CMakeLists.txt, but project build in working directory.
Can I transmit a destination directory?
P.S I can't to wrtite
cd .\build
cmake ..

Related

Qt6 qt_generate_deploy_app_script plugin DLL copying

Currently I have to manually copy the platforms and imageformats plugin folders to the directory containing the .exe that MSVC compiled. This is very tedious as the output folders often get deleted if you're working on your CMakeLists.txt or changing compilation target.
Now qt_generate_deploy_app_script seems like an official Qt solution to solve this problem, but it does not work.
I have added the CMake bits to my CMakeLists.txt as stated
qt_generate_deploy_app_script(
TARGET HiveWE
FILENAME_VARIABLE deploy_script
NO_UNSUPPORTED_PLATFORM_ERROR
)
install(SCRIPT ${deploy_script})
I can see some generated deploy scripts appear under build\x64-RelWithDebInfo\.qt, but they do not seem to be run as no DLL folders get copied to where my .exe is.
Am I misinterpreting what qt_generate_deploy_app_script should do or is it simply broken?
If you want to Creat exe in windows From Qt project you should use windeployqt
To Deploy and create Exe output with QT in windows you should follow this way:
put your compiler path in your system path. for example, if you use mingw81_64, you should set it. something like Qt/tools/mingw81_64/bin
copy exe file that provides after building in release mode in one
folder and run mingw81_64 cmd (it has separate cmd) and cd to that
folder path
windeployqt app.exe
you are using Cmake So first create one release output and then use step 3.
This command will get all dll needs for your app and your exe will work .
if you use qml
windeployqt --qmldir (the path of its directory ) app.exe
and also see these youtube videos for more info:
https://www.youtube.com/watch?v=LdSTgR0xJco
https://www.youtube.com/watch?v=hCXAgB6y8eA

How to get .pro file from the set of qt files

I was trying to modify the source code of this open source project https://github.com/haiwen/seafile-client
As I can see it contains .ui, .qrc etc files which is used in Qt, but there is no .pro files present in his repository. So how to get the .pro file for this repository code. Any idea?
That was the Cmake project , you should install CMake in your system and build it like this :
cmake .
make
make install
OR use CMakeLists.txt instead of .pro .
You can use qmake to generate the .pro file for this repository.
Just do the following steps:
Clone the repo.
cd into the repo
Run the following command
qmake -project -r *
It will repeatedly look into the directory and it's sub-directory files and will generate required .pro file for you.
You can learn more about this at below given link:
https://doc.qt.io/qt-5/qmake-running.html#project-mode-options

QMAKE_QMAKE with symbolic link to qmake

I need to get path of folder with my qt in pro file.
I used QMAKE_QMAKE and everything worked.
But now I created a symbolic link to qmake in ~/.local/bin to make it easier to call qmake.
qmake-linux -> /home/andrei/Qt/Qt-v5.13.0/Linux/bin/qmake*
And now I ran into the problem that qmake, launched by a symbolic link, contains in the variable QMAKE_QMAKE not the path to the executable file, but the path to the symbolic link.
Info: creating stash file /home/andrei/worker/githubworker/github-worker/build/.qmake.stash
Project MESSAGE: QT_DIR = /home/andrei/.local/bin
Maybe it is important: I build qt from sources.
Maybe there are ways to get qmake paths or folders with qt?
The directory where the qmake executable is located can be retrieved with $$[QT_HOST_BINS]. This is a qmake property.
Call qmake -query to see a list of available properties.

How to link properly shared linux libraries in qt?

I'd like to run my program on different computer which doesn't have any installed libs. I build my program in QT with openCV and copied all needed .so libs to folder with all my files. Next I changed paths in QT .pro to
INCLUDEPATH += ../
LIBS += -L../ -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_core.
I compiled that on my computer (linux) and it worked but I want it to work on another computer without compilation. On my friend's computer, binary doesnt work. I get error:
./displayImage: error while loading shared libraries: libopencv_highgui.so.3.1: cannot open shared object file: No such file or directory
Set the LD_LIBRARY_PATH environment variable to the directory that you're running it from.
If your files are located in /home/abc/cool/program/displayImage (and that folder contains all the .so files that your program needs to run)
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/abc/cool/program/
$ ./displayImage
You can also add a file <whatever>.conf in /etc/ld.so.conf.d and put one or more rows with the pathnames of your libraries.
Then run ldconfig. This is needed only once.

CMake + Qt : define the moc/ui output directory

I'm currently transferring a project built with qmake to CMake.
In the version with qmake, in the .pri file, there was
MOC_DIR = .moc/$${PLATFORM_NAME}
that permitted to produce the MOC temporary files in a given directory, keeping the sources clean. How to do the same thing with CMake?
Note: with CMake, I use the FindQt4.cmake package and the command QT4_WRAP_CPP().
As baysmith says, if your goal is to keep your source directory clean, the real solution is to use CMake's "out-of-source" builds feature. If you're on Windows, set "Where to build the binaries" to a new directory, different from the "Where is the source code" directory. If you're on Unix, it goes something like this:
cd <source directory>
mkdir build
cd build
cmake ..
make
By running CMake on a different directory, all of the build files will go into that directory, and your sources will stay clean. (Note: the build directory doesn't have to be inside the source directory. See the CMake wiki for more details.)
If "out-of-source" doesn't work for you, I was able to find one other option. Based on what I can tell from the Qt4Macros.cmake file installed with my CMake 2.8, it isn't accessible as a config parameter. Here's the relevant line:
SET(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC})
The workaround is to change all of your MOC include directives to specify the subfolder you'd like to build to.
#include "moc/mainwindow.moc"
After creating the moc directory inside my build directory, there were no problems building, and my MOC file was in the new directory.

Resources