Commit bcce85ef by Derek Mauro Committed by Copybara-Service

Fix CMake compiled ABI options after f845e60a.

f845e60a added an option to use C++20's
<ordering> header but the CMake install configured this as an alias
in C++17 when it is not available.

Fixes #1597

PiperOrigin-RevId: 597258569
Change-Id: I40277d55702601e1686370bee6af9b7491fd2000
parent bddf28e9
...@@ -627,17 +627,32 @@ include(CheckCXXSourceCompiles) ...@@ -627,17 +627,32 @@ include(CheckCXXSourceCompiles)
check_cxx_source_compiles( check_cxx_source_compiles(
[==[ [==[
#ifdef _MSC_VER #ifdef _MSC_VER
# if _MSVC_LANG < 201700L # if _MSVC_LANG < 201703L
# error "The compiler defaults or is configured for C++ < 17" # error "The compiler defaults or is configured for C++ < 17"
# endif # endif
#elif __cplusplus < 201700L #elif __cplusplus < 201703L
# error "The compiler defaults or is configured for C++ < 17" # error "The compiler defaults or is configured for C++ < 17"
#endif #endif
int main() { return 0; } int main() { return 0; }
]==] ]==]
ABSL_INTERNAL_AT_LEAST_CXX17) ABSL_INTERNAL_AT_LEAST_CXX17)
if(ABSL_INTERNAL_AT_LEAST_CXX17) check_cxx_source_compiles(
[==[
#ifdef _MSC_VER
# if _MSVC_LANG < 202002L
# error "The compiler defaults or is configured for C++ < 20"
# endif
#elif __cplusplus < 202002L
# error "The compiler defaults or is configured for C++ < 20"
#endif
int main() { return 0; }
]==]
ABSL_INTERNAL_AT_LEAST_CXX20)
if(ABSL_INTERNAL_AT_LEAST_CXX20)
set(ABSL_INTERNAL_CXX_STD_FEATURE cxx_std_20)
elseif(ABSL_INTERNAL_AT_LEAST_CXX17)
set(ABSL_INTERNAL_CXX_STD_FEATURE cxx_std_17) set(ABSL_INTERNAL_CXX_STD_FEATURE cxx_std_17)
else() else()
set(ABSL_INTERNAL_CXX_STD_FEATURE cxx_std_14) set(ABSL_INTERNAL_CXX_STD_FEATURE cxx_std_14)
...@@ -807,8 +822,8 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n") ...@@ -807,8 +822,8 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
if(ABSL_PROPAGATE_CXX_STD) if(ABSL_PROPAGATE_CXX_STD)
# Abseil libraries require C++14 as the current minimum standard. When # Abseil libraries require C++14 as the current minimum standard. When
# compiled with C++17 (either because it is the compiler's default or # compiled with a higher minimum (either because it is the compiler's
# explicitly requested), then Abseil requires C++17. # default or explicitly requested), then Abseil requires that standard.
target_compile_features(${_dll} PUBLIC ${ABSL_INTERNAL_CXX_STD_FEATURE}) target_compile_features(${_dll} PUBLIC ${ABSL_INTERNAL_CXX_STD_FEATURE})
endif() endif()
......
...@@ -287,8 +287,8 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n") ...@@ -287,8 +287,8 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
if(ABSL_PROPAGATE_CXX_STD) if(ABSL_PROPAGATE_CXX_STD)
# Abseil libraries require C++14 as the current minimum standard. When # Abseil libraries require C++14 as the current minimum standard. When
# compiled with C++17 (either because it is the compiler's default or # compiled with a higher standard (either because it is the compiler's
# explicitly requested), then Abseil requires C++17. # default or explicitly requested), then Abseil requires that standard.
target_compile_features(${_NAME} PUBLIC ${ABSL_INTERNAL_CXX_STD_FEATURE}) target_compile_features(${_NAME} PUBLIC ${ABSL_INTERNAL_CXX_STD_FEATURE})
endif() endif()
......
...@@ -236,20 +236,41 @@ if(ABSL_ENABLE_INSTALL) ...@@ -236,20 +236,41 @@ if(ABSL_ENABLE_INSTALL)
PATTERN "testdata" EXCLUDE PATTERN "testdata" EXCLUDE
) )
# Rewrite options.h to use the compiled ABI.
file(READ "absl/base/options.h" ABSL_INTERNAL_OPTIONS_H_CONTENTS) file(READ "absl/base/options.h" ABSL_INTERNAL_OPTIONS_H_CONTENTS)
if (ABSL_INTERNAL_AT_LEAST_CXX17)
string(REGEX REPLACE # Handle features that require at least C++20.
"#define ABSL_OPTION_USE_STD_([^ ]*) 2" if (ABSL_INTERNAL_AT_LEAST_CXX20)
"#define ABSL_OPTION_USE_STD_\\1 1" foreach(FEATURE "ORDERING")
string(REPLACE
"#define ABSL_OPTION_USE_STD_${FEATURE} 2"
"#define ABSL_OPTION_USE_STD_${FEATURE} 1"
ABSL_INTERNAL_OPTIONS_H_PINNED ABSL_INTERNAL_OPTIONS_H_PINNED
"${ABSL_INTERNAL_OPTIONS_H_CONTENTS}") "${ABSL_INTERNAL_OPTIONS_H_CONTENTS}")
else() set(ABSL_INTERNAL_OPTIONS_H_CONTENTS "${ABSL_INTERNAL_OPTIONS_H_PINNED}")
string(REGEX REPLACE endforeach()
"#define ABSL_OPTION_USE_STD_([^ ]*) 2" endif()
"#define ABSL_OPTION_USE_STD_\\1 0"
# Handle features that require at least C++17.
if (ABSL_INTERNAL_AT_LEAST_CXX17)
foreach(FEATURE "ANY" "OPTIONAL" "STRING_VIEW" "VARIANT")
string(REPLACE
"#define ABSL_OPTION_USE_STD_${FEATURE} 2"
"#define ABSL_OPTION_USE_STD_${FEATURE} 1"
ABSL_INTERNAL_OPTIONS_H_PINNED ABSL_INTERNAL_OPTIONS_H_PINNED
"${ABSL_INTERNAL_OPTIONS_H_CONTENTS}") "${ABSL_INTERNAL_OPTIONS_H_CONTENTS}")
set(ABSL_INTERNAL_OPTIONS_H_CONTENTS "${ABSL_INTERNAL_OPTIONS_H_PINNED}")
endforeach()
endif() endif()
# Any feature that still has the value of 2 (because it was not handled above)
# should be set to 0.
string(REGEX REPLACE
"#define ABSL_OPTION_USE_STD_([^ ]*) 2"
"#define ABSL_OPTION_USE_STD_\\1 0"
ABSL_INTERNAL_OPTIONS_H_PINNED
"${ABSL_INTERNAL_OPTIONS_H_CONTENTS}")
file(WRITE "${CMAKE_BINARY_DIR}/options-pinned.h" "${ABSL_INTERNAL_OPTIONS_H_PINNED}") file(WRITE "${CMAKE_BINARY_DIR}/options-pinned.h" "${ABSL_INTERNAL_OPTIONS_H_PINNED}")
install(FILES "${CMAKE_BINARY_DIR}/options-pinned.h" install(FILES "${CMAKE_BINARY_DIR}/options-pinned.h"
......
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