Skip to content

Commit 2d7be92

Browse files
committed
Add GBench library find and install scripts.
1 parent 814f963 commit 2d7be92

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

FindGBench.cmake

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#
2+
# CMake Find Google Benchmark by Parra Studios
3+
# CMake script to find Google Benchmark library.
4+
#
5+
# Copyright (C) 2016 - 2019 Vicente Eduardo Ferrer Garcia <[email protected]>
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
# The following variables are set:
21+
#
22+
# GBENCH_INCLUDE_DIR - Path where Google Benchmark header is located.
23+
# GBENCH_LIBRARY - Path where Google Benchmark library is located.
24+
25+
# Prevent vervosity if already included
26+
if(GBENCH_FOUND)
27+
set(GBENCH_FIND_QUIETLY TRUE)
28+
endif()
29+
30+
find_path(GBENCH_INCLUDE_DIR NAMES benchmark/benchmark.h)
31+
find_library(GBENCH_LIBRARY NAMES benchmark)
32+
33+
include(FindPackageHandleStandardArgs)
34+
35+
find_package_handle_standard_args(google-benchmark
36+
REQUIRED_VARS GBENCH_INCLUDE_DIR GBENCH_LIBRARY
37+
)
38+
39+
mark_as_advanced(GBENCH_INCLUDE_DIR GBENCH_LIBRARY)
40+
41+
if(GBENCH_FOUND)
42+
if(NOT GBENCH_FIND_QUIETLY)
43+
message(STATUS "Found Google Benchmark:\n\tLibrary: ${GBENCH_LIBRARY}\n\tIncludes: ${GBENCH_INCLUDE_PATH}")
44+
endif(NOT GBENCH_FIND_QUIETLY)
45+
else(GBENCH_FOUND)
46+
if(GBENCH_FIND_REQUIRED)
47+
message(FATAL_ERROR "Could not find Google Benchmark library")
48+
endif(GBENCH_FIND_REQUIRED)
49+
endif(GBENCH_FOUND)

InstallGBench.cmake

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#
2+
# CMake Install Google Benchmark by Parra Studios
3+
# CMake script to install Google Benchmark library.
4+
#
5+
# Copyright (C) 2016 - 2019 Vicente Eduardo Ferrer Garcia <[email protected]>
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
# The following variables are set:
21+
#
22+
# GBENCH_INCLUDE_DIR - Path where Google Benchmark header is located.
23+
# GBENCH_LIBRARY - Path where Google Benchmark library is located.
24+
25+
if(NOT GBENCH_FOUND OR USE_BUNDLED_GBENCH)
26+
if(NOT GBENCH_VERSION OR USE_BUNDLED_GBENCH)
27+
set(GBENCH_VERSION 1.4.1)
28+
set(GBENCH_URL_MD5 482dddb22bec43f5507a000456d6bb88)
29+
endif()
30+
31+
ExternalProject_Add(GoogleBench
32+
DOWNLOAD_NAME GBench-${GBENCH_VERSION}.tar.gz
33+
URL https://github.com/google/benchmark/archive/v${GBENCH_VERSION}.tar.gz
34+
URL_MD5 ${GBENCH_URL_MD5}
35+
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DBENCHMARK_DOWNLOAD_DEPENDENCIES=ON
36+
TEST_COMMAND ""
37+
)
38+
39+
ExternalProject_Get_Property(GoogleBench INSTALL_DIR)
40+
41+
if(MSVC)
42+
set(GBENCH_LIB_SUFFIX "lib")
43+
else()
44+
set(GBENCH_LIB_SUFFIX "a")
45+
endif()
46+
47+
set(GBENCH_ROOT_DIR "${INSTALL_DIR}")
48+
set(GBENCH_INCLUDE_DIR "${GBENCH_ROOT_DIR}/include")
49+
set(GBENCH_LIBRARY "${GBENCH_ROOT_DIR}/lib/libbenchmark.${GBENCH_LIB_SUFFIX}")
50+
set(GBENCH_FOUND TRUE)
51+
52+
mark_as_advanced(GBENCH_INCLUDE_DIR GBENCH_LIBRARY)
53+
54+
message(STATUS "Install Google Benchmark v${GBENCH_VERSION}")
55+
endif ()

0 commit comments

Comments
 (0)