CMake: Fix c++ standard config tests with MSVC
Need to pass additional -Zc:__cplusplus flag when using MSVC, so that the __cplusplus define has correct values. Additionally make the option be propagated to consumers of Qt via the public Platform target, which QtCore links against. Change-Id: Ie1283c25334b93f993529beb7fb32bdb001627f5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
This commit is contained in:
parent
00eeed234f
commit
eaa29378b9
@ -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})
|
||||
|
@ -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})
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user