Commit 8b6cc251 authored by Brad King's avatar Brad King

Features: Centralize per-compiler recording macros

Simplify and de-duplicate per-compiler feature recording macros and
convert to a centralized per-language macro.
parent 2d23f7b2
Pipeline #33601 passed with stage
......@@ -25,18 +25,14 @@ if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.0)
endif()
macro(cmake_record_c_compile_features)
macro(_get_appleclang_features std_version list)
record_compiler_features(C "${std_version}" ${list})
endmacro()
set(_result 0)
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.0)
_get_appleclang_features(${CMAKE_C11_STANDARD_COMPILE_OPTION} CMAKE_C11_COMPILE_FEATURES)
_record_compiler_features_c(11)
if (_result EQUAL 0)
_get_appleclang_features(${CMAKE_C99_STANDARD_COMPILE_OPTION} CMAKE_C99_COMPILE_FEATURES)
_record_compiler_features_c(99)
endif()
if (_result EQUAL 0)
_get_appleclang_features(${CMAKE_C90_STANDARD_COMPILE_OPTION} CMAKE_C90_COMPILE_FEATURES)
_record_compiler_features_c(90)
endif()
endif()
endmacro()
......@@ -36,21 +36,17 @@ endif()
macro(cmake_record_cxx_compile_features)
macro(_get_appleclang_features std_version list)
record_compiler_features(CXX "${std_version}" ${list})
endmacro()
set(_result 0)
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0)
set(_result 0)
if(CMAKE_CXX14_STANDARD_COMPILE_OPTION)
_get_appleclang_features(${CMAKE_CXX14_STANDARD_COMPILE_OPTION} CMAKE_CXX14_COMPILE_FEATURES)
_record_compiler_features_cxx(14)
endif()
if (_result EQUAL 0)
_get_appleclang_features(${CMAKE_CXX11_STANDARD_COMPILE_OPTION} CMAKE_CXX11_COMPILE_FEATURES)
_record_compiler_features_cxx(11)
endif()
if (_result EQUAL 0)
_get_appleclang_features(${CMAKE_CXX98_STANDARD_COMPILE_OPTION} CMAKE_CXX98_COMPILE_FEATURES)
_record_compiler_features_cxx(98)
endif()
endif()
endmacro()
......@@ -34,18 +34,14 @@ if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.4)
endif()
macro(cmake_record_c_compile_features)
macro(_get_clang_features std_version list)
record_compiler_features(C "${std_version}" ${list})
endmacro()
set(_result 0)
if (UNIX AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.4)
_get_clang_features(${CMAKE_C11_STANDARD_COMPILE_OPTION} CMAKE_C11_COMPILE_FEATURES)
_record_compiler_features_c(11)
if (_result EQUAL 0)
_get_clang_features(${CMAKE_C99_STANDARD_COMPILE_OPTION} CMAKE_C99_COMPILE_FEATURES)
_record_compiler_features_c(99)
endif()
if (_result EQUAL 0)
_get_clang_features(${CMAKE_C90_STANDARD_COMPILE_OPTION} CMAKE_C90_COMPILE_FEATURES)
_record_compiler_features_c(90)
endif()
endif()
endmacro()
......@@ -44,18 +44,14 @@ if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
endif()
macro(cmake_record_cxx_compile_features)
macro(_get_clang_features std_version list)
record_compiler_features(CXX "${std_version}" ${list})
endmacro()
set(_result 0)
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
_get_clang_features(${CMAKE_CXX14_STANDARD_COMPILE_OPTION} CMAKE_CXX14_COMPILE_FEATURES)
_record_compiler_features_cxx(14)
if (_result EQUAL 0)
_get_clang_features(${CMAKE_CXX11_STANDARD_COMPILE_OPTION} CMAKE_CXX11_COMPILE_FEATURES)
_record_compiler_features_cxx(11)
endif()
if (_result EQUAL 0)
_get_clang_features(${CMAKE_CXX98_STANDARD_COMPILE_OPTION} CMAKE_CXX98_COMPILE_FEATURES)
_record_compiler_features_cxx(98)
endif()
endif()
endmacro()
......@@ -40,20 +40,16 @@ endif()
macro(cmake_record_c_compile_features)
macro(_get_gcc_features std_version list)
record_compiler_features(C "${std_version}" ${list})
endmacro()
set(_result 0)
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.6)
_get_gcc_features(${CMAKE_C11_STANDARD_COMPILE_OPTION} CMAKE_C11_COMPILE_FEATURES)
_record_compiler_features_c(11)
endif()
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.4)
if (_result EQUAL 0)
_get_gcc_features(${CMAKE_C99_STANDARD_COMPILE_OPTION} CMAKE_C99_COMPILE_FEATURES)
_record_compiler_features_c(99)
endif()
if (_result EQUAL 0)
_get_gcc_features(${CMAKE_C90_STANDARD_COMPILE_OPTION} CMAKE_C90_COMPILE_FEATURES)
_record_compiler_features_c(90)
endif()
endif()
endmacro()
......@@ -47,20 +47,16 @@ if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4)
endif()
macro(cmake_record_cxx_compile_features)
macro(_get_gcc_features std_version list)
record_compiler_features(CXX "${std_version}" ${list})
endmacro()
set(_result 0)
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
_get_gcc_features(${CMAKE_CXX14_STANDARD_COMPILE_OPTION} CMAKE_CXX14_COMPILE_FEATURES)
_record_compiler_features_cxx(14)
endif()
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4)
if (_result EQUAL 0)
_get_gcc_features(${CMAKE_CXX11_STANDARD_COMPILE_OPTION} CMAKE_CXX11_COMPILE_FEATURES)
_record_compiler_features_cxx(11)
endif()
if (_result EQUAL 0)
_get_gcc_features(${CMAKE_CXX98_STANDARD_COMPILE_OPTION} CMAKE_CXX98_COMPILE_FEATURES)
_record_compiler_features_cxx(98)
endif()
endif()
endmacro()
......@@ -47,20 +47,16 @@ unset(_std)
unset(_ext)
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 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)
_record_compiler_features_C(11)
endif()
if (_result EQUAL 0)
_get_intel_c_features(${CMAKE_C99_STANDARD_COMPILE_OPTION} CMAKE_C99_COMPILE_FEATURES)
_record_compiler_features_C(99)
endif()
if (_result EQUAL 0)
_get_intel_c_features(${CMAKE_C90_STANDARD_COMPILE_OPTION} CMAKE_C90_COMPILE_FEATURES)
_record_compiler_features_C(90)
endif()
endif()
endmacro()
......
......@@ -60,20 +60,16 @@ unset(_std)
unset(_ext)
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 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)
_record_compiler_features_cxx(14)
endif()
if (_result EQUAL 0)
_get_intel_features("${CMAKE_CXX11_STANDARD_COMPILE_OPTION}" CMAKE_CXX11_COMPILE_FEATURES)
_record_compiler_features_cxx(11)
endif()
if (_result EQUAL 0)
_get_intel_features("${CMAKE_CXX98_STANDARD_COMPILE_OPTION}" CMAKE_CXX98_COMPILE_FEATURES)
_record_compiler_features_cxx(98)
endif()
endif()
endmacro()
......
......@@ -6,6 +6,6 @@ endif()
macro(cmake_record_cxx_compile_features)
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16.0)
record_compiler_features(CXX "" CMAKE_CXX_COMPILE_FEATURES)
_record_compiler_features(CXX "" CMAKE_CXX_COMPILE_FEATURES)
endif()
endmacro()
......@@ -32,6 +32,8 @@ set(CMAKE_CXX_CREATE_STATIC_LIBRARY
"<CMAKE_RANLIB> <TARGET> ")
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.13)
set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "")
set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "")
set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11")
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=c++11")
endif()
......@@ -49,15 +51,11 @@ if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.13)
endif()
macro(cmake_record_cxx_compile_features)
macro(_get_solaris_studio_features std_version list)
record_compiler_features(CXX "${std_version}" ${list})
endmacro()
set(_result 0)
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.13)
_get_solaris_studio_features(${CMAKE_CXX11_STANDARD_COMPILE_OPTION} CMAKE_CXX11_COMPILE_FEATURES)
_record_compiler_features_cxx(11)
if (_result EQUAL 0)
_get_solaris_studio_features("" CMAKE_CXX98_COMPILE_FEATURES)
_record_compiler_features_cxx(98)
endif()
endif()
endmacro()
macro(record_compiler_features lang compile_flags feature_list)
macro(_record_compiler_features lang compile_flags feature_list)
include("${CMAKE_ROOT}/Modules/Compiler/${CMAKE_${lang}_COMPILER_ID}-${lang}-FeatureTests.cmake" OPTIONAL)
string(TOLOWER ${lang} lang_lc)
......@@ -58,3 +58,11 @@ macro(record_compiler_features lang compile_flags feature_list)
"Detecting ${lang} [${compile_flags}] compiler features failed to compile with the following output:\n${_output}\n${_copy_error}\n\n")
endif()
endmacro()
macro(_record_compiler_features_c std)
_record_compiler_features(C "${CMAKE_C${std}_STANDARD_COMPILE_OPTION}" CMAKE_C${std}_COMPILE_FEATURES)
endmacro()
macro(_record_compiler_features_cxx std)
_record_compiler_features(CXX "${CMAKE_CXX${std}_STANDARD_COMPILE_OPTION}" CMAKE_CXX${std}_COMPILE_FEATURES)
endmacro()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment