summaryrefslogtreecommitdiff
path: root/CMake/AbseilHelpers.cmake
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2022-08-22 12:25:07 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2022-08-22 12:26:09 -0700
commitc561515182e8c67fadae009f5368ab72b6f19786 (patch)
tree4c4b101f16b5b8199b8346c63433528ddfb49e40 /CMake/AbseilHelpers.cmake
parentf7474d4961b769c34a08475110ba391e5926e893 (diff)
Support compilers that are unknown to CMake
Abseil failed to configure with `ABSL_PROPAGATE_CXX_STD` if the compiler was not known to CMake: target_compile_features no known features for CXX compiler Turns the error into a warning by checking `CMAKE_CXX_COMPILE_FEATURES` before calling `target_compile_features`. PiperOrigin-RevId: 469254470 Change-Id: Ifba006dcdbf6a7112e382075b24678a792dbc827
Diffstat (limited to 'CMake/AbseilHelpers.cmake')
-rw-r--r--CMake/AbseilHelpers.cmake14
1 files changed, 11 insertions, 3 deletions
diff --git a/CMake/AbseilHelpers.cmake b/CMake/AbseilHelpers.cmake
index 96d815dd..3fb86375 100644
--- a/CMake/AbseilHelpers.cmake
+++ b/CMake/AbseilHelpers.cmake
@@ -32,6 +32,14 @@ else()
set(ABSL_INTERNAL_INCLUDE_WARNING_GUARD "")
endif()
+function(_target_compile_features_if_available TARGET TYPE FEATURE)
+ if(FEATURE IN_LIST CMAKE_CXX_COMPILE_FEATURES)
+ target_compile_features(${TARGET} ${TYPE} ${FEATURE})
+ else()
+ message(WARNING "Feature ${FEATURE} is unknown for the CXX compiler")
+ endif()
+endfunction()
+
# absl_cc_library()
#
# CMake function to imitate Bazel's cc_library rule.
@@ -270,7 +278,7 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
# Abseil libraries require C++14 as the current minimum standard.
# Top-level application CMake projects should ensure a consistent C++
# standard for all compiled sources by setting CMAKE_CXX_STANDARD.
- target_compile_features(${_NAME} PUBLIC cxx_std_14)
+ _target_compile_features_if_available(${_NAME} PUBLIC cxx_std_14)
else()
# Note: This is legacy (before CMake 3.8) behavior. Setting the
# target-level CXX_STANDARD property to ABSL_CXX_STANDARD (which is
@@ -318,7 +326,7 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
# Abseil libraries require C++14 as the current minimum standard.
# Top-level application CMake projects should ensure a consistent C++
# standard for all compiled sources by setting CMAKE_CXX_STANDARD.
- target_compile_features(${_NAME} INTERFACE cxx_std_14)
+ _target_compile_features_if_available(${_NAME} INTERFACE cxx_std_14)
# (INTERFACE libraries can't have the CXX_STANDARD property set, so there
# is no legacy behavior else case).
@@ -430,7 +438,7 @@ function(absl_cc_test)
# Abseil libraries require C++14 as the current minimum standard.
# Top-level application CMake projects should ensure a consistent C++
# standard for all compiled sources by setting CMAKE_CXX_STANDARD.
- target_compile_features(${_NAME} PUBLIC cxx_std_14)
+ _target_compile_features_if_available(${_NAME} PUBLIC cxx_std_14)
else()
# Note: This is legacy (before CMake 3.8) behavior. Setting the
# target-level CXX_STANDARD property to ABSL_CXX_STANDARD (which is