From ef7d51c8ebf6fdc10687b4e9eaa48c72461e771d Mon Sep 17 00:00:00 2001 From: "Attila M. Szilagyi" Date: Sun, 15 Sep 2019 10:25:32 -0700 Subject: Allow setting GOOGLETEST_PATH cmake argument. Fixes #867 (#868) In `cmake/GoogleTest.cmake`, GOOGLETEST_PATH is default-initialized, but that init forgot to account for the fact that the patch is explicitly supposed to be user-configurable. By passing `CACHE` to `set()` we avoid that error. --- cmake/GoogleTest.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/GoogleTest.cmake b/cmake/GoogleTest.cmake index fb7c6be..dd611fc 100644 --- a/cmake/GoogleTest.cmake +++ b/cmake/GoogleTest.cmake @@ -2,7 +2,7 @@ set(GOOGLETEST_PREFIX "${benchmark_BINARY_DIR}/third_party/googletest") configure_file(${benchmark_SOURCE_DIR}/cmake/GoogleTest.cmake.in ${GOOGLETEST_PREFIX}/CMakeLists.txt @ONLY) -set(GOOGLETEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/googletest") # Mind the quotes +set(GOOGLETEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/googletest" CACHE PATH "") # Mind the quotes execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" -DALLOW_DOWNLOADING_GOOGLETEST=${BENCHMARK_DOWNLOAD_DEPENDENCIES} -DGOOGLETEST_PATH:PATH=${GOOGLETEST_PATH} . RESULT_VARIABLE result -- cgit v1.2.3 From bf4f2ea0bd1180b34718ac26eb79b170a4f6290e Mon Sep 17 00:00:00 2001 From: sharpe5 Date: Mon, 16 Sep 2019 09:05:05 +0100 Subject: Addresses issue #634. (#866) * Update with instructions to build under Visual Studio Fixes Issue #634. I spent 3 days trying to build this library under Visual Studio 2017, only to discover on has to link to `Shlwapi.lib`. Became so frustrated with the docs that I added full build instructions for Visual Studio 2015, 2017 and Intel Comiler 2015 and 2019. * Update headings --- README.md | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index eb9374c..c9aea0f 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,8 @@ The following minimum versions are required to build the library: * Visual Studio 14 2015 * Intel 2015 Update 1 +See [Platform-Specific Build Instructions](#platform-specific-build-instructions). + ## Installation This describes the installation process using cmake. As pre-requisites, you'll @@ -190,7 +192,9 @@ Alternatively, link against the `benchmark_main` library and remove The compiled executable will run all benchmarks by default. Pass the `--help` flag for option information or see the guide below. -### Platform-specific instructions +## Platform Specific Build Instructions + +### Building with GCC When the library is built using GCC it is necessary to link with the pthread library due to how GCC implements `std::thread`. Failing to link to pthread will @@ -200,8 +204,34 @@ can link to pthread by adding `-pthread` to your linker command. Note, you can also use `-lpthread`, but there are potential issues with ordering of command line parameters if you use that. -If you're running benchmarks on Windows, the shlwapi library (`-lshlwapi`) is -also required. +### Building with Visual Studio 2015 or 2017 + +The `shlwapi` library (`-lshlwapi`) is required to support a call to `CPUInfo` which reads the registry. Either add `shlwapi.lib` under `[ Configuration Properties > Linker > Input ]`, or use the following: + +``` +// Alternatively, can add libraries using linker options. +#ifdef _WIN32 +#pragma comment ( lib, "Shlwapi.lib" ) +#ifdef _DEBUG +#pragma comment ( lib, "benchmarkd.lib" ) +#else +#pragma comment ( lib, "benchmark.lib" ) +#endif +#endif +``` + +Can also use the graphical version of CMake: +* Open `CMake GUI`. +* Under `Where to build the binaries`, same path as source plus `build`. +* Under `CMAKE_INSTALL_PREFIX`, same path as source plus `install`. +* Click `Configure`, `Generate`, `Open Project`. +* If build fails, try deleting entire directory and starting again, or unticking options to build less. + +### Building with Intel 2015 Update 1 or Intel System Studio Update 4 + +See instructions for building with Visual Studio. Once built, right click on the solution and change the build to Intel. + +### Building on Solaris If you're running benchmarks on solaris, you'll want the kstat library linked in too (`-lkstat`). -- cgit v1.2.3 From d2fc7fe6591393c2672f3ba011304b778e71c020 Mon Sep 17 00:00:00 2001 From: Geoffrey Martin-Noble Date: Fri, 20 Sep 2019 02:25:31 -0700 Subject: Guard ASSERT_THROWS checks with BENCHMARK_HAS_NO_EXCEPTIONS (#874) * Guard ASSERT_THROWS checks with BENCHMARK_HAS_NO_EXCEPTIONS This allows the test be run with exceptions turned off * Add myself to CONTRIBUTORS I don't need to be added to AUTHORS, as I am a Google employee --- CONTRIBUTORS | 1 + test/string_util_gtest.cc | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 5be6dc4..e44f6f6 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -41,6 +41,7 @@ Eugene Zhuk Evgeny Safronov Federico Ficarelli Felix Homann +Geoffrey Martin-Noble Hannes Hauswedell Ismael Jimenez Martinez Jern-Kuan Leong diff --git a/test/string_util_gtest.cc b/test/string_util_gtest.cc index 2c5d073..01bf155 100644 --- a/test/string_util_gtest.cc +++ b/test/string_util_gtest.cc @@ -3,6 +3,7 @@ //===---------------------------------------------------------------------===// #include "../src/string_util.h" +#include "../src/internal_macros.h" #include "gtest/gtest.h" namespace { @@ -60,9 +61,11 @@ TEST(StringUtilTest, stoul) { EXPECT_EQ(0xBEEFul, benchmark::stoul("BEEF", &pos, 16)); EXPECT_EQ(4ul, pos); } +#ifndef BENCHMARK_HAS_NO_EXCEPTIONS { ASSERT_THROW(benchmark::stoul("this is a test"), std::invalid_argument); } +#endif } TEST(StringUtilTest, stoi) { @@ -106,9 +109,11 @@ TEST(StringUtilTest, stoi) { EXPECT_EQ(0xBEEF, benchmark::stoi("BEEF", &pos, 16)); EXPECT_EQ(4ul, pos); } +#ifndef BENCHMARK_HAS_NO_EXCEPTIONS { ASSERT_THROW(benchmark::stoi("this is a test"), std::invalid_argument); } +#endif } TEST(StringUtilTest, stod) { @@ -138,9 +143,11 @@ TEST(StringUtilTest, stod) { EXPECT_EQ(-1.25e+9, benchmark::stod("-1.25e+9", &pos)); EXPECT_EQ(8ul, pos); } +#ifndef BENCHMARK_HAS_NO_EXCEPTIONS { ASSERT_THROW(benchmark::stod("this is a test"), std::invalid_argument); } +#endif } } // end namespace -- cgit v1.2.3 From e7e3d976ef7d89ffc6bd6a53a6ea13ec35bb411d Mon Sep 17 00:00:00 2001 From: Colin Braley Date: Sat, 21 Sep 2019 13:55:05 -0700 Subject: Add missing parenthesis to code sample, and fix spacing. (#877) * Fix missing paren in README code sample, and fix code spacing. * Add Colin Braley to AUTHORS and CONTRIBUTORS. --- AUTHORS | 1 + CONTRIBUTORS | 3 ++- README.md | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/AUTHORS b/AUTHORS index c5e5c0c..35c4c8c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -14,6 +14,7 @@ Andriy Berestovskyy Arne Beer Carto Christopher Seymour +Colin Braley Daniel Harvey David Coeurjolly Deniz Evrenci diff --git a/CONTRIBUTORS b/CONTRIBUTORS index e44f6f6..6b64a00 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -29,6 +29,7 @@ Arne Beer Billy Robert O'Neal III Chris Kennelly Christopher Seymour +Colin Braley Cyrille Faucheux Daniel Harvey David Coeurjolly @@ -50,8 +51,8 @@ Joao Paulo Magalhaes John Millikin Jussi Knuuttila Kai Wolf -Kishan Kumar Kaito Udagawa +Kishan Kumar Lei Xu Matt Clarkson Maxim Vafin diff --git a/README.md b/README.md index c9aea0f..7eaa02a 100644 --- a/README.md +++ b/README.md @@ -873,7 +873,7 @@ static void MyMain(int size) { static void BM_OpenMP(benchmark::State& state) { for (auto _ : state) - MyMain(state.range(0); + MyMain(state.range(0)); } // Measure the time spent by the main thread, use it to decide for how long to @@ -950,7 +950,7 @@ static void BM_ManualTiming(benchmark::State& state) { auto start = std::chrono::high_resolution_clock::now(); // Simulate some useful workload with a sleep std::this_thread::sleep_for(sleep_duration); - auto end = std::chrono::high_resolution_clock::now(); + auto end = std::chrono::high_resolution_clock::now(); auto elapsed_seconds = std::chrono::duration_cast>( -- cgit v1.2.3 From 7411874d9563b18c56f8a81e02e77c6ffc5c3851 Mon Sep 17 00:00:00 2001 From: Geoffrey Martin-Noble Date: Mon, 23 Sep 2019 02:38:34 -0700 Subject: Define HOST_NAME_MAX for NaCl and RTEMS (#876) These OS's don't always have HOST_NAME_MAX defined, resulting in build errors. A few related changes as well: * Only define HOST_NAME_MAX if it's not already defined. There are some cases where this is already defined, e.g. with NaCl if __USE_POSIX is set. To avoid all of these, only define it if it's not already defined. * Default HOST_NAME_MAX to 64 and issue a #warning. Having the wrong max length is pretty harmless. The name just ends up getting truncated and this is only for printing debug info. Because we're constructing a std::string from a char[] (so defined length), we don't need to worry about gethostname's undefined behavior for whether the truncation is null-terminated when the hostname doesn't fit in HOST_NAME_MAX. Of course, this doesn't help people who have -Werror set, since they'll still get a warning. --- src/sysinfo.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/sysinfo.cc b/src/sysinfo.cc index 2812647..b5f99c7 100644 --- a/src/sysinfo.cc +++ b/src/sysinfo.cc @@ -429,11 +429,20 @@ std::string GetSystemName() { #endif return str; #else // defined(BENCHMARK_OS_WINDOWS) +#ifndef HOST_NAME_MAX #ifdef BENCHMARK_HAS_SYSCTL // BSD/Mac Doesnt have HOST_NAME_MAX defined #define HOST_NAME_MAX 64 +#elif defined(BENCHMARK_OS_NACL) +#define HOST_NAME_MAX 64 #elif defined(BENCHMARK_OS_QNX) #define HOST_NAME_MAX 154 +#elif defined(BENCHMARK_OS_RTEMS) +#define HOST_NAME_MAX 256 +#else +#warning "HOST_NAME_MAX not defined. using 64" +#define HOST_NAME_MAX 64 #endif +#endif // def HOST_NAME_MAX char hostname[HOST_NAME_MAX]; int retVal = gethostname(hostname, HOST_NAME_MAX); if (retVal != 0) return std::string(""); -- cgit v1.2.3 From b874e72208b6e21b62287942e5e3b11f6630107f Mon Sep 17 00:00:00 2001 From: Geoffrey Martin-Noble Date: Mon, 23 Sep 2019 02:53:09 -0700 Subject: Guard definition of __STDC_FORMAT_MACROS in ifndef (#875) This macro is sometimes already defined and redefining it results in build errors. --- src/benchmark_register.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/benchmark_register.cc b/src/benchmark_register.cc index 6696c38..cca39b2 100644 --- a/src/benchmark_register.cc +++ b/src/benchmark_register.cc @@ -34,7 +34,9 @@ #include #include +#ifndef __STDC_FORMAT_MACROS #define __STDC_FORMAT_MACROS +#endif #include #include "benchmark/benchmark.h" -- cgit v1.2.3 From b8bce0c7ed4e02426fa4de21fec385fbaa84a7b2 Mon Sep 17 00:00:00 2001 From: Chunsheng Pei Date: Fri, 27 Sep 2019 06:09:23 -0500 Subject: fixed the param order in g++ command and fixed the path for -L (#879) * fixed the param order in g++ command and fixed the path for -L * reorder the parameters for g++ command --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7eaa02a..a8aa276 100644 --- a/README.md +++ b/README.md @@ -182,8 +182,8 @@ library will be under the build directory you created. ```bash # Example on linux after running the build steps above. Assumes the # `benchmark` and `build` directories are under the current directory. -$ g++ -std=c++11 -isystem benchmark/include -Lbuild/src -lpthread \ - -lbenchmark mybenchmark.cc -o mybenchmark +$ g++ mybenchmark.cc -std=c++11 -isystem benchmark/include \ + -Lbenchmark/build/src -lbenchmark -lpthread -o mybenchmark ``` Alternatively, link against the `benchmark_main` library and remove -- cgit v1.2.3 From f4f5dba46bdbde0e95d736cca124025745bcd7b6 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Fri, 4 Oct 2019 04:50:53 -0400 Subject: Cache RUN_${FEATURE} variable in CXXFeatureCheck.cmake (#886) When cross-compiling, this variable was not set on the second run of CMake, resulting in the next check failing even though it shouldn't be run in the first place. Fix this by caching the variable. --- cmake/CXXFeatureCheck.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/CXXFeatureCheck.cmake b/cmake/CXXFeatureCheck.cmake index 99b56dd..059d510 100644 --- a/cmake/CXXFeatureCheck.cmake +++ b/cmake/CXXFeatureCheck.cmake @@ -37,9 +37,9 @@ function(cxx_feature_check FILE) if(COMPILE_${FEATURE}) message(WARNING "If you see build failures due to cross compilation, try setting HAVE_${VAR} to 0") - set(RUN_${FEATURE} 0) + set(RUN_${FEATURE} 0 CACHE INTERNAL "") else() - set(RUN_${FEATURE} 1) + set(RUN_${FEATURE} 1 CACHE INTERNAL "") endif() else() message(STATUS "Performing Test ${FEATURE}") -- cgit v1.2.3