Skip to content

Commit

Permalink
Merge pull request #992 from Chilledheart/qt6_prepare_for_crosscompiling
Browse files Browse the repository at this point in the history
qt6: prepare for cross-compiling
  • Loading branch information
Chilledheart authored Jun 2, 2024
2 parents d04e676 + 5a0d909 commit aee8ecf
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
*.crt text eol=lf
*.sh text eol=lf
*.patch text eol=lf
*.ts text eol=lf
*.qm binary
42 changes: 23 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2128,7 +2128,7 @@ elseif (GUI)
message(WARNING "pkg-config (required to search gtk+ path) not found, disabling GUI build")
set(GUI off)
elseif(USE_QT6)
find_package(Qt6 REQUIRED Widgets Gui LinguistTools)
find_package(Qt6 REQUIRED Widgets Gui OPTIONAL_COMPONENTS LinguistTools)
set(GUI_USE_FILE "")
set(GUI_INCLUDE_DIRS "")
set(GUI_DEFINITIONS "")
Expand Down Expand Up @@ -4600,24 +4600,28 @@ if (GUI)
${SRC_FILES}
${GUI_USE_FILE}
)
file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/qt6/lang/yass_*.ts")
# Custom target to update .ts files and include new strings from source files
# Depends on Qt's LinguistTools
get_target_property(QT_LUPDATE_EXECUTABLE Qt::lupdate IMPORTED_LOCATION)
add_custom_target(update-ts
COMMAND ${QT_LUPDATE_EXECUTABLE} -extensions cc,cpp,hpp
-locations none
-I "${CMAKE_CURRENT_SOURCE_DIR}/src"
"${CMAKE_CURRENT_SOURCE_DIR}/src/qt6"
-ts ${TS_FILES}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/qt6"
VERBATIM
COMMAND_EXPAND_LISTS)
# Based on https://gist.github.com/giraldeau/546ba5512a74dfe9d8ea0862d66db412
set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/src/qt6/lang")
qt_add_translation(QM_FILES ${TS_FILES} OPTIONS -removeidentical -silent)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/qt6/lang/lang.qrc" "${CMAKE_CURRENT_BINARY_DIR}/src/qt6/lang/lang.qrc" COPYONLY)
target_sources(${APP_NAME} PRIVATE ${QM_FILES} "${CMAKE_CURRENT_BINARY_DIR}/src/qt6/lang/lang.qrc")
if (NOT CMAKE_CROSSCOMPILING AND TARGET Qt::lupdate)
file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/qt6/lang/yass_*.ts")
# Custom target to update .ts files and include new strings from source files
# Depends on Qt's LinguistTools
get_target_property(QT_LUPDATE_EXECUTABLE Qt::lupdate IMPORTED_LOCATION)
add_custom_target(update-ts
COMMAND ${QT_LUPDATE_EXECUTABLE} -extensions cc,cpp,hpp
-locations none
-I "${CMAKE_CURRENT_SOURCE_DIR}/src"
"${CMAKE_CURRENT_SOURCE_DIR}/src/qt6"
-ts ${TS_FILES}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/qt6"
VERBATIM
COMMAND_EXPAND_LISTS)
# Based on https://gist.github.com/giraldeau/546ba5512a74dfe9d8ea0862d66db412
set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/src/qt6/lang")
qt_add_translation(QM_FILES ${TS_FILES} OPTIONS -removeidentical -silent)
target_sources(${APP_NAME} PRIVATE ${QM_FILES} "${CMAKE_CURRENT_SOURCE_DIR}/src/qt6/lang/lang.qrc")
else()
file(GLOB QM_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/qt6/lang/yass_*.qm")
target_sources(${APP_NAME} PRIVATE ${QM_FILES} "${CMAKE_CURRENT_SOURCE_DIR}/src/qt6/lang/lang.qrc")
endif()
else()
add_executable(${APP_NAME} WIN32 ${GUI_OPTIONS}
${SRC_FILES}
Expand Down
9 changes: 9 additions & 0 deletions cmake/platforms/Android.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ set(CMAKE_SYSROOT "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ANDROID_CURREN
set(CMAKE_CXX_COMPILE_OBJECT
"<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE> -nostdinc++")
string(APPEND CMAKE_CXX_STANDARD_LIBRARIES " -nostdlib++")

# target environment on the build host system
set(CMAKE_FIND_ROOT_PATH "${CMAKE_SYSROOT}")

# modify default behavior of FIND_XXX() commands
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
9 changes: 9 additions & 0 deletions cmake/platforms/FreeBSD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ set(CMAKE_RANLIB "${LLVM_SYSROOT}/bin/llvm-ranlib" CACHE FILEPATH "")
set(CMAKE_CXX_COMPILER_RANLIB "${LLVM_SYSROOT}/bin/llvm-ranlib" CACHE FILEPATH "")

set(CMAKE_SYSROOT "${GCC_SYSROOT}" CACHE STRING "")

# target environment on the build host system
set(CMAKE_FIND_ROOT_PATH "${GCC_SYSROOT}")

# modify default behavior of FIND_XXX() commands
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
9 changes: 9 additions & 0 deletions cmake/platforms/Linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,12 @@ set(CMAKE_C_FLAGS "${_CMAKE_C_FLAGS_INITIAL} ${COMPILE_FLAGS}" CACHE STRING "" F

set(_CMAKE_CXX_FLAGS_INITIAL "${CMAKE_CXX_FLAGS}" CACHE STRING "")
set(CMAKE_CXX_FLAGS "${_CMAKE_CXX_FLAGS_INITIAL} ${COMPILE_FLAGS}" CACHE STRING "" FORCE)

# target environment on the build host system
set(CMAKE_FIND_ROOT_PATH ${GCC_SYSROOT})

# modify default behavior of FIND_XXX() commands
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
2 changes: 1 addition & 1 deletion cmake/platforms/MinGW.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ else()
set(CMAKE_SYSROOT "${MINGW_SYSROOT}/${GCC_TARGET}" CACHE STRING "")
endif()


# target environment on the build host system
set(CMAKE_FIND_ROOT_PATH ${LLVM_SYSROOT}/${GCC_TARGET})

# modify default behavior of FIND_XXX() commands
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
5 changes: 5 additions & 0 deletions cmake/platforms/WinMsvc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ set(CMAKE_CXX_STANDARD_LIBRARIES "" CACHE STRING "" FORCE)

# where is the target environment
set (CMAKE_FIND_ROOT_PATH "${WINSDK_BASE}")
# modify default behavior of FIND_XXX() commands
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set (CMAKE_SYSTEM_INCLUDE_PATH
"${ATLMFC_INCLUDE}"
"${MSVC_INCLUDE}"
Expand Down
1 change: 1 addition & 0 deletions src/qt6/lang/yass_en.qm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<�d��!�`���
Binary file added src/qt6/lang/yass_zh_CN.qm
Binary file not shown.

0 comments on commit aee8ecf

Please sign in to comment.