diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 332fdd27aa..d963355066 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -75,6 +75,17 @@ option(BUILD_IFCVIEWER "Build IfcViewer, a high-performance IFC viewer" OFF) # R option(BUILD_IFCVIEWER_TESTS "Build unit tests for IfcViewer (fetches Catch2 v3)" OFF) option(BUILD_PACKAGE "" OFF) +option( + IFCOPENSHELL_DEPLOY_QT_RUNTIME + "Deploy Qt runtime dependencies for installed Qt applications." + ON +) +option( + IFCOPENSHELL_DEPLOY_QT_TRANSLATIONS + "Deploy Qt translation catalogs with installed Qt applications." + OFF +) + option(WITH_OPENCASCADE "Enable geometry interpretation using Open CASCADE" ON) option(WITH_CGAL "Enable geometry interpretation using CGAL" ON) option(WITH_MANIFOLD "Enable geometry interpretation using Manifold" OFF) diff --git a/cmake/utilities.cmake b/cmake/utilities.cmake index 71183daa84..fc8f505c9b 100644 --- a/cmake/utilities.cmake +++ b/cmake/utilities.cmake @@ -69,6 +69,47 @@ function(ifcopenshell_wasm_plugin_link_options TARGET REGISTRATION_SYMBOL) endforeach() endfunction() +function(ifcopenshell_deploy_qt_runtime TARGET) + if(NOT IFCOPENSHELL_DEPLOY_QT_RUNTIME) + return() + endif() + + if(NOT TARGET ${TARGET}) + message(FATAL_ERROR "Cannot deploy Qt runtime for unknown target '${TARGET}'.") + endif() + + get_target_property(target_type ${TARGET} TYPE) + if(NOT target_type STREQUAL "EXECUTABLE") + message(FATAL_ERROR "Qt runtime deployment target '${TARGET}' is not an executable.") + endif() + + set(deploy_args + TARGET ${TARGET} + OUTPUT_SCRIPT deploy_script + NO_UNSUPPORTED_PLATFORM_ERROR + ) + + if(NOT IFCOPENSHELL_DEPLOY_QT_TRANSLATIONS) + list(APPEND deploy_args NO_TRANSLATIONS) + endif() + + list(APPEND deploy_args ${ARGN}) + + if(COMMAND qt_generate_deploy_app_script) + qt_generate_deploy_app_script(${deploy_args}) + elseif(COMMAND qt6_generate_deploy_app_script) + qt6_generate_deploy_app_script(${deploy_args}) + else() + message(WARNING + "Qt runtime deployment requested for '${TARGET}', but this Qt version " + "does not provide qt_generate_deploy_app_script()." + ) + return() + endif() + + install(SCRIPT ${deploy_script}) +endfunction() + # Get a list of all OPTION flags from the CMakeLists.txt and store in an output LIST function(get_all_option_flags output_list) # Read the contents of the CMakeLists.txt diff --git a/src/ifcviewer-full/CMakeLists.txt b/src/ifcviewer-full/CMakeLists.txt index f578d96f70..ebe0a9b772 100644 --- a/src/ifcviewer-full/CMakeLists.txt +++ b/src/ifcviewer-full/CMakeLists.txt @@ -34,3 +34,4 @@ set_target_properties(IfcViewerFull PROPERTIES target_link_libraries(IfcViewerFull PRIVATE IfcViewer) install(TARGETS IfcViewerFull EXPORT ${IFCOPENSHELL_EXPORT_TARGETS}) +ifcopenshell_deploy_qt_runtime(IfcViewerFull) diff --git a/src/ifcviewer-minimal/CMakeLists.txt b/src/ifcviewer-minimal/CMakeLists.txt index dda8743f13..6efcebb965 100644 --- a/src/ifcviewer-minimal/CMakeLists.txt +++ b/src/ifcviewer-minimal/CMakeLists.txt @@ -34,3 +34,4 @@ set_target_properties(IfcViewerMinimal PROPERTIES target_link_libraries(IfcViewerMinimal PRIVATE IfcViewer) install(TARGETS IfcViewerMinimal EXPORT ${IFCOPENSHELL_EXPORT_TARGETS}) +ifcopenshell_deploy_qt_runtime(IfcViewerMinimal) diff --git a/src/qtviewer/CMakeLists.txt b/src/qtviewer/CMakeLists.txt index 0ffed811a7..d1390b382d 100644 --- a/src/qtviewer/CMakeLists.txt +++ b/src/qtviewer/CMakeLists.txt @@ -101,3 +101,4 @@ get_target_property(targetIncludeDirs ${targetName} INCLUDE_DIRECTORIES) message(STATUS "target_include_directories: ${targetIncludeDirs}") install(TARGETS ${targetName}) +ifcopenshell_deploy_qt_runtime(${targetName})