From 9e908fc57a2babb5b81ec139eca8bfbd04c966a1 Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Fri, 21 May 2021 10:22:04 +0200 Subject: [PATCH] Enable UNICODE for all Qt targets and Qt consumers by default After discussion we decided to opt-out the UNICODE definintion behavior. To disable UNICODE in user projects the qt6_disable_unicode_defines function could be used. Amends 5b64e5950cf984abb7d47e0802bcb4b5a21e06fa [ChangeLog][CMake] Enables the UNICODE and _UNICODE definitions on WIN32 platforms by default for all cmake projects to reflect the qmake behavior. Use qt6_disable_unicode_defines function to disable the default unicode definitions. Fixes: QTBUG-93895 Change-Id: Id70ff7dcf8c74f660ec851f8b950e1e3b94d9fb4 Reviewed-by: Alexandru Croitor (cherry picked from commit 715041b663ababa8b36f90978d20bdcdd80e3117) Reviewed-by: Joerg Bornemann --- cmake/QtFlagHandlingHelpers.cmake | 9 +++++++++ cmake/QtInternalTargets.cmake | 13 +++++-------- cmake/QtPublicTargetsHelpers.cmake | 2 ++ src/corelib/Qt6CoreMacros.cmake | 11 +++++++++++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/cmake/QtFlagHandlingHelpers.cmake b/cmake/QtFlagHandlingHelpers.cmake index 9af05d5907d..4e9d71d6cf9 100644 --- a/cmake/QtFlagHandlingHelpers.cmake +++ b/cmake/QtFlagHandlingHelpers.cmake @@ -260,6 +260,15 @@ function(qt_enable_utf8_sources target) endif() endfunction() +function(qt_internal_enable_unicode_defines) + if(WIN32) + set(no_unicode_condition + "$>>") + target_compile_definitions(Platform + INTERFACE "$<${no_unicode_condition}:UNICODE;_UNICODE>") + endif() +endfunction() + # Saves the list of known optimization flags for the current compiler in out_var. # # Mostly used for removing them before adding new ones. diff --git a/cmake/QtInternalTargets.cmake b/cmake/QtInternalTargets.cmake index b1895ddb3ec..7e934f6ac82 100644 --- a/cmake/QtInternalTargets.cmake +++ b/cmake/QtInternalTargets.cmake @@ -147,14 +147,11 @@ elseif(UIKIT) target_compile_definitions(PlatformCommonInternal INTERFACE GLES_SILENCE_DEPRECATION) endif() -if(WIN32) - target_compile_definitions(PlatformCommonInternal INTERFACE "UNICODE;_UNICODE") - if(MSVC) - target_compile_definitions(PlatformCommonInternal INTERFACE - "_CRT_SECURE_NO_WARNINGS" - "$<$,SHARED_LIBRARY>:_WINDLL>" - ) - endif() +if(MSVC) + target_compile_definitions(PlatformCommonInternal INTERFACE + "_CRT_SECURE_NO_WARNINGS" + "$<$,SHARED_LIBRARY>:_WINDLL>" + ) endif() if(UIKIT) diff --git a/cmake/QtPublicTargetsHelpers.cmake b/cmake/QtPublicTargetsHelpers.cmake index 0a414f379ac..39ba11b2609 100644 --- a/cmake/QtPublicTargetsHelpers.cmake +++ b/cmake/QtPublicTargetsHelpers.cmake @@ -30,4 +30,6 @@ function(qt_internal_setup_public_platform_target) # By default enable utf8 sources for both Qt and Qt consumers. Can be opted out. qt_enable_utf8_sources(Platform) + # By default enable unicode on WIN32 platforms for both Qt and Qt consumers. Can be opted out. + qt_internal_enable_unicode_defines(Platform) endfunction() diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index c5d8c928da7..7c43efff554 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -1785,3 +1785,14 @@ properties of both types." ) endforeach() endfunction() + +# Disables the default unicode definitions for the target +function(qt6_disable_unicode_defines target) + set_target_properties(${target} PROPERTIES QT_NO_UNICODE_DEFINES TRUE) +endfunction() + +if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) + function(qt_disable_unicode_defines) + qt6_disable_unicode_defines(${ARGV}) + endfunction() +endif()