From d3489bdb0bc58b36f1e5ff2baa0aee8f4daea734 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 19 Jan 2015 15:49:06 -0500 Subject: Features: Record for MSVC 2010-2015 Also, in WCDH add MSVC Compatibility for cxx_align{of,as}. Co-Author: Stephen Kelly Co-Author: Brad King --- Help/release/dev/feature-record-msvc.rst | 5 + Modules/Compiler/MSVC-CXX-FeatureTests.cmake | 106 +++++++++++++++++++++ Modules/Compiler/MSVC-CXX.cmake | 6 ++ Modules/WriteCompilerDetectionHeader.cmake | 9 +- Tests/CompileFeatures/CMakeLists.txt | 48 ++++++++++ .../WriteCompilerDetectionHeader/CMakeLists.txt | 15 ++- 6 files changed, 185 insertions(+), 4 deletions(-) create mode 100644 Help/release/dev/feature-record-msvc.rst create mode 100644 Modules/Compiler/MSVC-CXX-FeatureTests.cmake create mode 100644 Modules/Compiler/MSVC-CXX.cmake diff --git a/Help/release/dev/feature-record-msvc.rst b/Help/release/dev/feature-record-msvc.rst new file mode 100644 index 0000000..a8c9fd1 --- /dev/null +++ b/Help/release/dev/feature-record-msvc.rst @@ -0,0 +1,5 @@ +feature-record-msvc +------------------- + +* The :manual:`Compile Features ` functionality + is now aware of features supported by Microsoft Visual Studio (``MSVC``). diff --git a/Modules/Compiler/MSVC-CXX-FeatureTests.cmake b/Modules/Compiler/MSVC-CXX-FeatureTests.cmake new file mode 100644 index 0000000..c770211 --- /dev/null +++ b/Modules/Compiler/MSVC-CXX-FeatureTests.cmake @@ -0,0 +1,106 @@ + +# Reference: http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx +# http://blogs.msdn.com/b/vcblog/archive/2013/06/28/c-11-14-stl-features-fixes-and-breaking-changes-in-vs-2013.aspx +# http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx +# http://www.visualstudio.com/en-us/news/vs2015-preview-vs.aspx + + +set(_cmake_oldestSupported "_MSC_VER >= 1600") + +set(MSVC_2015 "_MSC_VER >= 1900") +set(_cmake_feature_test_cxx_alignas "${MSVC_2015}") +set(_cmake_feature_test_cxx_alignof "${MSVC_2015}") +set(_cmake_feature_test_cxx_binary_literals "${MSVC_2015}") +set(_cmake_feature_test_cxx_decltype_auto "${MSVC_2015}") +# Digit separators are not available as of VS 2015 Preview, but a footnote +# says they will be available in the RTM. +set(_cmake_feature_test_cxx_digit_separators "${MSVC_2015}") +set(_cmake_feature_test_cxx_func_identifier "${MSVC_2015}") +# http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx +# Note 1. While previous version of VisualStudio said they supported these +# they silently produced bad code, and are now marked as having partial +# support in previous versions. The footnote says the support will be complete +# in MSVC 2015, so support the feature for that version, assuming that is true. +set(_cmake_feature_test_cxx_generalized_initializers "${MSVC_2015}") +set(_cmake_feature_test_cxx_nonstatic_member_init "${MSVC_2015}") +# Microsoft calls this 'rvalue references v3' +set(_cmake_feature_test_cxx_defaulted_move_initializers "${MSVC_2015}") +set(_cmake_feature_test_cxx_generic_lambdas "${MSVC_2015}") +set(_cmake_feature_test_cxx_inheriting_constructors "${MSVC_2015}") +set(_cmake_feature_test_cxx_inline_namespaces "${MSVC_2015}") +set(_cmake_feature_test_cxx_lambda_init_captures "${MSVC_2015}") +set(_cmake_feature_test_cxx_noexcept "${MSVC_2015}") +set(_cmake_feature_test_cxx_return_type_deduction "${MSVC_2015}") +set(_cmake_feature_test_cxx_sizeof_member "${MSVC_2015}") +set(_cmake_feature_test_cxx_thread_local "${MSVC_2015}") +set(_cmake_feature_test_cxx_unicode_literals "${MSVC_2015}") +set(_cmake_feature_test_cxx_unrestricted_unions "${MSVC_2015}") +set(_cmake_feature_test_cxx_user_literals "${MSVC_2015}") +set(_cmake_feature_test_cxx_reference_qualified_functions "${MSVC_2015}") +# "The copies and moves don't interact precisely like the Standard says they +# should. For example, deletion of moves is specified to also suppress +# copies, but Visual C++ in Visual Studio 2013 does not." +# http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx +# lists this as 'partial' in 2013 +set(_cmake_feature_test_cxx_deleted_functions "${MSVC_2015}") + +set(MSVC_2013 "_MSC_VER >= 1800") +set(_cmake_feature_test_cxx_alias_templates "${MSVC_2013}") +# Microsoft now states they support contextual conversions in 2013 and above. +# See footnote 6 at: +# http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx +set(_cmake_feature_test_cxx_contextual_conversions "${MSVC_2013}") +set(_cmake_feature_test_cxx_default_function_template_args "${MSVC_2013}") +set(_cmake_feature_test_cxx_defaulted_functions "${MSVC_2013}") +set(_cmake_feature_test_cxx_delegating_constructors "${MSVC_2013}") +set(_cmake_feature_test_cxx_explicit_conversions "${MSVC_2013}") +set(_cmake_feature_test_cxx_raw_string_literals "${MSVC_2013}") +set(_cmake_feature_test_cxx_uniform_initialization "${MSVC_2013}") +# Support is documented, but possibly partly broken: +# https://msdn.microsoft.com/en-us/library/hh567368.aspx +# http://thread.gmane.org/gmane.comp.lib.boost.devel/244986/focus=245333 +set(_cmake_feature_test_cxx_variadic_templates "${MSVC_2013}") + +set(MSVC_2012 "_MSC_VER >= 1700") +set(_cmake_feature_test_cxx_enum_forward_declarations "${MSVC_2012}") +set(_cmake_feature_test_cxx_final "${MSVC_2012}") +set(_cmake_feature_test_cxx_range_for "${MSVC_2012}") +set(_cmake_feature_test_cxx_strong_enums "${MSVC_2012}") + +set(MSVC_2010 "_MSC_VER >= 1600") +set(_cmake_feature_test_cxx_auto_type "${MSVC_2010}") +set(_cmake_feature_test_cxx_decltype "${MSVC_2010}") +set(_cmake_feature_test_cxx_extended_friend_declarations "${MSVC_2010}") +set(_cmake_feature_test_cxx_extern_templates "${MSVC_2010}") +set(_cmake_feature_test_cxx_lambdas "${MSVC_2010}") +set(_cmake_feature_test_cxx_local_type_template_args "${MSVC_2010}") +set(_cmake_feature_test_cxx_long_long_type "${MSVC_2010}") +set(_cmake_feature_test_cxx_nullptr "${MSVC_2010}") +set(_cmake_feature_test_cxx_override "${MSVC_2010}") +set(_cmake_feature_test_cxx_right_angle_brackets "${MSVC_2010}") +set(_cmake_feature_test_cxx_rvalue_references "${MSVC_2010}") +set(_cmake_feature_test_cxx_static_assert "${MSVC_2010}") +set(_cmake_feature_test_cxx_template_template_parameters "${MSVC_2010}") +set(_cmake_feature_test_cxx_trailing_return_types "${MSVC_2010}") +set(_cmake_feature_test_cxx_variadic_macros "${MSVC_2010}") + +# Currently unsupported: +# set(_cmake_feature_test_cxx_constexpr ) +# set(_cmake_feature_test_cxx_relaxed_constexpr ) +# set(_cmake_feature_test_cxx_attributes ) +# set(_cmake_feature_test_cxx_attribute_deprecated ) +# 'NSDMIs for aggregates' +# set(_cmake_feature_test_cxx_aggregate_default_initializers ) +# set(_cmake_feature_test_cxx_variable_templates ) + +# In theory decltype incomplete return types was added in 2012 +# but without support for decltype_auto and return type deduction this +# feature is unusable. This remains so as of VS 2015 Preview. +# set(_cmake_feature_test_cxx_decltype_incomplete_return_types ) + +# Unset all the variables that we don't need exposed. +# _cmake_oldestSupported is required by WriteCompilerDetectionHeader +set(MSVC_2015) +set(MSVC_2013) +set(MSVC_2012) +set(MSVC_2010) diff --git a/Modules/Compiler/MSVC-CXX.cmake b/Modules/Compiler/MSVC-CXX.cmake new file mode 100644 index 0000000..962aaeb --- /dev/null +++ b/Modules/Compiler/MSVC-CXX.cmake @@ -0,0 +1,6 @@ +# MSVC has no specific language level or flags to change it. +set(CMAKE_CXX_STANDARD_DEFAULT "") + +macro(cmake_record_cxx_compile_features) + record_compiler_features(CXX "" CMAKE_CXX_COMPILE_FEATURES) +endmacro() diff --git a/Modules/WriteCompilerDetectionHeader.cmake b/Modules/WriteCompilerDetectionHeader.cmake index e81bc08..d18f47c 100644 --- a/Modules/WriteCompilerDetectionHeader.cmake +++ b/Modules/WriteCompilerDetectionHeader.cmake @@ -36,7 +36,7 @@ # PREFIX ClimbingStats # OUTPUT_FILES_VAR support_files # OUTPUT_DIR compilers -# COMPILERS GNU Clang +# COMPILERS GNU Clang MSVC # FEATURES cxx_variadic_templates # ) # install(FILES @@ -100,7 +100,7 @@ # write_compiler_detection_header( # FILE climbingstats_compiler_detection.h # PREFIX ClimbingStats -# COMPILERS GNU Clang AppleClang +# COMPILERS GNU Clang AppleClang MSVC # FEATURES cxx_variadic_templates # ) # @@ -321,6 +321,7 @@ function(write_compiler_detection_header GNU Clang AppleClang + MSVC SunPro ) @@ -528,6 +529,8 @@ function(write_compiler_detection_header # define ${def_value} alignas(X) # elif ${prefix_arg}_COMPILER_IS_GNU || ${prefix_arg}_COMPILER_IS_Clang || ${prefix_arg}_COMPILER_IS_AppleClang # define ${def_value} __attribute__ ((__aligned__(X))) +# elif ${prefix_arg}_COMPILER_IS_MSVC +# define ${def_value} __declspec(align(X)) # else # define ${def_value} # endif @@ -540,6 +543,8 @@ function(write_compiler_detection_header # define ${def_value} alignof(X) # elif ${prefix_arg}_COMPILER_IS_GNU || ${prefix_arg}_COMPILER_IS_Clang || ${prefix_arg}_COMPILER_IS_AppleClang # define ${def_value} __alignof__(X) +# elif ${prefix_arg}_COMPILER_IS_MSVC +# define ${def_value} __alignof(X) # endif \n") endif() diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt index 9ef8049..38c44c8 100644 --- a/Tests/CompileFeatures/CMakeLists.txt +++ b/Tests/CompileFeatures/CMakeLists.txt @@ -100,6 +100,31 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" ) endif() +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0) + list(REMOVE_ITEM CXX_non_features + # The cxx_contextual_conversions feature happens to work + # (for *this* testcase) with VS 2010 and VS 2012, but + # they do not document support until VS 2013. + cxx_contextual_conversions + ) + elseif (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0) + list(REMOVE_ITEM CXX_non_features + # The cxx_deleted_functions and cxx_nonstatic_member_init + # features happen to work (for *this* testcase) with VS 2013, + # but they do not document support until VS 2015. + cxx_deleted_functions + cxx_nonstatic_member_init + ) + else() + list(REMOVE_ITEM CXX_non_features + # The cxx_constexpr feature happens to work (for *this* testcase) + # with VS 2015, but they document only partial support. + cxx_constexpr + ) + endif() +endif() + set(C_ext c) set(C_standard_flag 11) set(CXX_ext cpp) @@ -220,6 +245,29 @@ if (CMAKE_CXX_COMPILE_FEATURES) -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=0 ) endif() + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0) + add_definitions( + -DEXPECT_OVERRIDE_CONTROL=1 + -DEXPECT_INHERITING_CONSTRUCTORS=1 + -DEXPECT_FINAL=1 + -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=1 + ) + elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17.0) + add_definitions( + -DEXPECT_OVERRIDE_CONTROL=1 + -DEXPECT_INHERITING_CONSTRUCTORS=0 + -DEXPECT_FINAL=1 + -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=0 + ) + else() + add_definitions( + -DEXPECT_OVERRIDE_CONTROL=0 + -DEXPECT_INHERITING_CONSTRUCTORS=0 + -DEXPECT_FINAL=0 + -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=0 + ) + endif() elseif (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro") add_definitions( -DEXPECT_OVERRIDE_CONTROL=1 diff --git a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt index 78c4a6a..e70a977 100644 --- a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt +++ b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt @@ -11,7 +11,7 @@ get_property(c_known_features GLOBAL PROPERTY CMAKE_C_KNOWN_FEATURES) write_compiler_detection_header( FILE "${CMAKE_CURRENT_BINARY_DIR}/test_compiler_detection.h" PREFIX TEST - COMPILERS GNU Clang AppleClang SunPro + COMPILERS GNU Clang AppleClang MSVC SunPro VERSION 3.1 PROLOG "// something" EPILOG "// more" @@ -67,6 +67,17 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" list(APPEND false_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES) endif() +# for msvc the compiler version determines which c++11 features are available. +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + if(";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_delegating_constructors;") + list(APPEND true_defs EXPECTED_COMPILER_CXX_DELEGATING_CONSTRUCTORS) + list(APPEND true_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES) + else() + list(APPEND false_defs EXPECTED_COMPILER_CXX_DELEGATING_CONSTRUCTORS) + list(APPEND false_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES) + endif() +endif() + if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang") @@ -84,7 +95,7 @@ write_compiler_detection_header( PREFIX MULTI OUTPUT_FILES_VAR multi_files OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/compiler_multi_files/compiler_support" - COMPILERS GNU Clang AppleClang SunPro + COMPILERS GNU Clang AppleClang MSVC SunPro VERSION 3.1 FEATURES ${cxx_known_features} ${c_known_features} -- cgit v0.12