Horst Walter
Horst Walter

Reputation: 14081

Qt Creator subproject just to copy files

I have a Qt subproject which only contains directories with files (no source code). Those files are to be copied to the build/bin directory

QtProject
  subproject1 (contains code)
  subproject2 (only contains directories with files to be copied)
    files1
    files2

So far I have been using QMAKE_PRE_LINK and QMAKE_PRE_LINK to copy the files (which works). However, as the project template is TEMPLATE = lib I get compile warnings as there is no code to be generated (see bottom).

If I change to TEMPLATE = subdirs the copy is not triggered, as there is no link operation.

So how can I trigger the copy operation without any source code?


Compile errors with TEMPLATE = lib

:-1: warning: LNK4001: no object files specified; libraries used
:-1: warning: LNK4068: /MACHINE not specified; defaulting to X86
:-1: error: LNK2001: unresolved external symbol __DllMainCRTStartup@12
debug\blackresources.dll:-1: error: LNK1120: 1 unresolved externals

copy which works, except for the above compile errors

QMAKE_PRE_LINK += $$COPY $$shell_path($$PWD/data) \
                      $$shell_path($$OUT_PWD/../bin/resources)

Upvotes: 1

Views: 1741

Answers (1)

phyatt
phyatt

Reputation: 19112

Extra build steps are mentioned in a generic fashion in the documentation...

http://doc.qt.io/qt-5/qmake-advanced-usage.html#adding-custom-targets

mytarget.target = .buildfile
mytarget.commands = touch $$mytarget.target
mytarget.depends = mytarget2

mytarget2.commands = @echo Building $$mytarget.target

...

QMAKE_EXTRA_TARGETS += mytarget mytarget2

Copying data files to the build directory with qmake

dragly spells it out nicely on his website. I've copied over some chunks of it.

http://dragly.org/2013/11/05/copying-data-files-to-the-build-directory-when-working-with-qmake/

copydata.commands = $(COPY_DIR) $$PWD/data $$OUT_PWD
first.depends = $(first) copydata
export(first.depends)
export(copydata.commands)
QMAKE_EXTRA_TARGETS += first copydata

The meaning of the different names in the above are as follows:

  • $(COPY_DIR) – Holds a platform-dependent copy-command that makes sure to copy recursively.
  • $$PWD – Holds the name of the source code directory, where your .pro file resides.
  • $$OUT_PWD – Holds the name of the build directory. Note that this may not work if you are running qmake and make in the same directory as your source code, as you will be copying into the same folder as you copy from.
  • copydata – Just a name we choose. You can replace this with whatever you want.
  • first – This is a build step that already exists in the Makefile generated by qmake. We attach the copy build step to this build step. export – Makes the variable in the argument of the function available in a global scope.
  • QMAKE_EXTRA_TARGETS – Tells qmake that you want to build more targets than the ones it adds by default to the Makefile. This method is a bit messy, and I wish the Qt developers would make it easier to do this, but it works. It also ensures that the data is always copied, ensuring that any changes in the data folder are pushed to the build folder.

On Windows, I personally like robocopy for all of my mirroring needs. And on linux/mac, it is hard to go wrong with rsync.

Hope that helps.

Upvotes: 2

Related Questions