Skip to content

Commit 5ae8f12

Browse files
authored
Merge pull request #1482 from sarnex/cmake
[CMake] Support preinstalled googlebenchmark
2 parents c765222 + df9fcf1 commit 5ae8f12

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

benchmark/CMakeLists.txt

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,28 @@
22
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

5-
include(FetchContent)
6-
FetchContent_Declare(
7-
googlebenchmark
8-
GIT_REPOSITORY https://github.com/google/benchmark.git
9-
GIT_TAG v1.9.0)
10-
11-
set(BENCHMARK_ENABLE_GTEST_TESTS
12-
OFF
13-
CACHE BOOL "" FORCE)
14-
set(BENCHMARK_ENABLE_TESTING
15-
OFF
16-
CACHE BOOL "" FORCE)
17-
set(BENCHMARK_ENABLE_INSTALL
18-
OFF
19-
CACHE BOOL "" FORCE)
20-
FetchContent_MakeAvailable(googlebenchmark)
5+
set(GBENCH_VERSION 1.9.0)
6+
7+
find_package(benchmark ${GBENCH_VERSION} QUIET)
8+
9+
if(NOT benchmark_FOUND)
10+
include(FetchContent)
11+
FetchContent_Declare(
12+
googlebenchmark
13+
GIT_REPOSITORY https://github.com/google/benchmark.git
14+
GIT_TAG v${GBENCH_VERSION})
15+
16+
set(BENCHMARK_ENABLE_GTEST_TESTS
17+
OFF
18+
CACHE BOOL "" FORCE)
19+
set(BENCHMARK_ENABLE_TESTING
20+
OFF
21+
CACHE BOOL "" FORCE)
22+
set(BENCHMARK_ENABLE_INSTALL
23+
OFF
24+
CACHE BOOL "" FORCE)
25+
FetchContent_MakeAvailable(googlebenchmark)
26+
endif()
2127

2228
# In MSVC builds, there is no way to determine the actual build type during the
2329
# CMake configuration step. Therefore, this message is printed in all MSVC

0 commit comments

Comments
 (0)