From 585dd9d8d542c85a36cc36bd7420e83b722ad744 Mon Sep 17 00:00:00 2001 From: Amir Masoud Abdol Date: Fri, 19 May 2023 10:11:23 +0200 Subject: [PATCH] Add NOMINMAX to PlatformCommonInternal By not explicitly disabling min/max macros of `windows.h`, we may see some unintended substitutions. This is especially important now that we are moving toward enabling Unity Build, and some of the constructs for manually dealing with this issue, eg., `#ifdef max`, `#undef max`, might not make it to the pool, and as a result we get build failure. Pick-to: 6.5 Change-Id: Ie3c31aebe00300126a2ac3a6044876ab92d5d99c Reviewed-by: Joerg Bornemann --- cmake/QtHeadersClean.cmake | 4 ++++ cmake/QtInternalTargets.cmake | 2 ++ 2 files changed, 6 insertions(+) diff --git a/cmake/QtHeadersClean.cmake b/cmake/QtHeadersClean.cmake index 2570f67b26..98e3d0fa47 100644 --- a/cmake/QtHeadersClean.cmake +++ b/cmake/QtHeadersClean.cmake @@ -184,6 +184,9 @@ function(qt_internal_add_headersclean_target module_target module_headers) elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") set(hcleanFLAGS -std:c++latest -Zc:__cplusplus -Za -WX -W3 -EHsc) + # Because we now add `-DNOMINMAX` to `PlatformCommonInternal`. + set(hcleanUDEFS -UNOMINMAX) + # cl.exe needs a source path get_filename_component(source_path "${QT_MKSPECS_DIR}/features/data/dummy.cpp" REALPATH) @@ -194,6 +197,7 @@ function(qt_internal_add_headersclean_target module_target module_headers) "${hcleanFLAGS}" "${target_includes_joined_genex}" "${hcleanDEFS}" + "${hcleanUDEFS}" ) string(JOIN " " compiler_command_line_variables "-FI" diff --git a/cmake/QtInternalTargets.cmake b/cmake/QtInternalTargets.cmake index b5ebc3ef0a..bc515ed56b 100644 --- a/cmake/QtInternalTargets.cmake +++ b/cmake/QtInternalTargets.cmake @@ -170,6 +170,8 @@ if(WIN32) # Needed for M_PI define. Same as mkspecs/features/qt_module.prf. # It's set for every module being built, but it's not propagated to user apps. target_compile_definitions(PlatformModuleInternal INTERFACE _USE_MATH_DEFINES) + # Not disabling min/max macros may result in unintended substitutions of std::min/max + target_compile_definitions(PlatformCommonInternal INTERFACE NOMINMAX) endif() if(FEATURE_largefile AND UNIX) target_compile_definitions(PlatformCommonInternal