Skip to content

Commit 29b7782

Browse files
authored
Merge 8fbe7fb into c9311a4
2 parents c9311a4 + 8fbe7fb commit 29b7782

File tree

5 files changed

+155
-0
lines changed

5 files changed

+155
-0
lines changed

conan/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 2.8.11)
2+
project(cmake_wrapper)
3+
4+
include(conanbuildinfo.cmake)
5+
conan_basic_setup()
6+
7+
include(${CMAKE_SOURCE_DIR}/CMakeListsOriginal.txt)

conan/test_package/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required(VERSION 2.8.11)
2+
project(test_package)
3+
4+
set(CMAKE_VERBOSE_MAKEFILE TRUE)
5+
6+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
7+
conan_basic_setup()
8+
9+
add_executable(${PROJECT_NAME} test_package.cpp)
10+
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})

conan/test_package/conanfile.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from conans import ConanFile, CMake
5+
import os
6+
7+
8+
class TestPackageConan(ConanFile):
9+
settings = "os", "compiler", "build_type", "arch"
10+
generators = "cmake"
11+
12+
def build(self):
13+
cmake = CMake(self)
14+
cmake.configure()
15+
cmake.build()
16+
17+
def test(self):
18+
bin_path = os.path.join("bin", "test_package")
19+
self.run(bin_path, run_environment=True)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "benchmark/benchmark.h"
2+
3+
void BM_StringCreation(benchmark::State& state) {
4+
while (state.KeepRunning())
5+
std::string empty_string;
6+
}
7+
8+
BENCHMARK(BM_StringCreation);
9+
10+
void BM_StringCopy(benchmark::State& state) {
11+
std::string x = "hello";
12+
while (state.KeepRunning())
13+
std::string copy(x);
14+
}
15+
16+
BENCHMARK(BM_StringCopy);
17+
18+
BENCHMARK_MAIN();

conanfile.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
from conans import ConanFile, CMake, tools
2+
from conans.errors import ConanInvalidConfiguration
3+
import shutil
4+
import os
5+
6+
7+
class GoogleBenchmarkConan(ConanFile):
8+
name = "benchmark"
9+
description = "A microbenchmark support library."
10+
topics = ("conan", "benchmark", "google", "microbenchmark")
11+
url = "https://github.com/google/benchmark"
12+
homepage = "https://github.com/google/benchmark"
13+
author = "Google Inc."
14+
license = "Apache-2.0"
15+
exports_sources = ["*"]
16+
generators = "cmake"
17+
18+
settings = "arch", "build_type", "compiler", "os"
19+
options = {
20+
"shared": [True, False],
21+
"fPIC": [True, False],
22+
"enable_lto": [True, False],
23+
"enable_exceptions": [True, False],
24+
"enable_gtest_tests": [True, False]
25+
}
26+
default_options = {"shared": False, "fPIC": True, "enable_lto": False, "enable_exceptions": True, "enable_gtest_tests": False}
27+
28+
_build_subfolder = "."
29+
30+
def source(self):
31+
# Wrap the original CMake file to call conan_basic_setup
32+
shutil.move("CMakeLists.txt", "CMakeListsOriginal.txt")
33+
shutil.move(os.path.join("conan", "CMakeLists.txt"), "CMakeLists.txt")
34+
35+
def config_options(self):
36+
if self.settings.os == "Windows":
37+
if self.settings.compiler == "Visual Studio" and float(self.settings.compiler.version.value) <= 12:
38+
raise ConanInvalidConfiguration("{} {} does not support Visual Studio <= 12".format(self.name, self.version))
39+
del self.options.fPIC
40+
41+
if tools.get_env("CONAN_RUN_TESTS") != "True":
42+
self.output.info("Environment variable CONAN_RUN_TEST is not defined.")
43+
self.output.info("Tests are disabled and the option enable_gtest_tests isn't available.")
44+
del self.options.enable_gtest_tests
45+
46+
def configure(self):
47+
if self.settings.os == "Windows" and self.options.shared:
48+
raise ConanInvalidConfiguration("Windows shared builds are not supported right now, see issue #639")
49+
50+
def _configure_cmake(self):
51+
cmake = CMake(self)
52+
53+
if tools.get_env("CONAN_RUN_TESTS"):
54+
cmake.definitions["BENCHMARK_ENABLE_TESTING"] = "ON"
55+
cmake.definitions["BENCHMARK_ENABLE_GTEST_TESTS"] = "ON" if self.options.enable_gtest_tests else "OFF"
56+
else:
57+
cmake.definitions["BENCHMARK_ENABLE_TESTING"] = "OFF"
58+
cmake.definitions["BENCHMARK_ENABLE_GTEST_TESTS"] = "OFF"
59+
60+
cmake.definitions["BENCHMARK_ENABLE_LTO"] = "ON" if self.options.enable_lto else "OFF"
61+
cmake.definitions["BENCHMARK_ENABLE_EXCEPTIONS"] = "ON" if self.options.enable_exceptions else "OFF"
62+
63+
# See https://github.com/google/benchmark/pull/638 for Windows 32 build explanation
64+
if self.settings.os != "Windows":
65+
cmake.definitions["BENCHMARK_BUILD_32_BITS"] = "ON" if "64" not in str(self.settings.arch) else "OFF"
66+
cmake.definitions["BENCHMARK_USE_LIBCXX"] = "ON" if (str(self.settings.compiler.libcxx) == "libc++") else "OFF"
67+
else:
68+
cmake.definitions["BENCHMARK_USE_LIBCXX"] = "OFF"
69+
70+
cmake.configure(build_folder=self._build_subfolder)
71+
return cmake
72+
73+
def build_requirements(self):
74+
if tools.get_env("CONAN_RUN_TESTS") and self.options.enable_gtest_tests:
75+
self.build_requires("gtest/1.8.0@bincrafters/stable")
76+
77+
def build(self):
78+
cmake = self._configure_cmake()
79+
cmake.build()
80+
81+
def package(self):
82+
cmake = self._configure_cmake()
83+
cmake.install()
84+
85+
self.copy(pattern="LICENSE", dst="licenses")
86+
87+
def package_info(self):
88+
self.cpp_info.libs = tools.collect_libs(self)
89+
if self.settings.os == "Linux":
90+
self.cpp_info.libs.extend(["pthread", "rt"])
91+
elif self.settings.os == "Windows":
92+
self.cpp_info.libs.append("shlwapi")
93+
elif self.settings.os == "SunOS":
94+
self.cpp_info.libs.append("kstat")
95+
96+
def package_id(self):
97+
# Development options don't change the binary output
98+
# from a user point of view; overwrite id information
99+
# so that the package_id is the same
100+
# if only the development options are different
101+
del self.info.options.enable_gtest_tests

0 commit comments

Comments
 (0)