mirror of https://github.com/google/benchmark.git
Rely on compiler intrinsics to identify regex engine. (#555)
Having the copts set on a per-target level can lead to ODR violations in some cases. Avoid this by ensuring the regex engine is picked through compiler intrinsics in the header directly.
This commit is contained in:
parent
e668e2a1ba
commit
df60aeb266
|
@ -1,7 +1,5 @@
|
|||
licenses(["notice"])
|
||||
|
||||
load("//bazel:have_regex.bzl", "have_regex_copts")
|
||||
|
||||
cc_library(
|
||||
name = "benchmark",
|
||||
srcs = glob([
|
||||
|
@ -9,7 +7,6 @@ cc_library(
|
|||
"src/*.h",
|
||||
]),
|
||||
hdrs = ["include/benchmark/benchmark.h"],
|
||||
copts = have_regex_copts(),
|
||||
strip_include_prefix = "include",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
16
bazel/BUILD
16
bazel/BUILD
|
@ -1,16 +0,0 @@
|
|||
package(default_visibility = ["//:__subpackages__"])
|
||||
|
||||
config_setting(
|
||||
name = "have_std_regex",
|
||||
values = {"define": "google_benchmark.have_regex=std"},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "have_posix_regex",
|
||||
values = {"define": "google_benchmark.have_regex=posix"},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "have_gnu_posix_regex",
|
||||
values = {"define": "google_benchmark.have_regex=gnu_posix"},
|
||||
)
|
|
@ -1,7 +0,0 @@
|
|||
def have_regex_copts():
|
||||
return select({
|
||||
"//bazel:have_std_regex": ["-DHAVE_STD_REGEX"],
|
||||
"//bazel:have_posix_regex": ["-DHAVE_POSIX_REGEX"],
|
||||
"//bazel:have_gnu_posix_regex": ["-DHAVE_GNU_POSIX_REGEX"],
|
||||
"//conditions:default": ["-DHAVE_STD_REGEX"],
|
||||
})
|
|
@ -39,6 +39,7 @@
|
|||
#elif defined(_WIN32)
|
||||
#define BENCHMARK_OS_WINDOWS 1
|
||||
#elif defined(__APPLE__)
|
||||
#define BENCHMARK_OS_APPLE 1
|
||||
#include "TargetConditionals.h"
|
||||
#if defined(TARGET_OS_MAC)
|
||||
#define BENCHMARK_OS_MACOSX 1
|
||||
|
|
14
src/re.h
14
src/re.h
|
@ -17,9 +17,21 @@
|
|||
|
||||
#include "internal_macros.h"
|
||||
|
||||
#if !defined(HAVE_STD_REGEX) && \
|
||||
!defined(HAVE_GNU_POSIX_REGEX) && \
|
||||
!defined(HAVE_POSIX_REGEX)
|
||||
// No explicit regex selection; detect based on builtin hints.
|
||||
#if defined(BENCHMARK_OS_LINUX) || defined(BENCHMARK_OS_APPLE)
|
||||
#define HAVE_POSIX_REGEX 1
|
||||
#elif __cplusplus >= 199711L
|
||||
#define HAVE_STD_REGEX 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Prefer C regex libraries when compiling w/o exceptions so that we can
|
||||
// correctly report errors.
|
||||
#if defined(BENCHMARK_HAS_NO_EXCEPTIONS) && defined(HAVE_STD_REGEX) && \
|
||||
#if defined(BENCHMARK_HAS_NO_EXCEPTIONS) && \
|
||||
defined(BENCHMARK_HAVE_STD_REGEX) && \
|
||||
(defined(HAVE_GNU_POSIX_REGEX) || defined(HAVE_POSIX_REGEX))
|
||||
#undef HAVE_STD_REGEX
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
load("//bazel:have_regex.bzl", "have_regex_copts")
|
||||
|
||||
NEEDS_GTEST_MAIN = [
|
||||
"statistics_test.cc",
|
||||
]
|
||||
|
@ -8,7 +6,7 @@ TEST_COPTS = [
|
|||
"-pedantic",
|
||||
"-pedantic-errors",
|
||||
"-std=c++11",
|
||||
] + have_regex_copts()
|
||||
]
|
||||
|
||||
TEST_ARGS = ["--benchmark_min_time=0.01"]
|
||||
|
||||
|
|
Loading…
Reference in New Issue