Files
docview/cmake/WindowsDeployment.cmake
2026-09-21 13:41:40 +09:00

62 lines
3.1 KiB
CMake

# Windows SDK tools and matching Qt binaries are required on the build host.
include_guard(GLOBAL)
if(NOT WIN32)
return()
endif()
set(DOCVIEW_EXTRA_WORKER_RUNTIME_DLLS "" CACHE STRING
"Explicit additional redistributable DLLs approved for worker packaging")
find_program(DOCVIEW_DUMPBIN_EXECUTABLE NAMES dumpbin REQUIRED)
find_program(DOCVIEW_WINDEPLOYQT_EXECUTABLE NAMES windeployqt
HINTS "${Qt6_DIR}/../../../bin" REQUIRED)
function(docview_configure_windows_worker target)
set(script "${CMAKE_CURRENT_BINARY_DIR}/stage-${target}-$<CONFIG>.cmake")
file(GENERATE OUTPUT "${script}" CONTENT "
set(WORKER_EXECUTABLE [==[$<TARGET_FILE:${target}>]==])
set(RUNTIME_LIBRARIES [==[$<TARGET_RUNTIME_DLLS:${target}>]==])
set(SEARCH_DIRECTORIES [==[$<TARGET_FILE_DIR:Qt6::Core>;$<TARGET_FILE_DIR:${DOCVIEW_ZIP_TARGET}>;$<TARGET_FILE_DIR:qpdf::libqpdf>;${DOCVIEW_PDFIUM_ROOT}/bin]==])
set(EXTRA_RUNTIME_LIBRARIES [==[${DOCVIEW_EXTRA_WORKER_RUNTIME_DLLS}]==])
set(CMAKE_GET_RUNTIME_DEPENDENCIES_TOOL dumpbin)
set(CMAKE_GET_RUNTIME_DEPENDENCIES_COMMAND [==[${DOCVIEW_DUMPBIN_EXECUTABLE}]==])
include([==[${CMAKE_CURRENT_FUNCTION_LIST_DIR}/StageWindowsWorker.cmake]==])
")
add_custom_command(TARGET ${target} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -P "${script}" VERBATIM
COMMENT "Collecting and hashing the restricted runtime for ${target}")
endfunction()
function(docview_install_windows_worker target)
set(script "${CMAKE_CURRENT_BINARY_DIR}/install-${target}-$<CONFIG>.cmake")
file(GENERATE OUTPUT "${script}" CONTENT "
set(WORKER_EXECUTABLE [==[$<TARGET_FILE:${target}>]==])
set(WORKER_INSTALL_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}/bin\")
set(WORKER_VERIFY_ONLY FALSE)
include([==[${CMAKE_CURRENT_FUNCTION_LIST_DIR}/InstallWindowsWorker.cmake]==])
")
install(SCRIPT "${script}")
endfunction()
function(docview_install_windows_gui target)
set(script "${CMAKE_CURRENT_BINARY_DIR}/deploy-${target}-$<CONFIG>.cmake")
file(GENERATE OUTPUT "${script}" CONTENT "
set(destination \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin\")
execute_process(COMMAND [==[${DOCVIEW_WINDEPLOYQT_EXECUTABLE}]==]
--$<IF:$<CONFIG:Debug>,debug,release> --no-compiler-runtime --nopatchqt
--dir \"\${destination}\" --plugindir \"\${destination}/plugins\"
--qml-deploy-dir \"\${destination}/qml\" --translationdir \"\${destination}/translations\"
--qmldir [==[${CMAKE_SOURCE_DIR}/qml]==] \"\${destination}/$<TARGET_FILE_NAME:${target}>\"
RESULT_VARIABLE deployed)
if(NOT deployed EQUAL 0)
message(FATAL_ERROR \"windeployqt failed: \${deployed}\")
endif()
file(WRITE \"\${destination}/qt.conf\" \"[Paths]\\nPrefix=.\\nPlugins=plugins\\nQmlImports=qml\\nLibraryExecutables=.\\nData=.\\nTranslations=translations\\n\")
# windeployqt must not patch or replace any hashed worker dependency.
set(WORKER_VERIFY_ONLY TRUE)
foreach(name docview-pdf-worker.exe docview-archive-worker.exe)
set(WORKER_EXECUTABLE \"\${destination}/\${name}\")
include([==[${CMAKE_CURRENT_FUNCTION_LIST_DIR}/InstallWindowsWorker.cmake]==])
endforeach()
")
install(SCRIPT "${script}")
endfunction()