diff --git a/.qmake.conf b/.qmake.conf new file mode 100644 index 00000000..546e78a9 --- /dev/null +++ b/.qmake.conf @@ -0,0 +1 @@ +QMAKEFEATURES += $$PWD diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 1ac6aedb..bd16e922 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -3,6 +3,10 @@ QT += core gui printsupport network svg xml widgets CONFIG += c++17 CONFIG += nokey +win32: CONFIG += lrelease_dosdevice +else: CONFIG += lrelease +CONFIG += embed_translations + # uncomment the following line to enable vcs (git) support # CONFIG += ENABLE_VCS @@ -539,13 +543,6 @@ TRANSLATIONS += \ translations/RedPandaIDE_zh_TW.ts \ translations/RedPandaIDE_pt_BR.ts -EXTRA_TRANSLATIONS += \ - ../libs/redpanda_qt_utils/qt_utils_zh_CN.ts \ - ../libs/qsynedit/qsynedit_zh_CN.ts - - -#CONFIG += lrelease embed_translations - win32: { !isEmpty(PREFIX) { target.path = $${PREFIX} @@ -567,31 +564,6 @@ RESOURCES += \ RC_ICONS = images/devcpp.ico images/associations/c.ico images/associations/cpp.ico images/associations/dev.ico images/associations/c.ico images/associations/cpp.ico images/associations/h.ico images/associations/hpp.ico -# fixed lrelease.prf -qtPrepareTool(QMAKE_LRELEASE, lrelease) - -isEmpty(LRELEASE_DIR): LRELEASE_DIR = .qm -isEmpty(QM_FILES_RESOURCE_PREFIX): QM_FILES_RESOURCE_PREFIX = i18n - -lrelease.name = lrelease -lrelease.input = TRANSLATIONS EXTRA_TRANSLATIONS -lrelease.output = $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm -lrelease.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN} $$QMAKE_LRELEASE_FLAGS -qm ${QMAKE_FILE_OUT} -silent: lrelease.commands = @echo lrelease ${QMAKE_FILE_IN} && $$lrelease.commands -lrelease.CONFIG = no_link target_predeps -QMAKE_EXTRA_COMPILERS += lrelease - -all_translations = $$TRANSLATIONS $$EXTRA_TRANSLATIONS -for (translation, all_translations) { - # mirrors $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm above - translation = $$basename(translation) - QM_FILES += $$OUT_PWD/$$LRELEASE_DIR/$$replace(translation, \\..*$, .qm) -} - -qmake_qm_files.files = $$QM_FILES -qmake_qm_files.base = $$OUT_PWD/$$LRELEASE_DIR -qmake_qm_files.prefix = $$QM_FILES_RESOURCE_PREFIX - iconsets_files.files += $$files(resources/iconsets/*.svg, true) iconsets_files.files += $$files(resources/iconsets/*.json, true) @@ -601,7 +573,6 @@ theme_files.files += $$files(resources/themes/*.png, false) colorscheme_files.files += $$files(resources/colorschemes/*.scheme, false) -RESOURCES += qmake_qm_files RESOURCES += iconsets_files RESOURCES += theme_files RESOURCES += colorscheme_files diff --git a/RedPandaIDE/main.cpp b/RedPandaIDE/main.cpp index 1e37d936..0789cf08 100644 --- a/RedPandaIDE/main.cpp +++ b/RedPandaIDE/main.cpp @@ -280,6 +280,8 @@ int main(int argc, char *argv[]) app.setAttribute(Qt::AA_UseHighDpiPixmaps); + ExternalResource resource; + QLockFile lockFile(QDir::tempPath()+QDir::separator()+"RedPandaDevCppStartUp.lock"); { bool firstRun; diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index d7eb4726..2e3d8675 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -784,3 +784,13 @@ QByteArray reformatContentUsingAstyle(const QByteArray &content, const QStringLi env); return newContent; } + +ExternalResource::ExternalResource() { + Q_INIT_RESOURCE(qsynedit_qmake_qmake_qm_files); + Q_INIT_RESOURCE(redpanda_qt_utils_qmake_qmake_qm_files); +} + +ExternalResource::~ExternalResource() { + Q_CLEANUP_RESOURCE(qsynedit_qmake_qmake_qm_files); + Q_CLEANUP_RESOURCE(redpanda_qt_utils_qmake_qmake_qm_files); +} diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h index cf4f8100..b4b5d039 100644 --- a/RedPandaIDE/utils.h +++ b/RedPandaIDE/utils.h @@ -204,4 +204,9 @@ std::tuple wrapCommandFor std::tuple wrapCommandForTerminalEmulator(const QString &terminal, const QString &argsPattern, const QStringList &payloadArgsWithArgv0); +struct ExternalResource { + ExternalResource(); + ~ExternalResource(); +}; + #endif // UTILS_H diff --git a/RedPandaIDE/xmake.lua b/RedPandaIDE/xmake.lua index a3510fcc..3d0ba3d4 100644 --- a/RedPandaIDE/xmake.lua +++ b/RedPandaIDE/xmake.lua @@ -228,11 +228,7 @@ target("RedPandaIDE") -- libs - if is_plat("windows") then - add_links("redpanda_qt_utils", "qsynedit") -- xmake 2.8.6 workaround - else - add_linkgroups("redpanda_qt_utils", "qsynedit", {whole = true}) - end + add_links("redpanda_qt_utils", "qsynedit") if is_os("windows") then add_links("psapi", "shlwapi") end diff --git a/libs/qsynedit/qsynedit.pro b/libs/qsynedit/qsynedit.pro index 60b03dd2..8b542ae0 100644 --- a/libs/qsynedit/qsynedit.pro +++ b/libs/qsynedit/qsynedit.pro @@ -13,6 +13,10 @@ contains(QMAKE_HOST.arch, x86_64):{ } } +win32: CONFIG += lrelease_dosdevice +else: CONFIG += lrelease +CONFIG += embed_translations +QMAKE_RESOURCE_FLAGS += -name $(QMAKE_TARGET)_${QMAKE_FILE_BASE} win32: { DEFINES += _WIN32_WINNT=0x0501 diff --git a/libs/qsynedit/xmake.lua b/libs/qsynedit/xmake.lua index 844e3956..0449d190 100644 --- a/libs/qsynedit/xmake.lua +++ b/libs/qsynedit/xmake.lua @@ -39,6 +39,8 @@ target("qsynedit") add_ui_classes() + add_files("*.ts") + add_includedirs(".", {interface = true}) -- do not install diff --git a/libs/redpanda_qt_utils/redpanda_qt_utils.pro b/libs/redpanda_qt_utils/redpanda_qt_utils.pro index f63e244b..9a7feeb0 100644 --- a/libs/redpanda_qt_utils/redpanda_qt_utils.pro +++ b/libs/redpanda_qt_utils/redpanda_qt_utils.pro @@ -7,6 +7,11 @@ CONFIG += c++17 CONFIG += nokey CONFIG += staticlib +win32: CONFIG += lrelease_dosdevice +else: CONFIG += lrelease +CONFIG += embed_translations +QMAKE_RESOURCE_FLAGS += -name $(QMAKE_TARGET)_${QMAKE_FILE_BASE} + win32: { DEFINES += _WIN32_WINNT=0x0501 } diff --git a/libs/redpanda_qt_utils/xmake.lua b/libs/redpanda_qt_utils/xmake.lua index 3adcb2b2..68aa25d7 100644 --- a/libs/redpanda_qt_utils/xmake.lua +++ b/libs/redpanda_qt_utils/xmake.lua @@ -5,6 +5,7 @@ target("redpanda_qt_utils") add_files("qt_utils/utils.cpp") add_moc_classes("qt_utils/charsetinfo") + add_files("*.ts") add_includedirs(".", {interface = true}) -- do not install diff --git a/lrelease_dosdevice.prf b/lrelease_dosdevice.prf new file mode 100644 index 00000000..13c378c7 --- /dev/null +++ b/lrelease_dosdevice.prf @@ -0,0 +1,47 @@ +# Automatically generate .qm files out of .ts files in TRANSLATIONS and +# EXTRA_TRANSLATIONS. +# +# If embed_translations is enabled, the generated .qm files are made available +# in the resource system under :/i18n/. +# +# Otherwise, the .qm files are available in the build directory in LRELEASE_DIR. +# They can also be automatically installed by setting QM_FILES_INSTALL_PATH. + +qtPrepareTool(QMAKE_LRELEASE, lrelease) + +isEmpty(LRELEASE_DIR): LRELEASE_DIR = .qm +isEmpty(QM_FILES_RESOURCE_PREFIX): QM_FILES_RESOURCE_PREFIX = i18n + +lrelease.name = lrelease +lrelease.input = TRANSLATIONS EXTRA_TRANSLATIONS +lrelease.output = $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm +lrelease.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN} $$QMAKE_LRELEASE_FLAGS -qm ${QMAKE_FILE_OUT} +silent: lrelease.commands = @echo lrelease ${QMAKE_FILE_IN} && $$lrelease.commands +lrelease.CONFIG = no_link +QMAKE_EXTRA_COMPILERS += lrelease + +# redpanda-cpp: fix dos device compatibility. +# When building in different drive letter from the source, the dependency `*.qm` for generating +# `qmake_qm_files.cpp` is missing in makefile. Adding `target_predeps` forces correct build order. +lrelease.CONFIG += target_predeps + +all_translations = $$TRANSLATIONS $$EXTRA_TRANSLATIONS +for (translation, all_translations) { + # mirrors $$LRELEASE_DIR/${QMAKE_FILE_IN_BASE}.qm above + translation = $$basename(translation) + QM_FILES += $$OUT_PWD/$$LRELEASE_DIR/$$replace(translation, \\.[^.]+$, .qm) +} +embed_translations { + qmake_qm_files.files = $$QM_FILES + qmake_qm_files.base = $$OUT_PWD/$$LRELEASE_DIR + qmake_qm_files.prefix = $$QM_FILES_RESOURCE_PREFIX + RESOURCES += qmake_qm_files +} else { + !isEmpty(QM_FILES_INSTALL_PATH) { + qm_files.files = $$QM_FILES + qm_files.path = $$QM_FILES_INSTALL_PATH + qm_files.CONFIG = no_check_exist + INSTALLS += qm_files + } + lrelease.CONFIG += target_predeps no_clean +} diff --git a/xmake.lua b/xmake.lua index 47aa042c..79383d4a 100644 --- a/xmake.lua +++ b/xmake.lua @@ -75,35 +75,48 @@ rule("qt.ts") -- save lrelease target:data_set("qt.lrelease", lrelease) end) - on_buildcmd_file(function (target, batchcmds, sourcefile_ts, opt) - -- get tools + on_buildcmd_files(function (target, batchcmds, sourcebatch, opt) local lrelease = target:data("qt.lrelease") - local rcc = target:data("qt.rcc") - -- get qm file - local sourcefile_qm = path.join(target:autogendir(), "rules", "qt", "ts", path.basename(sourcefile_ts) .. ".qm") - local sourcefile_dir = path.directory(sourcefile_qm) - -- prepare qrc file - local sourcefile_qrc = path.join(target:autogendir(), "rules", "qt", "ts", path.basename(sourcefile_ts) .. ".qrc") - io.writefile(sourcefile_qrc, [[ + local qrc_content = [[ - - ]] .. path.absolute(sourcefile_qm) .. [[ - + + ]] + for _, sourcefile_ts in ipairs(sourcebatch.sourcefiles) do + if is_host("windows") then + sourcefile_ts = sourcefile_ts:gsub("\\", "/") + end + -- get qm file + local sourcefile_qm = path.join(target:autogendir(), "rules", "qt", "ts", path.basename(sourcefile_ts) .. ".qm") + local sourcefile_dir = path.directory(sourcefile_qm) + -- build ts to qm file + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.qt.ts %s", sourcefile_ts) + batchcmds:mkdir(sourcefile_dir) + batchcmds:vrunv(lrelease, {sourcefile_ts, "-qm", sourcefile_qm}) + + qrc_content = qrc_content .. [[ + ]] .. path.absolute(sourcefile_qm) .. [[ + ]] + end + qrc_content = qrc_content .. [[ + - ]]) + ]] + + local rcc = target:data("qt.rcc") + local name = target:name() .. "_qmake_qmake_qm_files" -- same as qmake + local sourcefile_qrc = path.join(target:autogendir(), "rules", "qt", "ts", name .. ".qrc") + io.writefile(sourcefile_qrc, qrc_content) -- get c++ source file for qrc - local sourcefile_cpp = path.join(target:autogendir(), "rules", "qt", "ts", path.basename(sourcefile_ts) .. ".cpp") + local sourcefile_cpp = path.join(target:autogendir(), "rules", "qt", "ts", name .. ".cpp") -- add objectfile local objectfile = target:objectfile(sourcefile_cpp) table.insert(target:objectfiles(), objectfile) -- add commands - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.qt.ts %s", sourcefile_ts) - batchcmds:mkdir(sourcefile_dir) - batchcmds:vrunv(lrelease, {sourcefile_ts, "-qm", sourcefile_qm}) - batchcmds:vrunv(rcc, {"-name", path.basename(sourcefile_qrc), sourcefile_qrc, "-o", sourcefile_cpp}) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.qt.ts %s", sourcefile_cpp) + batchcmds:vrunv(rcc, {"-name", name, sourcefile_qrc, "-o", sourcefile_cpp}) batchcmds:compile(sourcefile_cpp, objectfile) -- add deps - batchcmds:add_depfiles(sourcefile_ts) + batchcmds:add_depfiles(sourcebatch.sourcefiles) batchcmds:set_depmtime(os.mtime(objectfile)) batchcmds:set_depcache(target:dependfile(objectfile)) end)