Skip to content
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

Add benchmark/1.5.0 #174

Merged
merged 1 commit into from Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions recipes/benchmark/all/CMakeLists.txt
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 2.8.12)
project(cmake_wrapper)

if(EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
else()
include(conanbuildinfo.cmake)
endif()
conan_basic_setup()

add_subdirectory("source_subfolder")
4 changes: 4 additions & 0 deletions recipes/benchmark/all/conandata.yml
@@ -0,0 +1,4 @@
sources:
"1.5.0":
sha256: 3c6a165b6ecc948967a1ead710d4a181d7b0fbcaa183ef7ea84604994966221a
url: https://github.com/google/benchmark/archive/v1.5.0.tar.gz
81 changes: 81 additions & 0 deletions recipes/benchmark/all/conanfile.py
@@ -0,0 +1,81 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os


class BenchmarkConan(ConanFile):
name = "benchmark"
description = "A microbenchmark support library."
topics = ("conan", "benchmark", "google", "microbenchmark")
url = "https://github.com/conan-io/conan-center-index/"
homepage = "https://github.com/google/benchmark"
license = "Apache-2.0"
exports_sources = ["CMakeLists.txt"]
generators = "cmake"

settings = "arch", "build_type", "compiler", "os"
options = {
"shared": [True, False],
"fPIC": [True, False],
"enable_lto": [True, False],
"enable_exceptions": [True, False]
}
default_options = {"shared": False, "fPIC": True, "enable_lto": False, "enable_exceptions": True}

_source_subfolder = "source_subfolder"
_build_subfolder = "build_subfolder"

def source(self):
tools.get(**self.conan_data["sources"][self.version])

extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)

def config_options(self):
if self.settings.os == "Windows":
if self.settings.compiler == "Visual Studio" and tools.Version(self.settings.compiler.version.value) <= 12:
raise ConanInvalidConfiguration("{} {} does not support Visual Studio <= 12".format(self.name, self.version))
del self.options.fPIC

def configure(self):
if self.settings.os == "Windows" and self.options.shared:
raise ConanInvalidConfiguration("Windows shared builds are not supported right now, see issue #639")

def _configure_cmake(self):
cmake = CMake(self)

cmake.definitions["BENCHMARK_ENABLE_TESTING"] = "OFF"
cmake.definitions["BENCHMARK_ENABLE_GTEST_TESTS"] = "OFF"
cmake.definitions["BENCHMARK_ENABLE_LTO"] = "ON" if self.options.enable_lto else "OFF"
cmake.definitions["BENCHMARK_ENABLE_EXCEPTIONS"] = "ON" if self.options.enable_exceptions else "OFF"

# See https://github.com/google/benchmark/pull/638 for Windows 32 build explanation
if self.settings.os != "Windows":
cmake.definitions["BENCHMARK_BUILD_32_BITS"] = "ON" if "64" not in str(self.settings.arch) else "OFF"
cmake.definitions["BENCHMARK_USE_LIBCXX"] = "ON" if (str(self.settings.compiler.libcxx) == "libc++") else "OFF"
else:
cmake.definitions["BENCHMARK_USE_LIBCXX"] = "OFF"

cmake.configure(build_folder=self._build_subfolder)
return cmake

def build(self):
cmake = self._configure_cmake()
cmake.build()

def package(self):
cmake = self._configure_cmake()
cmake.install()

self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
tools.rmdir(os.path.join(self.package_folder, 'lib', 'pkgconfig'))
tools.rmdir(os.path.join(self.package_folder, 'lib', 'cmake'))

def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
if self.settings.os == "Linux":
self.cpp_info.libs.extend(["pthread", "rt"])
elif self.settings.os == "Windows":
self.cpp_info.libs.append("shlwapi")
elif self.settings.os == "SunOS":
self.cpp_info.libs.append("kstat")
10 changes: 10 additions & 0 deletions recipes/benchmark/all/test_package/CMakeLists.txt
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 2.8.12)
project(test_package)

set(CMAKE_VERBOSE_MAKEFILE TRUE)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
17 changes: 17 additions & 0 deletions recipes/benchmark/all/test_package/conanfile.py
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
18 changes: 18 additions & 0 deletions recipes/benchmark/all/test_package/test_package.cpp
@@ -0,0 +1,18 @@
#include "benchmark/benchmark.h"

void BM_StringCreation(benchmark::State& state) {
while (state.KeepRunning())
std::string empty_string;
}

BENCHMARK(BM_StringCreation);

void BM_StringCopy(benchmark::State& state) {
std::string x = "hello";
while (state.KeepRunning())
std::string copy(x);
}

BENCHMARK(BM_StringCopy);

BENCHMARK_MAIN();
3 changes: 3 additions & 0 deletions recipes/benchmark/config.yml
@@ -0,0 +1,3 @@
versions:
"1.5.0":
folder: all