Copy dir for build dir
-
I am needing to copy a directory to the build directory, I found a solution but it is not meeting my need:
"Solution":http://dragly.org/2013/11/05/copying-data-files-to-the-build-directory-when-working-with-qmake/First I do not understand why so many lines of code just to copy a file to the build-dir.
According to my need is copy a folder and all its contents to the build-dir and not just a loose file as shown in the solution.Here is the picture of how this divided my project:
!http://i60.tinypic.com/103u0rc.png(MyPro)!
need to copy the uitest folder and all its contents to the same directory where the executable is created test.
-
Hi,
Do you really need these files there or is it just to make it easier for your tests to access them ?
-
if you want to copy the folder and its contents need to copy file to file.
You must first create the parent folder ( uitest ) .
Then the sons of uitest scrolling you have to create the folder by folder and copy the files in order .
Is that clear? -
SGaist,
Need for both reasons, yes, is for easier access, but also need to copy another folder where are the ui files for final use.Salvatello,
I found some information on how to copy files but not how to create dirs, you could set an example? -
If you generated the test with Qt Creator you should have a line like
@DEFINES += SRCDIR=\\"$$PWD/\\"@So you can use SRCDIR to access the files in your sources from your test
-
@void Main::copyPath(QString src, QString dst)
{
QDir dir(src);
if (! dir.exists())
return;
foreach (QString d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
QString dst_path = dst + QDir::separator() + d;
dir.mkpath(dst_path);
copyPath(src+ QDir::separator() + d, dst_path);
}foreach (QString f, dir.entryList(QDir::Files)) { QFile::copy(src + QDir::separator() + f, dst + QDir::separator() + f); }
}@
src is directory starting
dst is directory arrival -
@ Salvatello the question is not about doing it from an application, it's about doing in from a post-build step
-
No it does not. And I did not create the tests with QtCreator. Below is the content of tests_pro.
@QT += testlib sql widgets uitools
HEADERS +=
testdataaccess.hpp
testconnecdialog.hpp
testdynamicwidgets.hppSOURCES +=
testdataaccess.cpp
main.cpp
testconnecdialog.cpp
testdynamicwidgets.cppOTHER_FILES += uitests/*
#lib dataaccess
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../dataaccess/release/ -ldataaccess
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../dataaccess/debug/ -ldataaccess
else:unix: LIBS += -L$$OUT_PWD/../dataaccess/ -ldataaccessINCLUDEPATH += $$PWD/../dataaccess
DEPENDPATH += $$PWD/../dataaccesswin32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../dataaccess/release/libdataaccess.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../dataaccess/debug/libdataaccess.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../dataaccess/release/dataaccess.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../dataaccess/debug/dataaccess.lib
else:unix: PRE_TARGETDEPS += $$OUT_PWD/../dataaccess/libdataaccess.a#lib GUI
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../gui/release/ -lgui
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../gui/debug/ -lgui
else:unix: LIBS += -L$$OUT_PWD/../gui/ -lguiINCLUDEPATH += $$PWD/../gui
DEPENDPATH += $$PWD/../guiwin32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../gui/release/libgui.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../gui/debug/libgui.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../gui/release/gui.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../gui/debug/gui.lib
else:unix: PRE_TARGETDEPS += $$OUT_PWD/../gui/libgui.a@In pure makefile, I do this way:
@mkdir -p ui
cp -i uitests/*.ui ui/@simple
I do not know how to do the same thing with qmake script.
[quote author="SGaist" date="1413316037"]If you generated the test with Qt Creator you should have a line like
@DEFINES += SRCDIR=\\"$$PWD/\\"@So you can use SRCDIR to access the files in your sources from your test[/quote]
-
Ok, basing myself by the "solution":http://dragly.org/2013/11/05/copying-data-files-to-the-build-directory-when-working-with-qmake/, I mounted the script of copies that I needed.
@createdir.commands = $(MKDIR) $$OUT_PWD/uitests
copyfiles.commands = $(COPY) $$PWD/$$OTHER_FILES $$OUT_PWD/uitests
first.depends = $(first) createdir copyfiles
export(first.depends)
export(createdir.commands)
export(copyfiles.commands)
QMAKE_EXTRA_TARGETS += first createdir copyfiles
@However, the solution does not explain a few things:
'depends' and 'commands' are required? Are they for?
-
IIRC, something like
@
QMAKE_POST_LINK += $$quote($(COPY_DIR) $$PWD/uitests PATH_TO_BUILDIR/ui)
@should do the job
-
Perfect SGaist! More compact
[quote author="SGaist" date="1413498710"]IIRC, something like
@
QMAKE_POST_LINK += $$quote($(COPY_DIR) $$PWD/uitests PATH_TO_BUILDIR/ui)
@should do the job[/quote]
-
And should also be cross-platform :)
-
My dear fellow, sorry to raise this topic, but how do I copy two different folders?
I tried this:@QMAKE_POST_LINK += $$quote($(COPY_DIR) $$PWD/uis $$OUT_PWD/../tests/uis)
$$quote($(COPY_DIR) $$PWD/translations $$OUT_PWD/../tests/translations)@unsuccessfully
-
You need to add $$escape_expand(\n\t) after each line except the last one
-
Thanks boy!