summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorGravatar Derek Mauro <dmauro@google.com>2024-01-10 08:32:46 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2024-01-10 08:33:52 -0800
commitbcce85ef8d9042794a50e4afbbd2c672121ab0d2 (patch)
treed9313345d2884610a965474092ecdd96d9932197 /CMakeLists.txt
parentbddf28e9230364e45637a4a8725387d57fdfb79c (diff)
Fix CMake compiled ABI options after f845e60acd880dbf07788a5a2c0dbad0f9c57231.
f845e60acd880dbf07788a5a2c0dbad0f9c57231 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
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt37
1 files changed, 29 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ca74b80d..87f8ae82 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -236,20 +236,41 @@ if(ABSL_ENABLE_INSTALL)
PATTERN "testdata" EXCLUDE
)
+ # Rewrite options.h to use the compiled ABI.
file(READ "absl/base/options.h" ABSL_INTERNAL_OPTIONS_H_CONTENTS)
- if (ABSL_INTERNAL_AT_LEAST_CXX17)
- string(REGEX REPLACE
- "#define ABSL_OPTION_USE_STD_([^ ]*) 2"
- "#define ABSL_OPTION_USE_STD_\\1 1"
+
+ # Handle features that require at least C++20.
+ if (ABSL_INTERNAL_AT_LEAST_CXX20)
+ 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_CONTENTS}")
- else()
- string(REGEX REPLACE
- "#define ABSL_OPTION_USE_STD_([^ ]*) 2"
- "#define ABSL_OPTION_USE_STD_\\1 0"
+ set(ABSL_INTERNAL_OPTIONS_H_CONTENTS "${ABSL_INTERNAL_OPTIONS_H_PINNED}")
+ endforeach()
+ endif()
+
+ # 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_CONTENTS}")
+ set(ABSL_INTERNAL_OPTIONS_H_CONTENTS "${ABSL_INTERNAL_OPTIONS_H_PINNED}")
+ endforeach()
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}")
install(FILES "${CMAKE_BINARY_DIR}/options-pinned.h"