summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmake/QtBaseGlobalTargets.cmake2
-rw-r--r--cmake/QtBuild.cmake8
-rw-r--r--cmake/QtFeature.cmake12
-rw-r--r--qmake/CMakeLists.txt3
-rw-r--r--src/tools/bootstrap/CMakeLists.txt4
5 files changed, 28 insertions, 1 deletions
diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake
index fb27618499..182d2986f0 100644
--- a/cmake/QtBaseGlobalTargets.cmake
+++ b/cmake/QtBaseGlobalTargets.cmake
@@ -17,6 +17,8 @@ if (ANDROID)
target_link_libraries(Platform INTERFACE log)
endif()
+qt_enable_msvc_cplusplus_define(Platform INTERFACE)
+
set(__GlobalConfig_path_suffix "${INSTALL_CMAKE_NAMESPACE}")
qt_path_join(__GlobalConfig_build_dir ${QT_CONFIG_BUILD_DIR} ${__GlobalConfig_path_suffix})
qt_path_join(__GlobalConfig_install_dir ${QT_CONFIG_INSTALL_DIR} ${__GlobalConfig_path_suffix})
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake
index 4456ea99f1..81573381c4 100644
--- a/cmake/QtBuild.cmake
+++ b/cmake/QtBuild.cmake
@@ -4016,6 +4016,14 @@ function(qt_set_language_standards)
endif()
endfunction()
+function(qt_enable_msvc_cplusplus_define target visibility)
+ # For MSVC we need to explicitly pass -Zc:__cplusplus to get correct __cplusplus.
+ # Check qt_config_compile_test for more info.
+ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER_EQUAL 1913)
+ target_compile_options("${target}" ${visibility} "-Zc:__cplusplus")
+ endif()
+endfunction()
+
# Compatibility macros that should be removed once all their usages are removed.
function(extend_target)
qt_extend_target(${ARGV})
diff --git a/cmake/QtFeature.cmake b/cmake/QtFeature.cmake
index faca42635c..db12c9f0bb 100644
--- a/cmake/QtFeature.cmake
+++ b/cmake/QtFeature.cmake
@@ -635,6 +635,7 @@ function(qt_config_compile_test name)
if(NOT DEFINED HAVE_${name})
set(_save_CMAKE_C_STANDARD "${CMAKE_C_STANDARD}")
set(_save_CMAKE_CXX_STANDARD "${CMAKE_CXX_STANDARD}")
+ set(_save_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
if(arg_C_STANDARD)
set(CMAKE_C_STANDARD "${arg_C_STANDARD}")
@@ -644,6 +645,16 @@ function(qt_config_compile_test name)
set(CMAKE_CXX_STANDARD "${arg_CXX_STANDARD}")
endif()
+ # For MSVC we need to explicitly pass -Zc:__cplusplus to get correct __cplusplus
+ # define values. According to common/msvc-version.conf the flag is supported starting
+ # with 1913.
+ # https://developercommunity.visualstudio.com/content/problem/139261/msvc-incorrectly-defines-cplusplus.html
+ # No support for the flag in upstream CMake as of 3.17.
+ # https://gitlab.kitware.com/cmake/cmake/issues/18837
+ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER_EQUAL 1913)
+ set(CMAKE_REQUIRED_FLAGS "-Zc:__cplusplus")
+ endif()
+
set(_save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
set(CMAKE_REQUIRED_LIBRARIES "${arg_LIBRARIES}")
check_cxx_source_compiles("${arg_UNPARSED_ARGUMENTS} ${arg_CODE}" HAVE_${name})
@@ -651,6 +662,7 @@ function(qt_config_compile_test name)
set(CMAKE_C_STANDARD "${_save_CMAKE_C_STANDARD}")
set(CMAKE_CXX_STANDARD "${_save_CMAKE_CXX_STANDARD}")
+ set(CMAKE_REQUIRED_FLAGS "${_save_CMAKE_REQUIRED_FLAGS}")
endif()
endif()
diff --git a/qmake/CMakeLists.txt b/qmake/CMakeLists.txt
index ff50f507c5..fb370eda4a 100644
--- a/qmake/CMakeLists.txt
+++ b/qmake/CMakeLists.txt
@@ -215,3 +215,6 @@ set_target_properties(qmake PROPERTIES
)
qt_internal_add_link_flags_gc_sections(qmake PRIVATE) # special case
+
+qt_enable_msvc_cplusplus_define(qmake PUBLIC) # special case
+
diff --git a/src/tools/bootstrap/CMakeLists.txt b/src/tools/bootstrap/CMakeLists.txt
index 2121faae12..88b2c94038 100644
--- a/src/tools/bootstrap/CMakeLists.txt
+++ b/src/tools/bootstrap/CMakeLists.txt
@@ -223,7 +223,9 @@ qt_extend_target(Bootstrap CONDITION WIN32 AND mingw
uuid
)
-# special case:
+# special case begin
qt_internal_add_link_flags_gc_sections(Bootstrap PUBLIC)
set_target_properties(Bootstrap PROPERTIES AUTOMOC OFF AUTOUIC OFF AUTORCC OFF)
qt_internal_add_target_aliases(Bootstrap)
+qt_enable_msvc_cplusplus_define(Bootstrap PUBLIC)
+# special case end