summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2022-09-06 13:11:28 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2022-09-06 13:12:23 -0700
commit308bbf300fe9332130f4784c7a91fa2ad707d6e4 (patch)
treeaeb8bd89fc3891ada12b6c4dbbf2425f8e37d983 /CMakeLists.txt
parentd3c00b06b334311e23ab18f5d2b90938a07ce35d (diff)
CMake: install artifacts reflect the compiled ABI
Change `absl/base/options.h` at install time to reflect the ABI used to compile the libraries, i.e., if Abseil was compiled with C++ >= 17 then the `ABSL_OPTION_USE_STD_*` macros are set to `1`, because then the C++ 17 types are embedded in the ABI of the installed artifacts. Likewise, set the `target_compile_features()` of Abseil libraries to reflect the C++ version used to compile them. If they the Abseil libraries are compiled with C++ >= 17, then all downstream dependencies must also be compiled with C++ >= 17. Fixes #696 PiperOrigin-RevId: 472538165 Change-Id: Ic9e346ebe277c882a18ad96e1918c9e3511c91c3
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt26
1 files changed, 26 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 706af68a..016dd917 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,6 +46,11 @@ if (POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif (POLICY CMP0091)
+# try_compile() honors the CMAKE_CXX_STANDARD value
+if (POLICY CMP0067)
+ cmake_policy(SET CMP0067 NEW)
+endif (POLICY CMP0067)
+
project(absl LANGUAGES CXX)
include(CTest)
@@ -229,4 +234,25 @@ if(ABSL_ENABLE_INSTALL)
PATTERN "copts" EXCLUDE
PATTERN "testdata" EXCLUDE
)
+
+ 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"
+ 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"
+ ABSL_INTERNAL_OPTIONS_H_PINNED
+ "${ABSL_INTERNAL_OPTIONS_H_CONTENTS}")
+ endif()
+ file(WRITE "${CMAKE_BINARY_DIR}/options-pinned.h" "${ABSL_INTERNAL_OPTIONS_H_PINNED}")
+
+ install(FILES "${CMAKE_BINARY_DIR}/options-pinned.h"
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/absl/base
+ RENAME "options.h")
+
endif() # ABSL_ENABLE_INSTALL