diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index d3d7935..3060c05 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -16,7 +16,7 @@ jobs: modules: 'qtimageformats' - name: Run a qt project run: | - cmake . -Bbuild + cmake . -Bbuild -DTRANSLATION_RESOURCE_EMBEDDING=ON cmake --build build - name: Deploy run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index cca4167..b9736e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ include (FeatureSummary) option (EXIV2_METADATA_SUPPORT "Better image metadata support via libexiv2" ON) option (PREFER_QT_5 "Prefer to use Qt 5" OFF) +option (TRANSLATION_RESOURCE_EMBEDDING "Embedding .qm translation files inside resource" OFF) set (CMAKE_CXX_STANDARD 17) set (CMAKE_CXX_STANDARD_REQUIRED ON) @@ -115,7 +116,11 @@ add_executable (${EXE_NAME} ) if (${QT_VERSION_MAJOR} EQUAL "6") - qt_add_translations(${EXE_NAME} TS_FILES ${PPIC_TS_FILES} QM_FILES_OUTPUT_VARIABLE PPIC_QM_FILES) + if (TRANSLATION_RESOURCE_EMBEDDING) + qt_add_translations(${EXE_NAME} TS_FILES ${PPIC_TS_FILES}) + else() + qt_add_translations(${EXE_NAME} TS_FILES ${PPIC_TS_FILES} QM_FILES_OUTPUT_VARIABLE PPIC_QM_FILES) + endif() else() qt_create_translation(PPIC_QM_FILES ${PPIC_CPP_FILES_FOR_I18N} ${PPIC_TS_FILES}) endif() @@ -256,19 +261,25 @@ install ( ${INSTALL_TARGETS_DEFAULT_ARGS} ) -if (WIN32) +if (TRANSLATION_RESOURCE_EMBEDDING) + target_compile_definitions(${EXE_NAME} + PRIVATE TRANSLATION_RESOURCE_EMBEDDING + ) +elseif (WIN32) set (QM_FILE_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}/translations") -else () +else() set (QM_FILE_INSTALL_DIR "${CMAKE_INSTALL_FULL_DATADIR}/pineapple-pictures/translations") target_compile_definitions(${EXE_NAME} - PRIVATE QM_FILE_INSTALL_DIR=${QM_FILE_INSTALL_DIR} + PRIVATE QM_FILE_INSTALL_ABSOLUTE_DIR=${QM_FILE_INSTALL_DIR} ) -endif () +endif() -install ( - FILES ${PPIC_QM_FILES} - DESTINATION ${QM_FILE_INSTALL_DIR} -) +if (DEFINED QM_FILE_INSTALL_DIR) + install( + FILES ${PPIC_QM_FILES} + DESTINATION ${QM_FILE_INSTALL_DIR} + ) +endif() feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/app/main.cpp b/app/main.cpp index 65afe08..e55b9b5 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -13,11 +13,6 @@ #include #include -// QM_FILE_INSTALL_DIR should be defined from the CMakeLists file. -#ifndef QM_FILE_INSTALL_DIR -#define QM_FILE_INSTALL_DIR ":/i18n/" -#endif // QM_FILE_INSTALL_DIR - int main(int argc, char *argv[]) { QCoreApplication::setApplicationName("Pineapple Pictures"); @@ -30,11 +25,12 @@ int main(int argc, char *argv[]) #endif QTranslator translator; - QString qmDir; -#ifdef _WIN32 - qmDir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath("translations"); +#if defined(TRANSLATION_RESOURCE_EMBEDDING) + const QString qmDir = QLatin1String(":/i18n/"); +#elif defined(QM_FILE_INSTALL_ABSOLUTE_DIR) + const QString qmDir = QT_STRINGIFY(QM_FILE_INSTALL_ABSOLUTE_DIR); #else - qmDir = QT_STRINGIFY(QM_FILE_INSTALL_DIR); + const QString qmDir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath("translations"); #endif if (translator.load(QLocale(), QLatin1String("PineapplePictures"), QLatin1String("_"), qmDir)) { QCoreApplication::installTranslator(&translator);