summaryrefslogtreecommitdiffstats
path: root/cmake/QtInstallHelpers.cmake
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2021-02-26 11:04:00 +0100
committerJoerg Bornemann <joerg.bornemann@qt.io>2021-03-25 16:31:39 +0100
commit9f444ce5335d0e7a0978879d9441975de549e20b (patch)
treeaa8d8b3180127aafca638621f4b8ead4c6b121ca /cmake/QtInstallHelpers.cmake
parent9145650302d3cfe7df0fbc2a11f5d8f5f867897d (diff)
Add a way to install versioned hard-links for tools
Add the option argument INSTALL_VERSIONED_LINK to qt_internal_add_tool and qt_internal_add_app. For tools/apps with this argument we create an install rule that creates a versioned hard link. For example, for bin/qmake we create bin/qmake6. Note that this only applies to prefix builds. Apply this argument to qmake. The qt_internal_add_app change is necessary for qtdiag and in qttools. Task-number: QTBUG-89170 Change-Id: Id32d6055544c475166f4d854aaeb6292fbb5fbb5 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> (cherry picked from commit c19d957f45fa27f61b5ecc566f8dbc19f12a44c3)
Diffstat (limited to 'cmake/QtInstallHelpers.cmake')
-rw-r--r--cmake/QtInstallHelpers.cmake30
1 files changed, 30 insertions, 0 deletions
diff --git a/cmake/QtInstallHelpers.cmake b/cmake/QtInstallHelpers.cmake
index 5832df144c..1f1fb84634 100644
--- a/cmake/QtInstallHelpers.cmake
+++ b/cmake/QtInstallHelpers.cmake
@@ -125,3 +125,33 @@ function(qt_set_up_nonprefix_build)
qt_remove_install_target()
endif()
endfunction()
+
+# Create a versioned hard-link for the given target.
+# E.g. "bin/qmake6" -> "bin/qmake".
+# If no hard link can be created, make a copy instead.
+#
+# In a multi-config build, create the link for the main config only.
+function(qt_internal_install_versioned_link install_dir target)
+ if(NOT QT_WILL_INSTALL)
+ return()
+ endif()
+
+ qt_path_join(install_base_file_path "$ENV\{DESTDIR}$\{CMAKE_INSTALL_PREFIX}"
+ "${install_dir}" "$<TARGET_FILE_BASE_NAME:${target}>")
+ set(original "${install_base_file_path}$<TARGET_FILE_SUFFIX:${target}>")
+ set(linkname "${install_base_file_path}${PROJECT_VERSION_MAJOR}$<TARGET_FILE_SUFFIX:${target}>")
+ set(code
+ "message(STATUS \"Creating hard link ${original} -> ${linkname}\")"
+ "file(CREATE_LINK \"${original}\" \"${linkname}\" COPY_ON_ERROR)")
+
+ if(QT_GENERATOR_IS_MULTI_CONFIG)
+ # Wrap the code in a configuration check,
+ # because install(CODE) does not support a CONFIGURATIONS argument.
+ qt_create_case_insensitive_regex(main_config_regex ${QT_MULTI_CONFIG_FIRST_CONFIG})
+ list(PREPEND code "if(\"\${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"${main_config_regex}\")")
+ list(APPEND code "endif()")
+ endif()
+
+ list(JOIN code "\n" code)
+ install(CODE "${code}")
+endfunction()