From 7f401ae43fafed8258659f2da204bc818fd693d3 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 15 Apr 2016 16:06:41 -0400 Subject: [PATCH 1/7] Features: Detect C default dialect on MSVC-like compilers These compilers default to C 90 but do not define __STDC__. While MSVC itself has no option to change the dialect, compilers that document compatibility with MSVC and define _MSC_VER may (e.g. Intel). --- Modules/CMakeCCompilerId.c.in | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Modules/CMakeCCompilerId.c.in b/Modules/CMakeCCompilerId.c.in index c107dfdf5..95184c982 100644 --- a/Modules/CMakeCCompilerId.c.in +++ b/Modules/CMakeCCompilerId.c.in @@ -34,7 +34,11 @@ char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]"; @CMAKE_C_COMPILER_ID_ERROR_FOR_TEST@ #if !defined(__STDC__) -# define C_DIALECT +# if defined(_MSC_VER) && !defined(__clang__) +# define C_DIALECT "90" +# else +# define C_DIALECT +# endif #elif __STDC_VERSION__ >= 201000L # define C_DIALECT "11" #elif __STDC_VERSION__ >= 199901L From be910f00b580addcf60f33c6f6c0625dba505ef8 Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Mon, 16 Nov 2015 09:19:30 -0700 Subject: [PATCH 2/7] Features: Record standards and features for Intel C++ on UNIX Skip this for now on Windows (where Intel C++ simulates MSVC). --- Modules/Compiler/Intel-CXX-FeatureTests.cmake | 100 ++++++++++++++++++ Modules/Compiler/Intel-CXX.cmake | 58 ++++++++++ Tests/CompileFeatures/CMakeLists.txt | 72 +++++++++++++ 3 files changed, 230 insertions(+) create mode 100644 Modules/Compiler/Intel-CXX-FeatureTests.cmake diff --git a/Modules/Compiler/Intel-CXX-FeatureTests.cmake b/Modules/Compiler/Intel-CXX-FeatureTests.cmake new file mode 100644 index 000000000..d328e3c36 --- /dev/null +++ b/Modules/Compiler/Intel-CXX-FeatureTests.cmake @@ -0,0 +1,100 @@ +# References: +# - https://software.intel.com/en-us/articles/c0x-features-supported-by-intel-c-compiler +# - https://software.intel.com/en-us/articles/c14-features-supported-by-intel-c-compiler + +# FIXME: Intel C++ feature detection works only when simulating the GNU compiler. +# When simulating MSVC, Intel always sets __cplusplus to 199711L. +if("x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") + return() +endif() + +# these are not implemented in any version at time of writing +#set(_cmake_feature_test_cxx_variable_templates "${Intel15_CXX14}") +#set(_cmake_feature_test_cxx_relaxed_constexpr "${Intel15_CXX14}") + +set(_cmake_oldestSupported "__INTEL_COMPILER >= 1110") +set(DETECT_CXX11 "((__cplusplus >= 201103L) || defined(__INTEL_CXX11_MODE__) || defined(__GXX_EXPERIMENTAL_CXX0X__))") +#ICC version 15 update 1 has a bug where __cplusplus is defined as 1 no matter +#if you are compiling as 98/11/14. So to properly detect C++14 with this version +#we look for the existence of __GXX_EXPERIMENTAL_CXX0X__ but not __INTEL_CXX11_MODE__ +set(DETECT_BUGGY_ICC15 "((__INTEL_COMPILER == 1500) && (__INTEL_COMPILER_UPDATE == 1))") +set(DETECT_CXX14 "((__cplusplus >= 201300L) || ((__cplusplus == 201103L) && !defined(__INTEL_CXX11_MODE__)) || ((${DETECT_BUGGY_ICC15}) && defined(__GXX_EXPERIMENTAL_CXX0X__) && !defined(__INTEL_CXX11_MODE__) ) )") + +set(Intel16_CXX14 "__INTEL_COMPILER >= 1600 && ${DETECT_CXX14}") +set(_cmake_feature_test_cxx_aggregate_default_initializers "${Intel16_CXX14}") +set(_cmake_feature_test_cxx_contextual_conversions "${Intel16_CXX14}") +set(_cmake_feature_test_cxx_generic_lambdas "${Intel16_CXX14}") +set(_cmake_feature_test_cxx_digit_separators "${Intel16_CXX14}") +# This test is supposed to work in Intel 14 but the compiler has a bug +# in versions 14 and 15:: +# https://software.intel.com/en-us/forums/intel-c-compiler/topic/600514 +# It also appears to fail with an internal compiler error on Intel 16. +#set(_cmake_feature_test_cxx_generalized_initializers "${Intel16_CXX14}") + +set(Intel15_CXX14 "__INTEL_COMPILER >= 1500 && ${DETECT_CXX14}") +set(_cmake_feature_test_cxx_decltype_auto "${Intel15_CXX14}") +set(_cmake_feature_test_cxx_lambda_init_captures "${Intel15_CXX14}") +set(_cmake_feature_test_cxx_attribute_deprecated "${Intel15_CXX14}") +set(_cmake_feature_test_cxx_return_type_deduction "${Intel15_CXX14}") + +set(Intel15_CXX11 "__INTEL_COMPILER >= 1500 && ${DETECT_CXX11}") +set(_cmake_feature_test_cxx_alignas "${Intel15_CXX11}") +set(_cmake_feature_test_cxx_alignof "${Intel15_CXX11}") +set(_cmake_feature_test_cxx_inheriting_constructors "${Intel15_CXX11}") +set(_cmake_feature_test_cxx_user_literals "${Intel15_CXX11}") +set(_cmake_feature_test_cxx_thread_local "${Intel15_CXX11}") + +set(Intel14_CXX11 "${DETECT_CXX11} && (__INTEL_COMPILER > 1400 || (__INTEL_COMPILER == 1400 && __INTEL_COMPILER_UPDATE >= 2))") +# Documented as 12.0+ but in testing it only works on 14.0.2+ +set(_cmake_feature_test_cxx_decltype_incomplete_return_types "${Intel14_CXX11}") + +set(Intel14_CXX11 "__INTEL_COMPILER >= 1400 && ${DETECT_CXX11}") +set(_cmake_feature_test_cxx_delegating_constructors "${Intel14_CXX11}") +set(_cmake_feature_test_cxx_constexpr "${Intel14_CXX11}") +set(_cmake_feature_test_cxx_sizeof_member "${Intel14_CXX11}") +set(_cmake_feature_test_cxx_strong_enums "${Intel14_CXX11}") +set(_cmake_feature_test_cxx_reference_qualified_functions "${Intel14_CXX11}") +set(_cmake_feature_test_cxx_raw_string_literals "${Intel14_CXX11}") +set(_cmake_feature_test_cxx_unicode_literals "${Intel14_CXX11}") +set(_cmake_feature_test_cxx_inline_namespaces "${Intel14_CXX11}") +set(_cmake_feature_test_cxx_unrestricted_unions "${Intel14_CXX11}") +set(_cmake_feature_test_cxx_nonstatic_member_init "${Intel14_CXX11}") +set(_cmake_feature_test_cxx_enum_forward_declarations "${Intel14_CXX11}") +set(_cmake_feature_test_cxx_override "${Intel14_CXX11}") +set(_cmake_feature_test_cxx_final "${Intel14_CXX11}") +set(_cmake_feature_test_cxx_noexcept "${Intel14_CXX11}") +set(_cmake_feature_test_cxx_defaulted_move_initializers "${Intel14_CXX11}") + +set(Intel13_CXX11 "__INTEL_COMPILER >= 1300 && ${DETECT_CXX11}") +set(_cmake_feature_test_cxx_explicit_conversions "${Intel13_CXX11}") +set(_cmake_feature_test_cxx_range_for "${Intel13_CXX11}") +# Cannot find Intel documentation for N2640: cxx_uniform_initialization +set(_cmake_feature_test_cxx_uniform_initialization "${Intel13_CXX11}") + +set(Intel121_CXX11 "__INTEL_COMPILER >= 1210 && ${DETECT_CXX11}") +set(_cmake_feature_test_cxx_variadic_templates "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_alias_templates "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_nullptr "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_trailing_return_types "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_attributes "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_default_function_template_args "${Intel121_CXX11}") + +set(Intel12_CXX11 "__INTEL_COMPILER >= 1200 && ${DETECT_CXX11}") +set(_cmake_feature_test_cxx_extended_friend_declarations "${Intel12_CXX11}") +set(_cmake_feature_test_cxx_rvalue_references "${Intel12_CXX11}") +set(_cmake_feature_test_cxx_decltype "${Intel12_CXX11}") +set(_cmake_feature_test_cxx_defaulted_functions "${Intel12_CXX11}") +set(_cmake_feature_test_cxx_deleted_functions "${Intel12_CXX11}") +set(_cmake_feature_test_cxx_local_type_template_args "${Intel12_CXX11}") +set(_cmake_feature_test_cxx_lambdas "${Intel12_CXX11}") + +set(Intel11_CXX11 "${_cmake_oldestSupported} && ${DETECT_CXX11}") +set(_cmake_feature_test_cxx_binary_literals "${Intel11_CXX11}") +set(_cmake_feature_test_cxx_static_assert "${Intel11_CXX11}") +set(_cmake_feature_test_cxx_right_angle_brackets "${Intel11_CXX11}") +set(_cmake_feature_test_cxx_auto_type "${Intel11_CXX11}") +set(_cmake_feature_test_cxx_extern_templates "${Intel11_CXX11}") +set(_cmake_feature_test_cxx_variadic_macros "${Intel11_CXX11}") +set(_cmake_feature_test_cxx_long_long_type "${Intel11_CXX11}") +set(_cmake_feature_test_cxx_func_identifier "${Intel11_CXX11}") +set(_cmake_feature_test_cxx_template_template_parameters "${Intel11_CXX11}") diff --git a/Modules/Compiler/Intel-CXX.cmake b/Modules/Compiler/Intel-CXX.cmake index 02c636cc4..2785fd356 100644 --- a/Modules/Compiler/Intel-CXX.cmake +++ b/Modules/Compiler/Intel-CXX.cmake @@ -8,5 +8,63 @@ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -DNDEBUG") set(CMAKE_DEPFILE_FLAGS_CXX "-MD -MT -MF ") +if(NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15.0.2) + set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++14") + # todo: there is no gnu++14 value supported; figure out what to do + set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=c++14") + elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15.0.0) + set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++1y") + # todo: there is no gnu++14 value supported; figure out what to do + set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=c++1y") + endif() + + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.0) + set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11") + set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11") + elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.1) + set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++0x") + set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x") + endif() + + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.1) + set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98") + set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98") + endif() +endif() + +if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.1) + if (NOT CMAKE_CXX_COMPILER_FORCED) + if (NOT CMAKE_CXX_STANDARD_COMPUTED_DEFAULT) + message(FATAL_ERROR "CMAKE_CXX_STANDARD_COMPUTED_DEFAULT should be set for ${CMAKE_CXX_COMPILER_ID} (${CMAKE_CXX_COMPILER}) version ${CMAKE_CXX_COMPILER_VERSION}") + else() + set(CMAKE_CXX_STANDARD_DEFAULT ${CMAKE_CXX_STANDARD_COMPUTED_DEFAULT}) + endif() + elseif (NOT CMAKE_CXX_STANDARD_COMPUTED_DEFAULT) + # Compiler id was forced so just guess the default standard level. + set(CMAKE_CXX_STANDARD_DEFAULT 98) + endif() +endif() + +macro(cmake_record_cxx_compile_features) + macro(_get_intel_features std_version list) + record_compiler_features(CXX "${std_version}" ${list}) + endmacro() + + set(_result 0) + if(NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC" AND + NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.1) + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15.0) + _get_intel_features(${CMAKE_CXX14_STANDARD_COMPILE_OPTION} CMAKE_CXX14_COMPILE_FEATURES) + endif() + if (_result EQUAL 0) + _get_intel_features(${CMAKE_CXX11_STANDARD_COMPILE_OPTION} CMAKE_CXX11_COMPILE_FEATURES) + endif() + if (_result EQUAL 0) + _get_intel_features(${CMAKE_CXX98_STANDARD_COMPILE_OPTION} CMAKE_CXX98_COMPILE_FEATURES) + endif() + endif() +endmacro() + set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE " -E > ") set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE " -S -o ") diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt index a32138d71..e6acee883 100644 --- a/Tests/CompileFeatures/CMakeLists.txt +++ b/Tests/CompileFeatures/CMakeLists.txt @@ -119,6 +119,55 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") endif() endif() +if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16.0) + if (CMAKE_CXX_COMIPLER_VERSION VERSION_EQUAL 15.0) + list(REMOVE_ITEM CXX_non_features + # The cxx_contextual_conversions feature happens to work + # (for *this* testcase) with Intel 13/14/15, but they do not + # document support until 16. + cxx_contextual_conversions + ) + + elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14.0) + list(REMOVE_ITEM CXX_non_features + cxx_alignof + + # not supposed to work until 15 + cxx_attribute_deprecated + + # The cxx_contextual_conversions feature happens to work + # (for *this* testcase) with Intel 13/14/15, but they do not + # document support until 16. + cxx_contextual_conversions + ) + + elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.1) + list(REMOVE_ITEM CXX_non_features + # These features happen to work but aren't documented to + # do so until 14.0 + cxx_constexpr + cxx_enum_forward_declarations + cxx_sizeof_member + cxx_strong_enums + cxx_unicode_literals + + # not supposed to work until 15 + cxx_attribute_deprecated + cxx_nonstatic_member_init + + # The cxx_contextual_conversions feature happens to work + # (for *this* testcase) with Intel 13/14/15, but they do not + # document support until 16. + cxx_contextual_conversions + + # This is an undocumented feature; it does not work in future versions + cxx_aggregate_default_initializers + ) + endif() + endif() +endif() + set(C_ext c) set(C_standard_flag 11) set(CXX_ext cpp) @@ -301,6 +350,29 @@ if (CMAKE_CXX_COMPILE_FEATURES) -DEXPECT_FINAL=1 -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=1 ) + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15) + 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 14) + 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() endif() add_executable(CompileFeaturesGenex genex_test.cpp) From d028b948721d7a6042b87e238542a11fea78edb0 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 27 Apr 2016 15:28:33 -0400 Subject: [PATCH 3/7] Features: Specify minimum version Intel C++ 12.1 Versions below 12.1 do not provide enough information to properly detect if compiling with c++98 or c++0x enabled so remove them from the supported list. --- Help/manual/cmake-compile-features.7.rst | 1 + Modules/Compiler/Intel-CXX-FeatureTests.cmake | 40 +++++++++---------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Help/manual/cmake-compile-features.7.rst b/Help/manual/cmake-compile-features.7.rst index caf5bac2a..7289e6165 100644 --- a/Help/manual/cmake-compile-features.7.rst +++ b/Help/manual/cmake-compile-features.7.rst @@ -309,3 +309,4 @@ versions specified for each: * ``GNU``: GNU compiler versions 4.4 through 5.0. * ``MSVC``: Microsoft Visual Studio versions 2010 through 2015. * ``SunPro``: Oracle SolarisStudio version 12.4. +* ``Intel``: Intel compiler versions 12.1 through 16.0 on UNIX platforms. diff --git a/Modules/Compiler/Intel-CXX-FeatureTests.cmake b/Modules/Compiler/Intel-CXX-FeatureTests.cmake index d328e3c36..e111c07c8 100644 --- a/Modules/Compiler/Intel-CXX-FeatureTests.cmake +++ b/Modules/Compiler/Intel-CXX-FeatureTests.cmake @@ -12,7 +12,7 @@ endif() #set(_cmake_feature_test_cxx_variable_templates "${Intel15_CXX14}") #set(_cmake_feature_test_cxx_relaxed_constexpr "${Intel15_CXX14}") -set(_cmake_oldestSupported "__INTEL_COMPILER >= 1110") +set(_cmake_oldestSupported "__INTEL_COMPILER >= 1210") set(DETECT_CXX11 "((__cplusplus >= 201103L) || defined(__INTEL_CXX11_MODE__) || defined(__GXX_EXPERIMENTAL_CXX0X__))") #ICC version 15 update 1 has a bug where __cplusplus is defined as 1 no matter #if you are compiling as 98/11/14. So to properly detect C++14 with this version @@ -71,30 +71,26 @@ set(_cmake_feature_test_cxx_range_for "${Intel13_CXX11}") # Cannot find Intel documentation for N2640: cxx_uniform_initialization set(_cmake_feature_test_cxx_uniform_initialization "${Intel13_CXX11}") -set(Intel121_CXX11 "__INTEL_COMPILER >= 1210 && ${DETECT_CXX11}") +set(Intel121_CXX11 "${_cmake_oldestSupported} && ${DETECT_CXX11}") set(_cmake_feature_test_cxx_variadic_templates "${Intel121_CXX11}") set(_cmake_feature_test_cxx_alias_templates "${Intel121_CXX11}") set(_cmake_feature_test_cxx_nullptr "${Intel121_CXX11}") set(_cmake_feature_test_cxx_trailing_return_types "${Intel121_CXX11}") set(_cmake_feature_test_cxx_attributes "${Intel121_CXX11}") set(_cmake_feature_test_cxx_default_function_template_args "${Intel121_CXX11}") - -set(Intel12_CXX11 "__INTEL_COMPILER >= 1200 && ${DETECT_CXX11}") -set(_cmake_feature_test_cxx_extended_friend_declarations "${Intel12_CXX11}") -set(_cmake_feature_test_cxx_rvalue_references "${Intel12_CXX11}") -set(_cmake_feature_test_cxx_decltype "${Intel12_CXX11}") -set(_cmake_feature_test_cxx_defaulted_functions "${Intel12_CXX11}") -set(_cmake_feature_test_cxx_deleted_functions "${Intel12_CXX11}") -set(_cmake_feature_test_cxx_local_type_template_args "${Intel12_CXX11}") -set(_cmake_feature_test_cxx_lambdas "${Intel12_CXX11}") - -set(Intel11_CXX11 "${_cmake_oldestSupported} && ${DETECT_CXX11}") -set(_cmake_feature_test_cxx_binary_literals "${Intel11_CXX11}") -set(_cmake_feature_test_cxx_static_assert "${Intel11_CXX11}") -set(_cmake_feature_test_cxx_right_angle_brackets "${Intel11_CXX11}") -set(_cmake_feature_test_cxx_auto_type "${Intel11_CXX11}") -set(_cmake_feature_test_cxx_extern_templates "${Intel11_CXX11}") -set(_cmake_feature_test_cxx_variadic_macros "${Intel11_CXX11}") -set(_cmake_feature_test_cxx_long_long_type "${Intel11_CXX11}") -set(_cmake_feature_test_cxx_func_identifier "${Intel11_CXX11}") -set(_cmake_feature_test_cxx_template_template_parameters "${Intel11_CXX11}") +set(_cmake_feature_test_cxx_extended_friend_declarations "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_rvalue_references "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_decltype "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_defaulted_functions "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_deleted_functions "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_local_type_template_args "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_lambdas "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_binary_literals "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_static_assert "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_right_angle_brackets "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_auto_type "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_extern_templates "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_variadic_macros "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_long_long_type "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_func_identifier "${Intel121_CXX11}") +set(_cmake_feature_test_cxx_template_template_parameters "${Intel121_CXX11}") From 36f32ede8d1a2aa1578a726f687a24dec4cc3f33 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Fri, 15 Apr 2016 13:40:30 -0400 Subject: [PATCH 4/7] Features: Record standards and features for Intel C on UNIX Record features for Intel C 12.1 and above. Skip this for now on Windows (where Intel C simulates MSVC). --- Modules/Compiler/Intel-C-FeatureTests.cmake | 23 ++++++++++ Modules/Compiler/Intel-C.cmake | 50 +++++++++++++++++++++ Tests/CompileFeatures/CMakeLists.txt | 10 +++++ 3 files changed, 83 insertions(+) create mode 100644 Modules/Compiler/Intel-C-FeatureTests.cmake diff --git a/Modules/Compiler/Intel-C-FeatureTests.cmake b/Modules/Compiler/Intel-C-FeatureTests.cmake new file mode 100644 index 000000000..34175c875 --- /dev/null +++ b/Modules/Compiler/Intel-C-FeatureTests.cmake @@ -0,0 +1,23 @@ +# References: +# - https://software.intel.com/en-us/articles/iso-iec-standards-language-conformance-for-intel-c-compiler +# - https://software.intel.com/en-us/articles/c99-support-in-intel-c-compiler +# - https://software.intel.com/en-us/articles/c11-support-in-intel-c-compiler + +# FIXME: Intel C feature detection works only when simulating the GNU compiler. +if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") + return() +endif() + +set(DETECT_C99 "defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L") + +#static assert is only around in version 1500 update 2 and above +set(_cmake_feature_test_c_static_assert "(__INTEL_COMPILER > 1500 || (__INTEL_COMPILER == 1500 && __INTEL_COMPILER_UPDATE > 1) ) && ${DETECT_C99}") + +set(_cmake_oldestSupported "__INTEL_COMPILER >= 1110") +set(Intel_C99 "${_cmake_oldestSupported} && ${DETECT_C99}") +set(_cmake_feature_test_c_restrict "${Intel_C99}") +set(_cmake_feature_test_c_variadic_macros "${Intel_C99}") +set(_cmake_feature_test_c_function_prototypes "${_cmake_oldestSupported}") +unset(Intel_C99) + +unset(DETECT_C99) diff --git a/Modules/Compiler/Intel-C.cmake b/Modules/Compiler/Intel-C.cmake index 77363eb9c..6e0743654 100644 --- a/Modules/Compiler/Intel-C.cmake +++ b/Modules/Compiler/Intel-C.cmake @@ -8,5 +8,55 @@ set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -DNDEBUG") set(CMAKE_DEPFILE_FLAGS_C "-MD -MT -MF ") +if(NOT "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 15.0.0) + set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11") + set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=c11") + endif() + + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 12.1) + set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c89") + set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=c89") + set(CMAKE_C99_STANDARD_COMPILE_OPTION "-std=c99") + set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-std=c99") + endif() +endif() + +if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 12.1) + if (NOT CMAKE_C_COMPILER_FORCED) + if (NOT CMAKE_C_STANDARD_COMPUTED_DEFAULT) + message(FATAL_ERROR "CMAKE_C_STANDARD_COMPUTED_DEFAULT should be set for ${CMAKE_C_COMPILER_ID} (${CMAKE_C_COMPILER}) version ${CMAKE_C_COMPILER_VERSION}") + endif() + set(CMAKE_C_STANDARD_DEFAULT ${CMAKE_C_STANDARD_COMPUTED_DEFAULT}) + elseif(NOT DEFINED CMAKE_C_STANDARD_DEFAULT) + # Compiler id was forced so just guess the default standard level. + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 15.0.0) + set(CMAKE_C_STANDARD_DEFAULT 11) + else() + set(CMAKE_C_STANDARD_DEFAULT 90) + endif() + endif() +endif() + +macro(cmake_record_c_compile_features) + macro(_get_intel_c_features std_version list) + record_compiler_features(C "${std_version}" ${list}) + endmacro() + + set(_result 0) + if (NOT "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC" AND + NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 12.1) + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 15.0.0) + _get_intel_c_features(${CMAKE_C11_STANDARD_COMPILE_OPTION} CMAKE_C11_COMPILE_FEATURES) + endif() + if (_result EQUAL 0) + _get_intel_c_features(${CMAKE_C99_STANDARD_COMPILE_OPTION} CMAKE_C99_COMPILE_FEATURES) + endif() + if (_result EQUAL 0) + _get_intel_c_features(${CMAKE_C90_STANDARD_COMPILE_OPTION} CMAKE_C90_COMPILE_FEATURES) + endif() + endif() +endmacro() + set(CMAKE_C_CREATE_PREPROCESSED_SOURCE " -E > ") set(CMAKE_C_CREATE_ASSEMBLY_SOURCE " -S -o ") diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt index e6acee883..9f0852334 100644 --- a/Tests/CompileFeatures/CMakeLists.txt +++ b/Tests/CompileFeatures/CMakeLists.txt @@ -226,6 +226,16 @@ if (CMAKE_C_COMPILE_FEATURES) list(APPEND expected_defs EXPECT_C_STATIC_ASSERT=1 ) + elseif (CMAKE_C_COMPILER_ID STREQUAL "Intel") + if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 15) + list(APPEND expected_defs + EXPECT_C_STATIC_ASSERT=1 + ) + else() + list(APPEND expected_defs + EXPECT_C_STATIC_ASSERT=0 + ) + endif() endif() list(APPEND expected_defs From 15a6c9502d6916274af2c634593295cf81af8af6 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Thu, 14 Apr 2016 08:57:07 -0400 Subject: [PATCH 5/7] WCDH: Add Intel to list of supported compilers --- Modules/WriteCompilerDetectionHeader.cmake | 5 +++-- .../WriteCompilerDetectionHeader/CMakeLists.txt | 14 +++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Modules/WriteCompilerDetectionHeader.cmake b/Modules/WriteCompilerDetectionHeader.cmake index a3b73bb89..2669a84f6 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 MSVC +# COMPILERS GNU Clang MSVC Intel # 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 MSVC +# COMPILERS GNU Clang AppleClang MSVC Intel # FEATURES cxx_variadic_templates # ) # @@ -323,6 +323,7 @@ function(write_compiler_detection_header AppleClang MSVC SunPro + Intel ) set(_hex_compilers ADSP Borland Embarcadero SunPro) diff --git a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt index c53828074..8b251d73f 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 MSVC SunPro + COMPILERS GNU Clang AppleClang MSVC SunPro Intel VERSION 3.1 PROLOG "// something" EPILOG "// more" @@ -61,7 +61,8 @@ endmacro() if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" - OR CMAKE_CXX_COMPILER_ID STREQUAL "SunPro") + OR CMAKE_CXX_COMPILER_ID STREQUAL "SunPro" + OR CMAKE_CXX_COMPILER_ID STREQUAL "Intel") # False for C++98 mode. list(APPEND false_defs EXPECTED_COMPILER_CXX_DELEGATING_CONSTRUCTORS) list(APPEND false_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES) @@ -80,7 +81,9 @@ endif() if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang" - OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang") + OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang" + OR CMAKE_C_COMPILER_ID STREQUAL "Intel") + add_executable(C_undefined c_undefined.c) set_property(TARGET C_undefined PROPERTY C_STANDARD 90) target_compile_options(C_undefined PRIVATE -Werror=undef) @@ -104,7 +107,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 MSVC SunPro + COMPILERS GNU Clang AppleClang MSVC SunPro Intel VERSION 3.1 FEATURES ${cxx_known_features} ${c_known_features} @@ -142,7 +145,8 @@ set_defines(multi_files_11 "${true_defs}" "${false_defs}") if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang" - OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang") + OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang" + OR CMAKE_C_COMPILER_ID STREQUAL "Intel") add_executable(WriteCompilerDetectionHeader_C11 main.c) set_property(TARGET WriteCompilerDetectionHeader_C11 PROPERTY C_STANDARD 11) set_defines(WriteCompilerDetectionHeader_C11 "EXPECTED_COMPILER_C_FUNCTION_PROTOTYPES;EXPECTED_COMPILER_C_RESTRICT" "") From 9addce99c2b38a20c86815adb13d7cf450a72512 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 18 Apr 2016 14:20:32 -0400 Subject: [PATCH 6/7] Features: Record standard flags for Intel C/C++ on Windows Select the `-std=` or `-Qstd=` flag based on whether Intel is GNU-like or MSVC-like, respectively. --- Modules/Compiler/Intel-C.cmake | 28 +++++++++++-------- Modules/Compiler/Intel-CXX.cmake | 48 ++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 32 deletions(-) diff --git a/Modules/Compiler/Intel-C.cmake b/Modules/Compiler/Intel-C.cmake index 6e0743654..eb9602a16 100644 --- a/Modules/Compiler/Intel-C.cmake +++ b/Modules/Compiler/Intel-C.cmake @@ -8,18 +8,22 @@ set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -DNDEBUG") set(CMAKE_DEPFILE_FLAGS_C "-MD -MT -MF ") -if(NOT "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") - if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 15.0.0) - set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11") - set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=c11") - endif() +if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") + set(_std -Qstd) +else() + set(_std -std) +endif() - if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 12.1) - set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c89") - set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=c89") - set(CMAKE_C99_STANDARD_COMPILE_OPTION "-std=c99") - set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-std=c99") - endif() +if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 15.0.0) + set(CMAKE_C11_STANDARD_COMPILE_OPTION "${_std}=c11") + set(CMAKE_C11_EXTENSION_COMPILE_OPTION "${_std}=c11") +endif() + +if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 12.1) + set(CMAKE_C90_STANDARD_COMPILE_OPTION "${_std}=c89") + set(CMAKE_C90_EXTENSION_COMPILE_OPTION "${_std}=c89") + set(CMAKE_C99_STANDARD_COMPILE_OPTION "${_std}=c99") + set(CMAKE_C99_EXTENSION_COMPILE_OPTION "${_std}=c99") endif() if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 12.1) @@ -38,6 +42,8 @@ if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 12.1) endif() endif() +unset(_std) + macro(cmake_record_c_compile_features) macro(_get_intel_c_features std_version list) record_compiler_features(C "${std_version}" ${list}) diff --git a/Modules/Compiler/Intel-CXX.cmake b/Modules/Compiler/Intel-CXX.cmake index 2785fd356..369e04123 100644 --- a/Modules/Compiler/Intel-CXX.cmake +++ b/Modules/Compiler/Intel-CXX.cmake @@ -8,29 +8,33 @@ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -DNDEBUG") set(CMAKE_DEPFILE_FLAGS_CXX "-MD -MT -MF ") -if(NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15.0.2) - set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++14") - # todo: there is no gnu++14 value supported; figure out what to do - set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=c++14") - elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15.0.0) - set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++1y") - # todo: there is no gnu++14 value supported; figure out what to do - set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=c++1y") - endif() +if("x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") + set(_std -Qstd) +else() + set(_std -std) +endif() - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.0) - set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11") - set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11") - elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.1) - set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++0x") - set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x") - endif() +if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15.0.2) + set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "${_std}=c++14") + # todo: there is no gnu++14 value supported; figure out what to do + set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "${_std}=c++14") +elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15.0.0) + set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "${_std}=c++1y") + # todo: there is no gnu++14 value supported; figure out what to do + set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "${_std}=c++1y") +endif() - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.1) - set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98") - set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98") - endif() +if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.0) + set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "${_std}=c++11") + set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "${_std}=gnu++11") +elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.1) + set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "${_std}=c++0x") + set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "${_std}=gnu++0x") +endif() + +if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.1) + set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "${_std}=c++98") + set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "${_std}=gnu++98") endif() if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.1) @@ -46,6 +50,8 @@ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.1) endif() endif() +unset(_std) + macro(cmake_record_cxx_compile_features) macro(_get_intel_features std_version list) record_compiler_features(CXX "${std_version}" ${list}) From 21b1fa5cb9adccd8d5bbc411c4932cf46d2ed29f Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 20 Apr 2016 10:34:02 -0400 Subject: [PATCH 7/7] Help: Add notes for topic 'intel-compiler-features' --- Help/release/dev/intel-compiler-features.rst | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Help/release/dev/intel-compiler-features.rst diff --git a/Help/release/dev/intel-compiler-features.rst b/Help/release/dev/intel-compiler-features.rst new file mode 100644 index 000000000..f154dc9ba --- /dev/null +++ b/Help/release/dev/intel-compiler-features.rst @@ -0,0 +1,6 @@ +intel-compiler-features +----------------------- + +* The :manual:`Compile Features ` functionality + is now aware of features supported by Intel C++ compilers versions 12.1 + through 16.0 on UNIX platforms.