summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2022-10-31 11:20:42 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2022-10-31 11:21:32 -0700
commitea882fb76637f00e9a547ce1c6c42cd90a7f955b (patch)
treec8387608e82fb29776f47ccdf0bb1ad96ce3f8a5
parentf5fd4cc7ebdb05995b9c7399d9a091efdc1dc738 (diff)
CMake: installed artifacts reflect the compiled ABI
In a previous change, I forgot to fix the DLLs to also set the target_compile_features() as needed. Some amount of refactoring to expose the necessary variables and functions in AbseilDll.cmake Fixes #1116 PiperOrigin-RevId: 485101834 Change-Id: I5cd0eff9e20c0ddf48c364f917e40d66df0aac17
-rw-r--r--CMake/AbseilDll.cmake48
-rw-r--r--CMake/AbseilHelpers.cmake35
2 files changed, 51 insertions, 32 deletions
diff --git a/CMake/AbseilDll.cmake b/CMake/AbseilDll.cmake
index d90d24d8..b81b0cea 100644
--- a/CMake/AbseilDll.cmake
+++ b/CMake/AbseilDll.cmake
@@ -476,6 +476,35 @@ set(ABSL_INTERNAL_DLL_TARGETS
"variant"
)
+function(_absl_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()
+
+include(CheckCXXSourceCompiles)
+
+check_cxx_source_compiles(
+ [==[
+#ifdef _MSC_VER
+# if _MSVC_LANG < 201700L
+# error "The compiler defaults or is configured for C++ < 17"
+# endif
+#elif __cplusplus < 201700L
+# error "The compiler defaults or is configured for C++ < 17"
+#endif
+int main() { return 0; }
+]==]
+ ABSL_INTERNAL_AT_LEAST_CXX17)
+
+if(ABSL_INTERNAL_AT_LEAST_CXX17)
+ set(ABSL_INTERNAL_CXX_STD_FEATURE cxx_std_17)
+else()
+ set(ABSL_INTERNAL_CXX_STD_FEATURE cxx_std_14)
+endif()
+
function(absl_internal_dll_contains)
cmake_parse_arguments(ABSL_INTERNAL_DLL
""
@@ -555,6 +584,25 @@ function(absl_make_dll)
${ABSL_CC_LIB_DEFINES}
ABSL_CONSUME_DLL
)
+
+ if(ABSL_PROPAGATE_CXX_STD)
+ # Abseil libraries require C++14 as the current minimum standard. When
+ # compiled with C++17 (either because it is the compiler's default or
+ # explicitly requested), then Abseil requires C++17.
+ _absl_target_compile_features_if_available(${_NAME} PUBLIC ${ABSL_INTERNAL_CXX_STD_FEATURE})
+ else()
+ # Note: This is legacy (before CMake 3.8) behavior. Setting the
+ # target-level CXX_STANDARD property to ABSL_CXX_STANDARD (which is
+ # initialized by CMAKE_CXX_STANDARD) should have no real effect, since
+ # that is the default value anyway.
+ #
+ # CXX_STANDARD_REQUIRED does guard against the top-level CMake project
+ # not having enabled CMAKE_CXX_STANDARD_REQUIRED (which prevents
+ # "decaying" to an older standard if the requested one isn't available).
+ set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD})
+ set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
+ endif()
+
install(TARGETS abseil_dll EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
diff --git a/CMake/AbseilHelpers.cmake b/CMake/AbseilHelpers.cmake
index 6d402872..8e08d3fc 100644
--- a/CMake/AbseilHelpers.cmake
+++ b/CMake/AbseilHelpers.cmake
@@ -32,35 +32,6 @@ else()
set(ABSL_INTERNAL_INCLUDE_WARNING_GUARD "")
endif()
-function(_absl_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()
-
-include(CheckCXXSourceCompiles)
-
-check_cxx_source_compiles(
- [==[
-#ifdef _MSC_VER
-# if _MSVC_LANG < 201700L
-# error "The compiler defaults or is configured for C++ < 17"
-# endif
-#elif __cplusplus < 201700L
-# error "The compiler defaults or is configured for C++ < 17"
-#endif
-int main() { return 0; }
-]==]
- ABSL_INTERNAL_AT_LEAST_CXX17)
-
-if(ABSL_INTERNAL_AT_LEAST_CXX17)
- set(ABSL_INTERNAL_CXX_STD_FEATURE cxx_std_17)
-else()
- set(ABSL_INTERNAL_CXX_STD_FEATURE cxx_std_14)
-endif()
-
# absl_cc_library()
#
# CMake function to imitate Bazel's cc_library rule.
@@ -297,9 +268,9 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
endif()
if(ABSL_PROPAGATE_CXX_STD)
- # 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.
+ # Abseil libraries require C++14 as the current minimum standard. When
+ # compiled with C++17 (either because it is the compiler's default or
+ # explicitly requested), then Abseil requires C++17.
_absl_target_compile_features_if_available(${_NAME} PUBLIC ${ABSL_INTERNAL_CXX_STD_FEATURE})
else()
# Note: This is legacy (before CMake 3.8) behavior. Setting the