Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
benchmark
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
benchmark
Commits
efd4e992
Commit
efd4e992
authored
Dec 05, 2016
by
Eric
Committed by
Dominic Hamon
Dec 05, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for building w/o exceptions (#317)
parent
a3eac442
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
2 deletions
+32
-2
CMakeLists.txt
CMakeLists.txt
+12
-1
internal_macros.h
src/internal_macros.h
+5
-0
re.h
src/re.h
+15
-1
No files found.
CMakeLists.txt
View file @
efd4e992
...
@@ -11,6 +11,7 @@ foreach(p
...
@@ -11,6 +11,7 @@ foreach(p
endforeach
()
endforeach
()
option
(
BENCHMARK_ENABLE_TESTING
"Enable testing of the benchmark library."
ON
)
option
(
BENCHMARK_ENABLE_TESTING
"Enable testing of the benchmark library."
ON
)
option
(
BENCHMARK_ENABLE_EXCEPTIONS
"Enable the use of exceptions in the benchmark library."
ON
)
option
(
BENCHMARK_ENABLE_LTO
"Enable link time optimisation of the benchmark library."
OFF
)
option
(
BENCHMARK_ENABLE_LTO
"Enable link time optimisation of the benchmark library."
OFF
)
option
(
BENCHMARK_USE_LIBCXX
"Build and test using libc++ as the standard library."
OFF
)
option
(
BENCHMARK_USE_LIBCXX
"Build and test using libc++ as the standard library."
OFF
)
# Make sure we can import out CMake functions
# Make sure we can import out CMake functions
...
@@ -39,6 +40,10 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
...
@@ -39,6 +40,10 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
/W4"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
/W4"
)
add_definitions
(
-D_CRT_SECURE_NO_WARNINGS
)
add_definitions
(
-D_CRT_SECURE_NO_WARNINGS
)
if
(
NOT BENCHMARK_ENABLE_EXCEPTIONS
)
add_cxx_compiler_flag
(
-EHs-
)
add_cxx_compiler_flag
(
-EHa-
)
endif
()
# Link time optimisation
# Link time optimisation
if
(
BENCHMARK_ENABLE_LTO
)
if
(
BENCHMARK_ENABLE_LTO
)
set
(
CMAKE_CXX_FLAGS_RELEASE
"
${
CMAKE_CXX_FLAGS_RELEASE
}
/GL"
)
set
(
CMAKE_CXX_FLAGS_RELEASE
"
${
CMAKE_CXX_FLAGS_RELEASE
}
/GL"
)
...
@@ -80,6 +85,9 @@ else()
...
@@ -80,6 +85,9 @@ else()
add_cxx_compiler_flag
(
-Wshorten-64-to-32
)
add_cxx_compiler_flag
(
-Wshorten-64-to-32
)
add_cxx_compiler_flag
(
-Wfloat-equal
)
add_cxx_compiler_flag
(
-Wfloat-equal
)
add_cxx_compiler_flag
(
-fstrict-aliasing
)
add_cxx_compiler_flag
(
-fstrict-aliasing
)
if
(
NOT BENCHMARK_ENABLE_EXCEPTIONS
)
add_cxx_compiler_flag
(
-fno-exceptions
)
endif
()
if
(
NOT BENCHMARK_USE_LIBCXX
)
if
(
NOT BENCHMARK_USE_LIBCXX
)
add_cxx_compiler_flag
(
-Wzero-as-null-pointer-constant
)
add_cxx_compiler_flag
(
-Wzero-as-null-pointer-constant
)
endif
()
endif
()
...
@@ -162,7 +170,10 @@ cxx_feature_check(POSIX_REGEX)
...
@@ -162,7 +170,10 @@ cxx_feature_check(POSIX_REGEX)
if
(
NOT HAVE_STD_REGEX AND NOT HAVE_GNU_POSIX_REGEX AND NOT HAVE_POSIX_REGEX
)
if
(
NOT HAVE_STD_REGEX AND NOT HAVE_GNU_POSIX_REGEX AND NOT HAVE_POSIX_REGEX
)
message
(
FATAL_ERROR
"Failed to determine the source files for the regular expression backend"
)
message
(
FATAL_ERROR
"Failed to determine the source files for the regular expression backend"
)
endif
()
endif
()
if
(
NOT BENCHMARK_ENABLE_EXCEPTIONS AND HAVE_STD_REGEX
AND NOT HAVE_GNU_POSIX_REGEX AND NOT HAVE_POSIX_REGEX
)
message
(
WARNING
"Using std::regex with exceptions disabled is not fully supported"
)
endif
()
cxx_feature_check
(
STEADY_CLOCK
)
cxx_feature_check
(
STEADY_CLOCK
)
# Ensure we have pthreads
# Ensure we have pthreads
find_package
(
Threads REQUIRED
)
find_package
(
Threads REQUIRED
)
...
...
src/internal_macros.h
View file @
efd4e992
...
@@ -39,4 +39,9 @@
...
@@ -39,4 +39,9 @@
#define BENCHMARK_OS_LINUX 1
#define BENCHMARK_OS_LINUX 1
#endif
#endif
#if !__has_feature(cxx_exceptions) && !defined(__cpp_exceptions) \
&& !defined(__EXCEPTIONS)
#define BENCHMARK_HAS_NO_EXCEPTIONS
#endif
#endif // BENCHMARK_INTERNAL_MACROS_H_
#endif // BENCHMARK_INTERNAL_MACROS_H_
src/re.h
View file @
efd4e992
...
@@ -15,6 +15,15 @@
...
@@ -15,6 +15,15 @@
#ifndef BENCHMARK_RE_H_
#ifndef BENCHMARK_RE_H_
#define BENCHMARK_RE_H_
#define BENCHMARK_RE_H_
#include "internal_macros.h"
// 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) && \
(defined(HAVE_GNU_POSIX_REGEX) || defined(HAVE_POSIX_REGEX))
#undef HAVE_STD_REGEX
#endif
#if defined(HAVE_STD_REGEX)
#if defined(HAVE_STD_REGEX)
#include <regex>
#include <regex>
#elif defined(HAVE_GNU_POSIX_REGEX)
#elif defined(HAVE_GNU_POSIX_REGEX)
...
@@ -62,15 +71,20 @@ class Regex {
...
@@ -62,15 +71,20 @@ class Regex {
#if defined(HAVE_STD_REGEX)
#if defined(HAVE_STD_REGEX)
inline
bool
Regex
::
Init
(
const
std
::
string
&
spec
,
std
::
string
*
error
)
{
inline
bool
Regex
::
Init
(
const
std
::
string
&
spec
,
std
::
string
*
error
)
{
#ifdef BENCHMARK_HAS_NO_EXCEPTIONS
((
void
)
error
);
// suppress unused warning
#else
try
{
try
{
#endif
re_
=
std
::
regex
(
spec
,
std
::
regex_constants
::
extended
);
re_
=
std
::
regex
(
spec
,
std
::
regex_constants
::
extended
);
init_
=
true
;
init_
=
true
;
#ifndef BENCHMARK_HAS_NO_EXCEPTIONS
}
catch
(
const
std
::
regex_error
&
e
)
{
}
catch
(
const
std
::
regex_error
&
e
)
{
if
(
error
)
{
if
(
error
)
{
*
error
=
e
.
what
();
*
error
=
e
.
what
();
}
}
}
}
#endif
return
init_
;
return
init_
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment