I am trying to use qmake to include all files in a directory (this project is an external subversion project with hundreds of files). I am using qmake version 3.1.
What I tried was something like:
server_files = $$files($$PWD/server)
SOURCES += server_files(*.cpp, true)
The first line does not give any error but the second line gives:
:-1: warning: Failure to find: server_files(*.cpp,
:-1: warning: Failure to find: true)
Putting a $ sign in front of the variable as SOURCES += $server_files(*.cpp, true) gives the same error.
The following example function takes a variable name as its only argument, extracts a list of values from the variable with the eval() built-in function, and compiles a list of files:
defineReplace(headersAndSources) {
variable = $$1
names = $$eval($$variable)
headers =
sources =
for(name, names) {
header = $${name}.h
exists($$header) {
headers += $$header
}
source = $${name}.cpp
exists($$source) {
sources += $$source
}
}
return($$headers $$sources)
}
Variable Processing Functions
Related
I have a problem with including a file through ".pro" file.
If the ARCH equals "64bit" ,this is an environment variable of my system, I will include a 'function1.h' to my project.
else, include 'function2.h'
But only a message works properly and both files are included together.
I mean, I only can see a Project Message saying "Hello 64-bit" , but I can see two files in my project file list. function1.h and function2.h.
what's the problem and how can I make this out
here is my code
QT += quick
CONFIG += c++11
SOURCES += main.cpp
OS_IS = $$(ARCH)
equals(OS_IS,64bit){
message("Hello 64-bit")
HEADERS += function1.h
}else{
message("Hello 32-bit")
HEADERS += function2.h
}
...
Thank you in advance
I think that your problem must be in other place. This is working to me as expected:
OS_IS = $$(ARCH)
message("Headers before:" $$HEADERS)
equals(OS_IS,"64bit"){
message("Hello 64-bit")
HEADERS += function1.h
}else{
message("Hello 32-bit")
HEADERS += function2.h
}
message("Headers after:" $$HEADERS)
This question has been posted before in the qt community: https://forum.qt.io/topic/106930/how-to-run-lupdate-with-a-qmake-config
I use such a construct in my project files:
LANGUAGES = de
TRANSLATION_NAME = authorization
include(../../gen_translations.pri)
where gen_translations.pri looks like so:
# parameters: var, prepend, append
defineReplace(prependAll) {
for(a,$$1):result += $$2$${a}$$3
return($$result)
}
TRANSLATIONS = $$prependAll(LANGUAGES, $$PWD/libs/$$TRANSLATION_NAME/translations/lib$${TRANSLATION_NAME}_, .ts)
TRANSLATIONS_FILES =
qtPrepareTool(LRELEASE, lrelease)
for(tsfile, TRANSLATIONS) {
qmfile = $$shadowed($$tsfile)
qmfile ~= s,.ts$,.qm,
qmdir = $$dirname(qmfile)
!exists($$qmdir) {
mkpath($$qmdir)|error("Aborting.")
}
command = $$LRELEASE -removeidentical $$tsfile -qm $$qmfile
system($$command)|error("Failed to run: $$command")
TRANSLATIONS_FILES += $$qmfile
}
for(qmentry, $$list($$TRANSLATIONS_FILES)) {
qmpath = $$OUT_PWD/../translations
qmpathname = $$replace(qmpath,/,)
qmpathname = $$replace(qmpathname,\.,)
qmpathname = $$replace(qmpathname,:,)
qmpathname = $$replace(qmpathname," ",)
qmentity = qmfiles_$${qmpathname}
eval($${qmentity}.files += $$qmentry)
eval($${qmentity}.path = $$qmpath)
INSTALLS *= $${qmentity}
}
It generates the *.qm files for me and moves them to a defined location with make install.
I do not want qmake to execute that whole stuff for each build on my developing machine. Therefore I want to make it conditional by wrapping it for qmake:
translate{
LANGUAGES = de
TRANSLATION_NAME = authorization
include(../../gen_translations.pri)
}
That way I can decide when I want to get *.qm files and when not.
But then I am unable to run lupdate on the project file beforehand because it is blocked by that conditional.
I am sure, that someone has a better idea to accomplish the task.
Thanks in advance.
I'm sharing here my recipe for the vmpk project. I've borrowed it from the Arora project (I think). It is much simpler than yours, and I let qmake to decide if it is necessary regenerate any .qm files when the output has been erased or the input .ts has changed, like any other compiler does.
updateqm.pri
# update translations
isEmpty(QMAKE_LRELEASE) {
win32:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]\\lrelease.exe
else:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]/lrelease
!exists($$QMAKE_LRELEASE) { QMAKE_LRELEASE = lrelease }
}
updateqm.input = TRANSLATIONS
updateqm.output = $$OUT_PWD/${QMAKE_FILE_BASE}.qm
updateqm.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN} -qm $$OUT_PWD/${QMAKE_FILE_BASE}.qm
updateqm.CONFIG += no_link target_predeps
QMAKE_EXTRA_COMPILERS += updateqm
project.pro:
TRANSLATIONS += \
translations/project_en.ts \
translations/project_cs.ts \
translations/project_de.ts \
translations/project_es.ts \
translations/project_fr.ts \
translations/project_ru.ts
include(updateqm.pri)
With this project file you can do, as always:
lupdate project.pro
Anyway, Qt5 has a builtin CONFIG+=lrelease option that makes "updateqm.pri" deprecated.
Given the following code contained in a qmake project file:
QWT_LIB_BINARY=/usr/lib/libqwt-qt4.so
TEMP1 = $$basename(QWT_LIB_BINARY)
TEMP2 = $$replace(TEMP1, .so, )
QWT_LIB_NAME = $$replace(TEMP2, lib, )
message(QWT library name = $$QWT_LIB_NAME)
Eliminates the path, the 'lib' prefix and the '.so' suffix of the string
contained in the QWT_LIB_BINARY variable. When compiling, the 'make' command
outputs the following line:
Project MESSAGE: QWT library name = qwt-qt4
When the temporary variable assignations are eliminated, like this:
QWT_LIB_BINARY=/usr/lib/libqwt-qt4.so
QWT_LIB_NAME = $$replace($$replace($$basename(QWT_LIB_BINARY), .so, ), lib, )
message(QWT library name = $$QWT_LIB_NAME)
The 'make' command outputs the message:
Project MESSAGE: QWT library name =
Indicating that the last code is not working correctly. Is it possible to
nest function calls in '.pro' files in some other way, so it can work?
What is the best (proper) way to organize compiled translations (*.qm) into resources?
*.qm files referred in qrc file and generated by two (three) extra targets this way:
trans_update.commands = lupdate $$_PRO_FILE_
trans_update.depends = $$_PRO_FILE_
trans_release.commands = lrelease $$_PRO_FILE_
trans_release.depends = trans_update $$TRANSLATIONS
translate.depends = trans_release
QMAKE_EXTRA_TARGETS += trans_update trans_release translate deploy
CONFIG(release, debug|release) {
DESTDIR=release
PRE_TARGETDEPS += translate
}
but the problem is at the moment qmake runs first time, there're no qm files generated yet and make prints errors like:
RCC: Error in 'qml.qrc': Cannot find file ...
I don't like an idea of saving compiled qm files into VSC.
Is there a way to organize it nicely?
I like to point out a solution which I use in some projects. It might be far from perfect, but it works out nicely.
CONFIG(release, debug|release) {
TRANSLATION_TARGET_DIR = $${OUT_PWD}/release/translations
LANGUPD_OPTIONS = -locations relative -no-ui-lines
LANGREL_OPTIONS = -compress -nounfinished -removeidentical
} else {
TRANSLATION_TARGET_DIR = $${OUT_PWD}/debug/translations
LANGUPD_OPTIONS =
LANGREL_OPTIONS = -markuntranslated "MISS_TR "
}
isEmpty(QMAKE_LUPDATE) {
win32:LANGUPD = $$[QT_INSTALL_BINS]\lupdate.exe
else:LANGUPD = $$[QT_INSTALL_BINS]/lupdate
}
isEmpty(QMAKE_LRELEASE) {
win32:LANGREL = $$[QT_INSTALL_BINS]\lrelease.exe
else:LANGREL = $$[QT_INSTALL_BINS]/lrelease
}
langupd.command = \
$$LANGUPD $$LANGUPD_OPTIONS $$shell_path($$_PRO_FILE_) -ts $$_PRO_FILE_PWD_/$$TRANSLATIONS
langrel.depends = langupd
langrel.input = TRANSLATIONS
langrel.output = $$TRANSLATION_TARGET_DIR/${QMAKE_FILE_BASE}.qm
langrel.commands = \
$$LANGREL $$LANGREL_OPTIONS ${QMAKE_FILE_IN} -qm $$TRANSLATION_TARGET_DIR/${QMAKE_FILE_BASE}.qm
langrel.CONFIG += no_link
QMAKE_EXTRA_TARGETS += langupd
QMAKE_EXTRA_COMPILERS += langrel
PRE_TARGETDEPS += langupd compiler_langrel_make_all
There might be a sensful tweak to lupdate options because the various builds (release and debug) generate different *.ts files which then trigger a change in the used VCS.
I also like to guide the tended reader to an example where experts use it.
The recommended way -- which may not have been available at the time this question was originally asked would be to use
TRANSLATIONS += <your *.ts files>
CONFIG += lrelease embed_translations
If you really need/want to build the qm files separately, I'd point to what qmake does with the above config and adapt it according to your needs. See https://github.com/qt/qtbase/blob/5.15.2/mkspecs/features/lrelease.prf
(Basically, it creates and adds a list of resources to RESOURCES).
I am trying to redefine the \nomencl_command in LyX, in order to be able to use the glossaries package in stead of the obsolete nomencl.
LyX allows you to specify the Nomenclature command, which by default is set to:
makeindex -s nomencl.ist
For glossaries the command is thus changed to:
makeglossaries
However, the LyX implementation of nomencl uses the more recent .nlo as an input file, and the .nls as an output file. Whereas glossaries uses the 'older' .glo and .gls Unfortunately, the extensions cannot be specified.
I found that the preferences file only says:
\nomencl_command "makeglossaries"
but the log output says:
makeglossaries "[filename].nlo" -o [filename].nls
So my question is where is \nomencl_command defined further?
The relevant code is in src/LaTeX.cpp.
Note below that some diagnostic information is written to the latex debug flag. You can see this info on the terminal if you run LyX with lyx -dbg latex.
The following are excerpts from the file src/LaTeX.cpp from the soon-to-be-released (a matter of days) LyX 2.1.
FileName const nlofile(changeExtension(file.absFileName(), ".nlo"));
// If all nomencl entries are removed, nomencl writes an empty nlo file.
// DepTable::hasChanged() returns false in this case, since it does not
// distinguish empty files from non-existing files. This is why we need
// the extra checks here (to trigger a rerun). Cf. discussions in #8905.
// FIXME: Sort out the real problem in DepTable.
if (head.haschanged(nlofile) || (nlofile.exists() && nlofile.isFileEmpty()))
rerun |= runMakeIndexNomencl(file, ".nlo", ".nls");
FileName const glofile(changeExtension(file.absFileName(), ".glo"));
if (head.haschanged(glofile))
rerun |= runMakeIndexNomencl(file, ".glo", ".gls");
and
bool LaTeX::runMakeIndexNomencl(FileName const & file,
string const & nlo, string const & nls)
{
LYXERR(Debug::LATEX, "Running MakeIndex for nomencl.");
message(_("Running MakeIndex for nomencl."));
string tmp = lyxrc.nomencl_command + ' ';
// onlyFileName() is needed for cygwin
tmp += quoteName(onlyFileName(changeExtension(file.absFileName(), nlo)));
tmp += " -o "
+ onlyFileName(changeExtension(file.toFilesystemEncoding(), nls));
Systemcall one;
one.startscript(Systemcall::Wait, tmp, path);
return true;
}
and
// nomencl file
FileName const nls(changeExtension(file.absFileName(), ".nls"));
nls.removeFile();
// nomencl file (old version of the package)
FileName const gls(changeExtension(file.absFileName(), ".gls"));
gls.removeFile();