Skip to content

Commit

Permalink
BUILD(cmake): Work around invalidly reported Qt translation directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzmbrzl committed Feb 15, 2025
1 parent 748a003 commit 5688828
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cmake/qt-utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,35 @@ function(bundle_qt_translations TARGET)
query_qmake(QT_TRANSLATIONS_DIRECTORY "QT_INSTALL_TRANSLATIONS")
string(STRIP "${QT_TRANSLATIONS_DIRECTORY}" QT_TRANSLATIONS_DIRECTORY)

if (NOT EXISTS "${QT_TRANSLATIONS_DIRECTORY}" AND VCPKG_TARGET_TRIPLET)
message(STATUS "Trying to fix Qt translation directory...")

file(TO_NATIVE_PATH "/" path_separator)
file(TO_NATIVE_PATH "${QT_TRANSLATIONS_DIRECTORY}" QT_TRANSLATIONS_DIRECTORY)
string(REPLACE "${path_separator}" ";" PATH_COMPONENTS "${QT_TRANSLATIONS_DIRECTORY}")

set(PROCESSED_COMPONENTS "")

foreach (CURRENT_COMPONENT IN LISTS PATH_COMPONENTS)
message(STATUS "Current component '${CURRENT_COMPONENT}' vs. '${VCPKG_TARGET_TRIPLET}'?")
if ("${VCPKG_TARGET_TRIPLET}" MATCHES "^${CURRENT_COMPONENT}")
# In a vcpkg installation, it can happen that the path to the translation directory
# is reported to reside in the wrong triplet subdir. Hence, we try to rectify this
# by replacing the wrong triplet with the actual triplet that is being used.
# See https://github.com/microsoft/vcpkg/issues/40506
list(APPEND PROCESSED_COMPONENTS "${VCPKG_TARGET_TRIPLET}")
else()
list(APPEND PROCESSED_COMPONENTS "${CURRENT_COMPONENT}")
endif()
endforeach()

list(JOIN PROCESSED_COMPONENTS "${path_separator}" QT_TRANSLATIONS_DIRECTORY)
endif()

if (NOT EXISTS "${QT_TRANSLATIONS_DIRECTORY}")
message(FATAL_ERROR "Unable to determine Qt translation directory (determined path '${QT_TRANSLATIONS_DIRECTORY}' does not exist)")
endif()

message(STATUS "Bundling Qt translations from \"${QT_TRANSLATIONS_DIRECTORY}\"")

# Compile our version of Qt translations
Expand Down

0 comments on commit 5688828

Please sign in to comment.