Need help with .pro file, copy files at build
-
Hi,
Noob with build stuff, even though developed with Qt for long.
I implemented a Node.js integration via QProcess, and I would like to copy the .js files from the project folder to the build folder.
Any way to implement this in the .pro syntax?
It's Windows for now. I can't seem to be able to run a batch file.
A)
I tried:
.qrc
OTHER_FILES += $$PWD/src/qml/A8QuickDev_2_0/build_extras.bat CONFIG(build_copy) { DEFINES += BUILD_DIR=\\\"$$OUT_PWD\\\" QMAKE_POST_LINK += $$PWD/src/qml/A8QuickDev_2_0/build_extras.bat $$OUT_PWD }
build_extras.bat:
@echo off setlocal set BUILD_DIR=%1 set SOURCE_DIR=%~dp0A8NodeAssistant echo Copying A8NodeAssistant folder from %SOURCE_DIR% to %BUILD_DIR%... xcopy /s /e /y %SOURCE_DIR% %BUILD_DIR%\ pause
I swear the .bat is in the folder as described above.
It just says nothing, does nothing, when I hit build. The cmd window is not opened.I am building the debug build.
B)
Also I tried for test just to be able to run a .bat:
.qrc:
OTHER_FILES += my_batch_file.bat QMAKE_POST_LINK = my_batch_file.bat
my_batch_file.bat:
@echo off echo Hello world! pause
^^It should simply open a cmd window with the Hello World text.
It gave me some error:
:-1: error: [Makefile.Debug:88: debug/A8Elements.exe] Error 2
Any help appreciated.
-
Hi @Archie888,
While I'm not sure exactly what the issue is, I think you can make it a but simpler by using the
QMAKE_SUBSTITUTES
feature.Basically, you would rename your
build_extras.bat
file tobuild_extras.bat.in
in your source. Then in a QMake*.pro
file, add something like:QMAKE_SUBSTITUTES += build_extras.bat.in QMAKE_POST_LINK += build_extras.bat
This will cause qmake to copy
build_extras.bat.in
from your source dir to the build dir, renaming it tobuild_extras.bat
in the process, but also, very helpfully replacing tokens as well. So, for example, yourbuild_extras.bat.in
file can reference things like$$PWD
(source dir) and$$DESTDIR
directly, and qmake will replace it when copying.I don't think that will solve the issue, but should get you closer to a working solution.
QMAKE_SUBSTITUTES
doesn't appear to be well documented, but have a look here for some more info. Also, see this page for a list of variables you can substitute this way.PS Your post sort of suggests you are using a
.qrc
extension for qmake files... you can, but shouldn't. Typically qmake files would be.pro
for project files, and.pri
for "include" files. But.qrc
is meant to be a Qt Resource Collection, which looks more like this:<RCC> <qresource prefix="/"> <file>images/copy.png</file> <file>images/cut.png</file> <file>images/new.png</file> <file>images/open.png</file> <file>images/paste.png</file> <file>images/save.png</file> </qresource> </RCC>
Cheers.
-
Hi @Archie888,
While I'm not sure exactly what the issue is, I think you can make it a but simpler by using the
QMAKE_SUBSTITUTES
feature.Basically, you would rename your
build_extras.bat
file tobuild_extras.bat.in
in your source. Then in a QMake*.pro
file, add something like:QMAKE_SUBSTITUTES += build_extras.bat.in QMAKE_POST_LINK += build_extras.bat
This will cause qmake to copy
build_extras.bat.in
from your source dir to the build dir, renaming it tobuild_extras.bat
in the process, but also, very helpfully replacing tokens as well. So, for example, yourbuild_extras.bat.in
file can reference things like$$PWD
(source dir) and$$DESTDIR
directly, and qmake will replace it when copying.I don't think that will solve the issue, but should get you closer to a working solution.
QMAKE_SUBSTITUTES
doesn't appear to be well documented, but have a look here for some more info. Also, see this page for a list of variables you can substitute this way.PS Your post sort of suggests you are using a
.qrc
extension for qmake files... you can, but shouldn't. Typically qmake files would be.pro
for project files, and.pri
for "include" files. But.qrc
is meant to be a Qt Resource Collection, which looks more like this:<RCC> <qresource prefix="/"> <file>images/copy.png</file> <file>images/cut.png</file> <file>images/new.png</file> <file>images/open.png</file> <file>images/paste.png</file> <file>images/save.png</file> </qresource> </RCC>
Cheers.
Thanks for the tip to the right direction, very helpful!!
The .qrc was a mistake, meant .pro, sorry.
QMAKE_SUBSTITUTES seems like an interesting cross-platform way to copy files to the build destination from project, and it worked, thanks. However, having to have the .in extension creates issues, having to create a copy automatically with .in and so on, which I can do, but it's not very elegant. But I will definitely keep that in mind.
As I checked into the issue again, I now finally got QMAKE_SUBSTITUTES working to run the .bat file, but it needs to be like this:
QMAKE_POST_LINK += $$PWD/my_batch_file.bat
Unlike with OTHER_FILES, it needs the $$PWD/ as the starting point.
Also, no cmd window is opened unlike I was expecting. The execution will be part of the Qt build process, and any echo ouput in your .bat file is shown in the Compile Output tab.
However, now I am running into problems with getting access denied with copying with the .bat, so I will have to look into this issue later.
Here is the .bat again, which is giving the :
@echo off setlocal set BUILD_DIR=%1 set SOURCE_DIR=%~dp0A8NodeAssistant echo Copying A8NodeAssistant folder from %SOURCE_DIR% to %BUILD_DIR%... xcopy /s /e /y %SOURCE_DIR% %BUILD_DIR%\ pause
Any help appreciated of course what the mystery could be, if someone has info at the tip of the fingers, but I'll get into this later again myself.
Cheers!
(I might have to implement the nasty .in file generator in the end, LOL!)
-
Ok, was too intrigued by the mystery, and still had a little time to solve the issue, and solved it finally... (With a bit of help by ChatGPT)
In .pro:
QMAKE_POST_LINK += $$PWD/path_to_bat_relative_to_project/build_extras.bat $$OUT_PWD
We give the $$OUT_PWD as a parameter for the .bat, which will yield the build path.
In .bat:
@echo off setlocal set "source=%~dp0A8NodeAssistant" set "dest=%~1\A8NodeAssistant" echo Copying files from %source% to %dest% ... xcopy /E /I /Y "%source%" "%dest%" echo Copy completed. endlocal
This finally worked, but as you can see, it is not cross-platform, just for Windows.
-
Thanks for the tip to the right direction, very helpful!!
The .qrc was a mistake, meant .pro, sorry.
QMAKE_SUBSTITUTES seems like an interesting cross-platform way to copy files to the build destination from project, and it worked, thanks. However, having to have the .in extension creates issues, having to create a copy automatically with .in and so on, which I can do, but it's not very elegant. But I will definitely keep that in mind.
As I checked into the issue again, I now finally got QMAKE_SUBSTITUTES working to run the .bat file, but it needs to be like this:
QMAKE_POST_LINK += $$PWD/my_batch_file.bat
Unlike with OTHER_FILES, it needs the $$PWD/ as the starting point.
Also, no cmd window is opened unlike I was expecting. The execution will be part of the Qt build process, and any echo ouput in your .bat file is shown in the Compile Output tab.
However, now I am running into problems with getting access denied with copying with the .bat, so I will have to look into this issue later.
Here is the .bat again, which is giving the :
@echo off setlocal set BUILD_DIR=%1 set SOURCE_DIR=%~dp0A8NodeAssistant echo Copying A8NodeAssistant folder from %SOURCE_DIR% to %BUILD_DIR%... xcopy /s /e /y %SOURCE_DIR% %BUILD_DIR%\ pause
Any help appreciated of course what the mystery could be, if someone has info at the tip of the fingers, but I'll get into this later again myself.
Cheers!
(I might have to implement the nasty .in file generator in the end, LOL!)
@Archie888 said in Need help with .pro file, copy files at build:
Thanks for the tip to the right direction, very helpful!!
The .qrc was a mistake, meant .pro, sorry.
QMAKE_SUBSTITUTES seems like an interesting cross-platform way to copy files to the build destination from project, and it worked, thanks. However, having to have the .in extension creates issues, having to create a copy automatically with .in and so on, which I can do, but it's not very elegant. But I will definitely keep that in mind.
As I checked into the issue again, I now finally got QMAKE_SUBSTITUTES working to run the .bat file, but it needs to be like this:
QMAKE_POST_LINK += $$PWD/my_batch_file.bat
Unlike with OTHER_FILES, it needs the $$PWD/ as the starting point.
Also, no cmd window is opened unlike I was expecting. The execution will be part of the Qt build process, and any echo ouput in your .bat file is shown in the Compile Output tab.
However, now I am running into problems with getting access denied with copying with the .bat, so I will have to look into this issue later.
Here is the .bat again, which is giving the :
@echo off setlocal set BUILD_DIR=%1 set SOURCE_DIR=%~dp0A8NodeAssistant echo Copying A8NodeAssistant folder from %SOURCE_DIR% to %BUILD_DIR%... xcopy /s /e /y %SOURCE_DIR% %BUILD_DIR%\ pause
Any help appreciated of course what the mystery could be, if someone has info at the tip of the fingers, but I'll get into this later again myself.
Cheers!
(I might have to implement the nasty .in file generator in the end, LOL!)
Typo on the line:
"As I checked into the issue again, I now finally got QMAKE_SUBSTITUTES working to run the .bat file, but it needs to be like this:"
Meant:
"As I checked into the issue again, I now finally got QMAKE_POST_LINK working to run the .bat file, but it needs to be like this:"
It seems that the time period to edit comments here has been decreased.