Features: Add compiler version support to WriteCompilerDetectionHeader.
This commit is contained in:
parent
b70295760c
commit
ddec418a8f
|
@ -52,7 +52,15 @@
|
||||||
# Feature Test Macros
|
# Feature Test Macros
|
||||||
# ===================
|
# ===================
|
||||||
#
|
#
|
||||||
# For each compiler, a preprocessor test of the compiler version is generated
|
# For each compiler, a preprocessor macro is generated matching
|
||||||
|
# ``<PREFIX>_COMPILER_IS_<compiler>`` which has the content either ``0``
|
||||||
|
# or ``1``, depending on the compiler in use. Preprocessor macros for
|
||||||
|
# compiler version components are generated matching
|
||||||
|
# ``<PREFIX>_COMPILER_VERSION_MAJOR`` ``<PREFIX>_COMPILER_VERSION_MINOR``
|
||||||
|
# and ``<PREFIX>_COMPILER_VERSION_PATCH`` containing decimal values
|
||||||
|
# for the corresponding compiler version components, if defined.
|
||||||
|
#
|
||||||
|
# A preprocessor test is generated based on the compiler version
|
||||||
# denoting whether each feature is enabled. A preprocessor macro
|
# denoting whether each feature is enabled. A preprocessor macro
|
||||||
# matching ``<PREFIX>_COMPILER_<FEATURE>``, where ``<FEATURE>`` is the
|
# matching ``<PREFIX>_COMPILER_<FEATURE>``, where ``<FEATURE>`` is the
|
||||||
# upper-case ``<feature>`` name, is generated to contain the value
|
# upper-case ``<feature>`` name, is generated to contain the value
|
||||||
|
@ -166,6 +174,8 @@ function(_load_compiler_variables CompilerId lang)
|
||||||
foreach(feature ${ARGN})
|
foreach(feature ${ARGN})
|
||||||
set(_cmake_feature_test_${CompilerId}_${feature} ${_cmake_feature_test_${feature}} PARENT_SCOPE)
|
set(_cmake_feature_test_${CompilerId}_${feature} ${_cmake_feature_test_${feature}} PARENT_SCOPE)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
include("${CMAKE_ROOT}/Modules/Compiler/${CompilerId}-DetermineCompiler.cmake" OPTIONAL)
|
||||||
|
set(_compiler_id_version_compute_${CompilerId} ${_compiler_id_version_compute} PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(write_compiler_detection_header
|
function(write_compiler_detection_header
|
||||||
|
@ -210,11 +220,20 @@ function(write_compiler_detection_header
|
||||||
GNU
|
GNU
|
||||||
Clang
|
Clang
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(_hex_compilers ADSP Borland Embarcadero SunPro)
|
||||||
|
|
||||||
foreach(_comp ${_WCD_COMPILERS})
|
foreach(_comp ${_WCD_COMPILERS})
|
||||||
list(FIND compilers ${_comp} idx)
|
list(FIND compilers ${_comp} idx)
|
||||||
if (idx EQUAL -1)
|
if (idx EQUAL -1)
|
||||||
message(FATAL_ERROR "Unsupported compiler ${_comp}.")
|
message(FATAL_ERROR "Unsupported compiler ${_comp}.")
|
||||||
endif()
|
endif()
|
||||||
|
if (NOT _need_hex_conversion)
|
||||||
|
list(FIND _hex_compilers ${_comp} idx)
|
||||||
|
if (NOT idx EQUAL -1)
|
||||||
|
set(_need_hex_conversion TRUE)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
set(file_content "
|
set(file_content "
|
||||||
|
@ -228,6 +247,21 @@ function(write_compiler_detection_header
|
||||||
set(file_content "${file_content}\n${_WCD_PROLOG}\n")
|
set(file_content "${file_content}\n${_WCD_PROLOG}\n")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (_need_hex_conversion)
|
||||||
|
set(file_content "${file_content}
|
||||||
|
#define ${prefix_arg}_DEC(X) (X)
|
||||||
|
#define ${prefix_arg}_HEX(X) ( \\
|
||||||
|
((X)>>28 & 0xF) * 10000000 + \\
|
||||||
|
((X)>>24 & 0xF) * 1000000 + \\
|
||||||
|
((X)>>20 & 0xF) * 100000 + \\
|
||||||
|
((X)>>16 & 0xF) * 10000 + \\
|
||||||
|
((X)>>12 & 0xF) * 1000 + \\
|
||||||
|
((X)>>8 & 0xF) * 100 + \\
|
||||||
|
((X)>>4 & 0xF) * 10 + \\
|
||||||
|
((X) & 0xF) \\
|
||||||
|
)\n")
|
||||||
|
endif()
|
||||||
|
|
||||||
foreach(feature ${_WCD_FEATURES})
|
foreach(feature ${_WCD_FEATURES})
|
||||||
if (feature MATCHES "^cxx_")
|
if (feature MATCHES "^cxx_")
|
||||||
list(APPEND _langs CXX)
|
list(APPEND _langs CXX)
|
||||||
|
@ -271,6 +305,21 @@ function(write_compiler_detection_header
|
||||||
# if !(${_cmake_oldestSupported_${compiler}})
|
# if !(${_cmake_oldestSupported_${compiler}})
|
||||||
# error Unsupported compiler version
|
# error Unsupported compiler version
|
||||||
# endif\n")
|
# endif\n")
|
||||||
|
|
||||||
|
set(PREFIX ${prefix_arg}_)
|
||||||
|
if (_need_hex_conversion)
|
||||||
|
set(MACRO_DEC ${prefix_arg}_DEC)
|
||||||
|
set(MACRO_HEX ${prefix_arg}_HEX)
|
||||||
|
else()
|
||||||
|
set(MACRO_DEC)
|
||||||
|
set(MACRO_HEX)
|
||||||
|
endif()
|
||||||
|
string(CONFIGURE "${_compiler_id_version_compute_${compiler}}" VERSION_BLOCK @ONLY)
|
||||||
|
set(file_content "${file_content}${VERSION_BLOCK}\n")
|
||||||
|
set(PREFIX)
|
||||||
|
set(MACRO_DEC)
|
||||||
|
set(MACRO_HEX)
|
||||||
|
|
||||||
set(pp_if "elif")
|
set(pp_if "elif")
|
||||||
foreach(feature ${${_lang}_features})
|
foreach(feature ${${_lang}_features})
|
||||||
string(TOUPPER ${feature} feature_upper)
|
string(TOUPPER ${feature} feature_upper)
|
||||||
|
|
|
@ -35,6 +35,10 @@ if (NOT CMAKE_CXX_COMPILE_FEATURES AND NOT CMAKE_C_COMPILE_FEATURES)
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" COMPILER_VERSION_MAJOR "${CMAKE_CXX_COMPILER_VERSION}")
|
||||||
|
string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" COMPILER_VERSION_MINOR "${CMAKE_CXX_COMPILER_VERSION}")
|
||||||
|
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" COMPILER_VERSION_PATCH "${CMAKE_CXX_COMPILER_VERSION}")
|
||||||
|
|
||||||
macro(set_defines target true_defs false_defs)
|
macro(set_defines target true_defs false_defs)
|
||||||
set(defines)
|
set(defines)
|
||||||
foreach(def ${true_defs})
|
foreach(def ${true_defs})
|
||||||
|
@ -46,6 +50,9 @@ macro(set_defines target true_defs false_defs)
|
||||||
target_compile_definitions(${target}
|
target_compile_definitions(${target}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${defines}
|
${defines}
|
||||||
|
EXPECTED_COMPILER_VERSION_MAJOR=${COMPILER_VERSION_MAJOR}
|
||||||
|
EXPECTED_COMPILER_VERSION_MINOR=${COMPILER_VERSION_MINOR}
|
||||||
|
EXPECTED_COMPILER_VERSION_PATCH=${COMPILER_VERSION_PATCH}
|
||||||
)
|
)
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,18 @@
|
||||||
#error cxx_variadic_templates expected availability did not match.
|
#error cxx_variadic_templates expected availability did not match.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !CHECK(VERSION_MAJOR)
|
||||||
|
#error Compiler major version did not match.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !CHECK(VERSION_MINOR)
|
||||||
|
#error Compiler minor version did not match.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !CHECK(VERSION_PATCH)
|
||||||
|
#error Compiler patch version did not match.
|
||||||
|
#endif
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue