PDA

View Full Version : How to detect shadow building in qmake?



Fazer
10th August 2010, 19:44
I wrote this code to detect if shadow building is enabled - and when it is, copy some files to the output directory. It works, but...

... it always thinks the shadow building is enabled, even when I build in the same directory as my project. I believe the problem lies within contains() function, which always invokes code inside its scope.

Here's the revelant code in my .pro file:


# if shadow building is enabled
!contains($${PWD}, $${OUT_PWD}) {

# copy files from the current directory to the output directory

# some stuff
}

Maybe there is a better way of detecting shadow building and moving necessary files? I don't want to use INSTALLS because it's supposed to install the app on one's system, not to help developing.


And here is the real code if anyone is interested in how the copying of files is done (currently adjusted for Windows):

# compile translations
QMAKE_POST_LINK += lrelease $$_PRO_FILE_

# if shadow building is enabled
!contains($${PWD}, $${OUT_PWD}) {

# copy files from the current directory to the output directory
win32 {
CHECK_DIR_EXIST = if exist
MAKE_DIR = mkdir
COPY = copy /y
}

# specify files for copying
COMPILED_TRANSLATIONS_SOURCE = $${PWD}/translations/$${TARGET}_pl_PL.qm
COMPILED_TRANSLATIONS_DEST = $${OUT_PWD}/translations

# replace '/' with '\' in Windows paths
win32 {
COMPILED_TRANSLATIONS_SOURCE = $${replace(COMPILED_TRANSLATIONS_SOURCE, /, \)}
COMPILED_TRANSLATIONS_DEST = $${replace(COMPILED_TRANSLATIONS_DEST, /, \)}
}

CHECK_COMPILED_TRANSLATIONS_DEST_DIR_EXIST = $$CHECK_DIR_EXIST $$COMPILED_TRANSLATIONS_DEST
MAKE_COMPILED_TRANSLATIONS_DEST_DIR = $$MAKE_DIR $$COMPILED_TRANSLATIONS_DEST
COPY_COMPILED_TRANSLATIONS = $$COPY $$COMPILED_TRANSLATIONS_SOURCE $$COMPILED_TRANSLATIONS_DEST

QMAKE_POST_LINK += && $$CHECK_COMPILED_TRANSLATIONS_DEST_DIR_EXIST \
($$COPY_COMPILED_TRANSLATIONS) else \
($$MAKE_COMPILED_TRANSLATIONS_DEST_DIR && $$COPY_COMPILED_TRANSLATIONS)
}

Fazer
11th August 2010, 19:16
I solved the issue by using


!equals(PWD, $${OUT_PWD}) {
# code when paths are not equal
}