-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Step one towards merging timer changes. #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,93 +1,62 @@ | ||
| cmake_minimum_required (VERSION 2.8) | ||
| project (benchmark) | ||
|
|
||
| option(BENCHMARK_ENABLE_SHARED "Enable building a shared library." OFF) | ||
| option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." ON) | ||
| # Make sure we can import out CMake functions | ||
| list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") | ||
|
|
||
| # Import and build Google Test | ||
| include(ExternalProject) | ||
| set_directory_properties(properties EP_PREFIX "${CMAKE_BINARY_DIR}/third_party") | ||
| ExternalProject_Add(googletest | ||
| URL "https://googletest.googlecode.com/files/gtest-1.7.0.zip" | ||
| URL_MD5 2d6ec8ccdf5c46b05ba54a9fd1d130d7 | ||
| SOURCE_DIR "${CMAKE_BINARY_DIR}/third_party/gtest" | ||
| CMAKE_ARGS "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" | ||
| INSTALL_COMMAND "") | ||
| ExternalProject_Get_Property(googletest source_dir) | ||
| include_directories(${source_dir}/include) | ||
| ExternalProject_Get_Property(googletest binary_dir) | ||
| link_directories(${binary_dir}) | ||
| # Read the git tags to determine the project version | ||
| include(GetGitVersion) | ||
| get_git_version(GIT_VERSION) | ||
|
|
||
| # Tell the user what versions we are using | ||
| string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" VERSION ${GIT_VERSION}) | ||
| message("-- Version: ${VERSION}") | ||
|
|
||
| # The version of the libraries | ||
| set(GENERIC_LIB_VERSION ${VERSION}) | ||
| string(SUBSTRING ${VERSION} 0 1 GENERIC_LIB_SOVERSION) | ||
|
|
||
| # Try and enable C++11. Don't use C++14 because it doesn't work in some | ||
| # configurations. | ||
| include(CheckCXXCompilerFlag) | ||
| check_cxx_compiler_flag(--std=c++11 HAVE_FLAG_CXX_11) | ||
| check_cxx_compiler_flag(--std=c++0x HAVE_FLAG_CXX_0X) | ||
| include(AddCXXCompilerFlag) | ||
| include(CXXFeatureCheck) | ||
|
|
||
| check_cxx_compiler_flag(-std=c++11 HAVE_FLAG_CXX_11) | ||
| check_cxx_compiler_flag(-std=c++0x HAVE_FLAG_CXX_0X) | ||
| if (HAVE_FLAG_CXX_11) | ||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11") | ||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") | ||
| elseif (HAVE_FLAG_CXX_0X) | ||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++0x") | ||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") | ||
| endif() | ||
|
|
||
| # Turn compiler warnings up to 11 | ||
| include(AddCXXCompilerFlag) | ||
| add_cxx_compiler_flag(-Wall) | ||
| add_cxx_compiler_flag(-Wextra) | ||
| add_cxx_compiler_flag(-Wshadow) | ||
| add_cxx_compiler_flag(-Werror) | ||
| add_cxx_compiler_flag(-pedantic-errors) | ||
| # TODO(ericwf): enable this for g++ | ||
| #add_cxx_compiler_flag(-Wzero-as-null-pointer-constant) | ||
|
|
||
| # Release flags | ||
| add_cxx_compiler_flag(-fno-strict-aliasing RELEASE) | ||
|
|
||
| # Add a debug definition so we can make decisions in the compilation | ||
| set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") | ||
|
|
||
| # Set OS | ||
| if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") | ||
| add_definitions(-DOS_MACOSX) | ||
| endif() | ||
|
|
||
| if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") | ||
| add_definitions(-DOS_LINUX) | ||
| endif() | ||
|
|
||
| if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") | ||
| add_definitions(-DOS_WINDOWS) | ||
| endif() | ||
|
|
||
| if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") | ||
| add_definitions(-DOS_FREEBSD) | ||
| endif() | ||
|
|
||
| # Set CPU | ||
| if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86") | ||
| add_definitions(-DARCH_X86) | ||
| endif() | ||
|
|
||
| # Read the git tags to determine the project version | ||
| include(GetGitVersion) | ||
| get_git_version(GIT_VERSION) | ||
|
|
||
| # Tell the user what versions we are using | ||
| string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" VERSION ${GIT_VERSION}) | ||
| message("-- Version: ${VERSION}") | ||
|
|
||
| # The version of the libraries | ||
| set(GENERIC_LIB_VERSION ${VERSION}) | ||
| string(SUBSTRING ${VERSION} 0 1 GENERIC_LIB_SOVERSION) | ||
| add_cxx_compiler_flag(-Wthread-safety) | ||
|
|
||
| # C++ feature checks | ||
| include(CXXFeatureCheck) | ||
| cxx_feature_check(STD_REGEX) | ||
| cxx_feature_check(GNU_POSIX_REGEX) | ||
| cxx_feature_check(POSIX_REGEX) | ||
|
|
||
| # Set up directories | ||
| include_directories(${PROJECT_SOURCE_DIR}/include) | ||
| include_directories(${PROJECT_SOURCE_DIR}/src) | ||
|
|
||
| # Build the targets | ||
| enable_testing() | ||
| add_subdirectory(src) | ||
| add_subdirectory(test) | ||
|
|
||
| if (BENCHMARK_ENABLE_TESTING) | ||
| enable_testing() | ||
| add_subdirectory(test) | ||
| endif() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,51 +1,44 @@ | ||
| // Copyright 2015 Google Inc. All rights reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| #ifndef BENCHMARK_MACROS_H_ | ||
| #define BENCHMARK_MACROS_H_ | ||
|
|
||
| #include <assert.h> | ||
| #include <stddef.h> | ||
|
|
||
| #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ | ||
| TypeName(const TypeName&); \ | ||
| void operator=(const TypeName&); | ||
|
|
||
| // The arraysize(arr) macro returns the # of elements in an array arr. | ||
| // The expression is a compile-time constant, and therefore can be | ||
| // used in defining new arrays, for example. If you use arraysize on | ||
| // a pointer by mistake, you will get a compile-time error. | ||
| // | ||
| // One caveat is that, for C++03, arraysize() doesn't accept any array of | ||
| // an anonymous type or a type defined inside a function. In these rare | ||
| // cases, you have to use the unsafe ARRAYSIZE() macro below. This is | ||
| // due to a limitation in C++03's template system. The limitation has | ||
| // been removed in C++11. | ||
|
|
||
| // This template function declaration is used in defining arraysize. | ||
| // Note that the function doesn't need an implementation, as we only | ||
| // use its type. | ||
| template <typename T, size_t N> | ||
| char (&ArraySizeHelper(T (&array)[N]))[N]; | ||
|
|
||
| // That gcc wants both of these prototypes seems mysterious. VC, for | ||
| // its part, can't decide which to use (another mystery). Matching of | ||
| // template overloads: the final frontier. | ||
| #ifndef COMPILER_MSVC | ||
| template <typename T, size_t N> | ||
| char (&ArraySizeHelper(const T (&array)[N]))[N]; | ||
| #if __cplusplus < 201103L | ||
| # define BENCHMARK_DISALLOW_COPY_AND_ASSIGN(TypeName) \ | ||
| TypeName(const TypeName&); \ | ||
| TypeName& operator=(const TypeName&) | ||
| #else | ||
| # define BENCHMARK_DISALLOW_COPY_AND_ASSIGN(TypeName) \ | ||
| TypeName(const TypeName&) = delete; \ | ||
| TypeName& operator=(const TypeName&) = delete | ||
| #endif | ||
|
|
||
| #define arraysize(array) (sizeof(ArraySizeHelper(array))) | ||
|
|
||
| // | ||
| // Prevent the compiler from complaining about or optimizing away variables | ||
| // that appear unused. | ||
| #define ATTRIBUTE_UNUSED __attribute__((unused)) | ||
| #if defined(__GNUC__) | ||
| # define BENCHMARK_UNUSED __attribute__((unused)) | ||
| # define BENCHMARK_ALWAYS_INLINE __attribute__((always_inline)) | ||
| #elif defined(_MSC_VER) && !defined(__clang__) | ||
| # define BENCHMARK_UNUSED | ||
| # define BENCHMARK_ALWAYS_INLINE __forceinline | ||
| #else | ||
| # define BENCHMARK_UNUSED | ||
| # define BENCHMARK_ALWAYS_INLINE | ||
| #endif | ||
|
|
||
| // | ||
| // For functions we want to force inline or not inline. | ||
| // Introduced in gcc 3.1. | ||
| #define ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline)) | ||
| #define HAVE_ATTRIBUTE_ALWAYS_INLINE 1 | ||
| #define ATTRIBUTE_NOINLINE __attribute__((noinline)) | ||
| #define HAVE_ATTRIBUTE_NOINLINE 1 | ||
| #if defined(__GNUC__) | ||
| # define BENCHMARK_BUILTIN_EXPECT(x, y) __builtin_expect(x, y) | ||
| #else | ||
| # define BENCHMARK_BUILTIN_EXPECT(x, y) x | ||
| #endif | ||
|
|
||
| #endif // BENCHMARK_MACROS_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #ifndef BENCHMARK_ARRAYSIZE_H_ | ||
| #define BENCHMARK_ARRAYSIZE_H_ | ||
|
|
||
| #include <cstddef> | ||
|
|
||
| #include "internal_macros.h" | ||
|
|
||
| namespace benchmark { | ||
| namespace internal { | ||
| // The arraysize(arr) macro returns the # of elements in an array arr. | ||
| // The expression is a compile-time constant, and therefore can be | ||
| // used in defining new arrays, for example. If you use arraysize on | ||
| // a pointer by mistake, you will get a compile-time error. | ||
| // | ||
|
|
||
|
|
||
| // This template function declaration is used in defining arraysize. | ||
| // Note that the function doesn't need an implementation, as we only | ||
| // use its type. | ||
| template <typename T, size_t N> | ||
| char (&ArraySizeHelper(T (&array)[N]))[N]; | ||
|
|
||
| // That gcc wants both of these prototypes seems mysterious. VC, for | ||
| // its part, can't decide which to use (another mystery). Matching of | ||
| // template overloads: the final frontier. | ||
| #ifndef COMPILER_MSVC | ||
| template <typename T, size_t N> | ||
| char (&ArraySizeHelper(const T (&array)[N]))[N]; | ||
| #endif | ||
|
|
||
| #define arraysize(array) (sizeof(::benchmark::internal::ArraySizeHelper(array))) | ||
|
|
||
| } // end namespace internal | ||
| } // end namespace benchmark | ||
|
|
||
| #endif // BENCHMARK_ARRAYSIZE_H_ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason why you moved this up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I felt like it didn't make sense that it lived between the
add_cxx_compiler_flag(...)andcxx_feature_check(...)blocks. Those seem to be logically related to each other and setting the SO version there seemed out of place.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM