diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2020-04-17 17:12:40 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2020-04-23 10:09:15 +0200 |
commit | 4545eadd3e28be4b04537cc71a8697da4421d918 (patch) | |
tree | 7784381372b51e27da11f25ee34ccfb34e297096 | |
parent | 1c7950081f926475bbdaa18379c2f51f99fcb3bb (diff) |
CMake: Port the 'static_runtime' feature
This feature is Windows-only and must be turned on manually.
For MSVC it sets the MSVC_RUNTIME_LIBRARY target property.
For MinGW it adds the -static linker flag.
Change-Id: I9da3b88d545b34bc34a3a80301b2dd1b5986fa88
Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r-- | cmake/QtBuild.cmake | 24 | ||||
-rw-r--r-- | configure.cmake | 8 | ||||
-rwxr-xr-x | util/cmake/configurejson2cmake.py | 1 |
3 files changed, 32 insertions, 1 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index 11f00e5222..b3eafd8d9e 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -1830,6 +1830,19 @@ endfunction() variable_watch(CMAKE_CURRENT_LIST_DIR qt_watch_current_list_dir) +# Set target properties that are the same for all modules, plugins, executables +# and 3rdparty libraries. +function(qt_set_common_target_properties target) + if(FEATURE_static_runtime) + if(MSVC) + set_property(TARGET ${target} PROPERTY + MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") + elseif(MINGW) + target_link_options(${target} INTERFACE "LINKER:-static") + endif() + endif() +endfunction() + # This is the main entry function for creating a Qt module, that typically # consists of a library, public header files, private header files and configurable # features. @@ -1870,6 +1883,10 @@ function(qt_add_module target) add_library("${target}" STATIC) endif() + if(NOT is_interface_lib) + qt_set_common_target_properties(${target}) + endif() + set(is_framework 0) if(QT_FEATURE_framework AND NOT ${arg_HEADER_MODULE} AND NOT ${arg_STATIC}) set(is_framework 1) @@ -2739,6 +2756,8 @@ function(qt_internal_add_plugin target) endif() endif() + qt_set_common_target_properties(${target}) + # Make sure the Qt6 plugin library names are like they were in Qt5 qmake land. # Whereas the Qt6 CMake target names are like the Qt5 CMake target names. set(output_name "${target}") @@ -3039,6 +3058,7 @@ function(qt_add_executable name) qt6_generate_win32_rc_file(${name}) endif() + qt_set_common_target_properties(${name}) qt_autogen_tools_initial_setup(${name}) qt_skip_warnings_are_errors_when_repo_unclean("${name}") @@ -3522,6 +3542,10 @@ function(qt_add_3rdparty_library target) add_library("${target}") endif() + if(NOT arg_INTERFACE) + qt_set_common_target_properties(${target}) + endif() + if (NOT arg_ARCHIVE_INSTALL_DIRECTORY AND arg_INSTALL_DIRECTORY) set(arg_ARCHIVE_INSTALL_DIRECTORY "${arg_INSTALL_DIRECTORY}") endif() diff --git a/configure.cmake b/configure.cmake index ddb28060b6..d262882bb5 100644 --- a/configure.cmake +++ b/configure.cmake @@ -794,6 +794,14 @@ qt_feature("ccache" CONDITION QT_USE_CCACHE ) qt_feature_config("ccache" QMAKE_PRIVATE_CONFIG) +qt_feature("static_runtime" + LABEL "Statically link the C/C++ runtime library" + AUTODETECT OFF + CONDITION NOT QT_FEATURE_shared + EMIT_IF WIN32 +) +qt_feature_config("static_runtime" QMAKE_PUBLIC_CONFIG) +qt_feature_config("static_runtime" QMAKE_PUBLIC_QT_CONFIG) qt_feature("dlopen" PRIVATE LABEL "dlopen()" CONDITION UNIX diff --git a/util/cmake/configurejson2cmake.py b/util/cmake/configurejson2cmake.py index 91ef573b3e..d85cd7e4f2 100755 --- a/util/cmake/configurejson2cmake.py +++ b/util/cmake/configurejson2cmake.py @@ -907,7 +907,6 @@ def get_feature_mapping(): }, "silent": None, "sql-sqlite": {"condition": "QT_FEATURE_datestring"}, - "static_runtime": None, "stl": None, # Do we really need to test for this in 2018?! "strip": None, "sun-libiconv": { |