Merge topic 'compute-default-dialect'

7235334a Project: Determine default language dialect for the compiler.
This commit is contained in:
Brad King 2015-09-18 10:00:51 -04:00 committed by CMake Topic Stage
commit e3ace61212
14 changed files with 66 additions and 19 deletions

View File

@ -52,9 +52,9 @@ When adding the first supported feature to a particular CompilerId, it is
necessary to list support for all features known to cmake (See necessary to list support for all features known to cmake (See
:variable:`CMAKE_C_COMPILE_FEATURES` and :variable:`CMAKE_C_COMPILE_FEATURES` and
:variable:`CMAKE_CXX_COMPILE_FEATURES` as appropriate), where available for :variable:`CMAKE_CXX_COMPILE_FEATURES` as appropriate), where available for
the compiler. Furthermore, set ``CMAKE_<LANG>_STANDARD_DEFAULT`` to the the compiler. Ensure that the ``CMAKE_<LANG>_STANDARD_DEFAULT`` is set to
default language standard level the compiler uses, or to the empty string the computed internal variable ``CMAKE_<LANG>_STANDARD_COMPUTED_DEFAULT``
if the compiler has no notion of standard levels (such as ``MSVC``). for compiler versions which should be supported.
It is sensible to record the features for the most recent version of a It is sensible to record the features for the most recent version of a
particular CompilerId first, and then work backwards. It is sensible to particular CompilerId first, and then work backwards. It is sensible to

View File

@ -2,6 +2,7 @@ set(CMAKE_C_COMPILER "@CMAKE_C_COMPILER@")
set(CMAKE_C_COMPILER_ARG1 "@CMAKE_C_COMPILER_ARG1@") set(CMAKE_C_COMPILER_ARG1 "@CMAKE_C_COMPILER_ARG1@")
set(CMAKE_C_COMPILER_ID "@CMAKE_C_COMPILER_ID@") set(CMAKE_C_COMPILER_ID "@CMAKE_C_COMPILER_ID@")
set(CMAKE_C_COMPILER_VERSION "@CMAKE_C_COMPILER_VERSION@") set(CMAKE_C_COMPILER_VERSION "@CMAKE_C_COMPILER_VERSION@")
set(CMAKE_C_STANDARD_COMPUTED_DEFAULT "@CMAKE_C_STANDARD_COMPUTED_DEFAULT@")
set(CMAKE_C_COMPILE_FEATURES "@CMAKE_C_COMPILE_FEATURES@") set(CMAKE_C_COMPILE_FEATURES "@CMAKE_C_COMPILE_FEATURES@")
set(CMAKE_C90_COMPILE_FEATURES "@CMAKE_C90_COMPILE_FEATURES@") set(CMAKE_C90_COMPILE_FEATURES "@CMAKE_C90_COMPILE_FEATURES@")
set(CMAKE_C99_COMPILE_FEATURES "@CMAKE_C99_COMPILE_FEATURES@") set(CMAKE_C99_COMPILE_FEATURES "@CMAKE_C99_COMPILE_FEATURES@")

View File

@ -24,6 +24,17 @@ char const* qnxnto = "INFO" ":" "qnxnto[]";
@CMAKE_C_COMPILER_ID_PLATFORM_CONTENT@ @CMAKE_C_COMPILER_ID_PLATFORM_CONTENT@
@CMAKE_C_COMPILER_ID_ERROR_FOR_TEST@ @CMAKE_C_COMPILER_ID_ERROR_FOR_TEST@
const char* info_language_dialect_default = "INFO" ":" "dialect_default["
#if !defined(__STDC_VERSION__)
"90"
#elif __STDC_VERSION__ >= 201000L
"11"
#elif __STDC_VERSION__ >= 199901L
"99"
#else
#endif
"]";
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
#ifdef ID_VOID_MAIN #ifdef ID_VOID_MAIN

View File

@ -2,6 +2,7 @@ set(CMAKE_CXX_COMPILER "@CMAKE_CXX_COMPILER@")
set(CMAKE_CXX_COMPILER_ARG1 "@CMAKE_CXX_COMPILER_ARG1@") set(CMAKE_CXX_COMPILER_ARG1 "@CMAKE_CXX_COMPILER_ARG1@")
set(CMAKE_CXX_COMPILER_ID "@CMAKE_CXX_COMPILER_ID@") set(CMAKE_CXX_COMPILER_ID "@CMAKE_CXX_COMPILER_ID@")
set(CMAKE_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@") set(CMAKE_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@")
set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT "@CMAKE_CXX_STANDARD_COMPUTED_DEFAULT@")
set(CMAKE_CXX_COMPILE_FEATURES "@CMAKE_CXX_COMPILE_FEATURES@") set(CMAKE_CXX_COMPILE_FEATURES "@CMAKE_CXX_COMPILE_FEATURES@")
set(CMAKE_CXX98_COMPILE_FEATURES "@CMAKE_CXX98_COMPILE_FEATURES@") set(CMAKE_CXX98_COMPILE_FEATURES "@CMAKE_CXX98_COMPILE_FEATURES@")
set(CMAKE_CXX11_COMPILE_FEATURES "@CMAKE_CXX11_COMPILE_FEATURES@") set(CMAKE_CXX11_COMPILE_FEATURES "@CMAKE_CXX11_COMPILE_FEATURES@")

View File

@ -23,6 +23,16 @@ char const* qnxnto = "INFO" ":" "qnxnto[]";
@CMAKE_CXX_COMPILER_ID_PLATFORM_CONTENT@ @CMAKE_CXX_COMPILER_ID_PLATFORM_CONTENT@
@CMAKE_CXX_COMPILER_ID_ERROR_FOR_TEST@ @CMAKE_CXX_COMPILER_ID_ERROR_FOR_TEST@
const char* info_language_dialect_default = "INFO" ":" "dialect_default["
#if __cplusplus >= 201402L
"14"
#elif __cplusplus >= 201103L
"11"
#else
"98"
#endif
"]";
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int main(int argc, char* argv[]) int main(int argc, char* argv[])

View File

@ -102,6 +102,7 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE) set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE)
set(CMAKE_${lang}_SIMULATE_ID "${CMAKE_${lang}_SIMULATE_ID}" PARENT_SCOPE) set(CMAKE_${lang}_SIMULATE_ID "${CMAKE_${lang}_SIMULATE_ID}" PARENT_SCOPE)
set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE) set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE)
set(CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT "${CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT}" PARENT_SCOPE)
endfunction() endfunction()
include(CMakeCompilerIdDetection) include(CMakeCompilerIdDetection)
@ -487,6 +488,9 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
if("${info}" MATCHES "INFO:qnxnto\\[\\]") if("${info}" MATCHES "INFO:qnxnto\\[\\]")
set(COMPILER_QNXNTO 1) set(COMPILER_QNXNTO 1)
endif() endif()
if("${info}" MATCHES "INFO:dialect_default\\[([^]\"]*)\\]")
set(CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT "${CMAKE_MATCH_1}")
endif()
endforeach() endforeach()
# Construct compiler version from components if needed. # Construct compiler version from components if needed.
@ -590,6 +594,7 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE) set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE)
set(CMAKE_EXECUTABLE_FORMAT "${CMAKE_EXECUTABLE_FORMAT}" PARENT_SCOPE) set(CMAKE_EXECUTABLE_FORMAT "${CMAKE_EXECUTABLE_FORMAT}" PARENT_SCOPE)
set(COMPILER_QNXNTO "${COMPILER_QNXNTO}" PARENT_SCOPE) set(COMPILER_QNXNTO "${COMPILER_QNXNTO}" PARENT_SCOPE)
set(CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT "${CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT}" PARENT_SCOPE)
endfunction() endfunction()
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------

View File

@ -13,7 +13,10 @@ if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.0)
endif() endif()
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.0) if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.0)
set(CMAKE_C_STANDARD_DEFAULT 99) 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})
endif() endif()
macro(cmake_record_c_compile_features) macro(cmake_record_c_compile_features)

View File

@ -23,9 +23,13 @@ elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1)
endif() endif()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0) if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0)
set(CMAKE_CXX_STANDARD_DEFAULT 98) 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}")
endif()
set(CMAKE_CXX_STANDARD_DEFAULT ${CMAKE_CXX_STANDARD_COMPUTED_DEFAULT})
endif() endif()
macro(cmake_record_cxx_compile_features) macro(cmake_record_cxx_compile_features)
macro(_get_appleclang_features std_version list) macro(_get_appleclang_features std_version list)
record_compiler_features(CXX "${std_version}" ${list}) record_compiler_features(CXX "${std_version}" ${list})

View File

@ -17,10 +17,11 @@ if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.4)
set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu11") set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu11")
endif() endif()
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.6) if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.4)
set(CMAKE_C_STANDARD_DEFAULT 11) if (NOT CMAKE_C_STANDARD_COMPUTED_DEFAULT)
elseif(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.4) message(FATAL_ERROR "CMAKE_C_STANDARD_COMPUTED_DEFAULT should be set for ${CMAKE_C_COMPILER_ID} (${CMAKE_C_COMPILER}) version ${CMAKE_C_COMPILER_VERSION}")
set(CMAKE_C_STANDARD_DEFAULT 99) endif()
set(CMAKE_C_STANDARD_DEFAULT ${CMAKE_C_STANDARD_COMPUTED_DEFAULT})
endif() endif()
macro(cmake_record_c_compile_features) macro(cmake_record_c_compile_features)

View File

@ -31,8 +31,11 @@ elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++1y") set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++1y")
endif() endif()
if(UNIX AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4) if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
set(CMAKE_CXX_STANDARD_DEFAULT 98) 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}")
endif()
set(CMAKE_CXX_STANDARD_DEFAULT ${CMAKE_CXX_STANDARD_COMPUTED_DEFAULT})
endif() endif()
macro(cmake_record_cxx_compile_features) macro(cmake_record_cxx_compile_features)

View File

@ -22,12 +22,14 @@ elseif (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.6)
set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu1x") set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu1x")
endif() endif()
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0) if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.4)
set(CMAKE_C_STANDARD_DEFAULT 11) if (NOT CMAKE_C_STANDARD_COMPUTED_DEFAULT)
elseif(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.4) message(FATAL_ERROR "CMAKE_C_STANDARD_COMPUTED_DEFAULT should be set for ${CMAKE_C_COMPILER_ID} (${CMAKE_C_COMPILER}) version ${CMAKE_C_COMPILER_VERSION}")
set(CMAKE_C_STANDARD_DEFAULT 90) endif()
set(CMAKE_C_STANDARD_DEFAULT ${CMAKE_C_STANDARD_COMPUTED_DEFAULT})
endif() endif()
macro(cmake_record_c_compile_features) macro(cmake_record_c_compile_features)
macro(_get_gcc_features std_version list) macro(_get_gcc_features std_version list)
record_compiler_features(C "${std_version}" ${list}) record_compiler_features(C "${std_version}" ${list})

View File

@ -35,7 +35,10 @@ elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
endif() endif()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4) if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4)
set(CMAKE_CXX_STANDARD_DEFAULT 98) 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}")
endif()
set(CMAKE_CXX_STANDARD_DEFAULT ${CMAKE_CXX_STANDARD_COMPUTED_DEFAULT})
endif() endif()
macro(cmake_record_cxx_compile_features) macro(cmake_record_cxx_compile_features)

View File

@ -36,8 +36,11 @@ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.13)
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=c++11") set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=c++11")
endif() endif()
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.13) if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.13)
set(CMAKE_CXX_STANDARD_DEFAULT 98) 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}")
endif()
set(CMAKE_CXX_STANDARD_DEFAULT ${CMAKE_CXX_STANDARD_COMPUTED_DEFAULT})
endif() endif()
macro(cmake_record_cxx_compile_features) macro(cmake_record_cxx_compile_features)

View File

@ -29,7 +29,7 @@ if (NOT CXX_FEATURES)
run_cmake(NoSupportedCxxFeatures) run_cmake(NoSupportedCxxFeatures)
run_cmake(NoSupportedCxxFeaturesGenex) run_cmake(NoSupportedCxxFeaturesGenex)
else() else()
if(CXX_STANDARD_DEFAULT) if(CXX_STANDARD_DEFAULT EQUAL 98)
run_cmake(LinkImplementationFeatureCycle) run_cmake(LinkImplementationFeatureCycle)
endif() endif()
run_cmake(LinkImplementationFeatureCycleSolved) run_cmake(LinkImplementationFeatureCycleSolved)