1a8c51b3fSopenharmony_ci# Require CMake 3.10. If available, use the policies up to CMake 3.22.
2a8c51b3fSopenharmony_cicmake_minimum_required (VERSION 3.10...3.22)
3a8c51b3fSopenharmony_ci
4a8c51b3fSopenharmony_ciproject (benchmark VERSION 1.8.3 LANGUAGES CXX)
5a8c51b3fSopenharmony_ci
6a8c51b3fSopenharmony_cioption(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." ON)
7a8c51b3fSopenharmony_cioption(BENCHMARK_ENABLE_EXCEPTIONS "Enable the use of exceptions in the benchmark library." ON)
8a8c51b3fSopenharmony_cioption(BENCHMARK_ENABLE_LTO "Enable link time optimisation of the benchmark library." OFF)
9a8c51b3fSopenharmony_cioption(BENCHMARK_USE_LIBCXX "Build and test using libc++ as the standard library." OFF)
10a8c51b3fSopenharmony_cioption(BENCHMARK_ENABLE_WERROR "Build Release candidates with -Werror." ON)
11a8c51b3fSopenharmony_cioption(BENCHMARK_FORCE_WERROR "Build Release candidates with -Werror regardless of compiler issues." OFF)
12a8c51b3fSopenharmony_ci
13a8c51b3fSopenharmony_ciif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "PGI")
14a8c51b3fSopenharmony_ci  # PGC++ maybe reporting false positives.
15a8c51b3fSopenharmony_ci  set(BENCHMARK_ENABLE_WERROR OFF)
16a8c51b3fSopenharmony_ciendif()
17a8c51b3fSopenharmony_ciif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "NVHPC")
18a8c51b3fSopenharmony_ci  set(BENCHMARK_ENABLE_WERROR OFF)
19a8c51b3fSopenharmony_ciendif()
20a8c51b3fSopenharmony_ciif(BENCHMARK_FORCE_WERROR)
21a8c51b3fSopenharmony_ci  set(BENCHMARK_ENABLE_WERROR ON)
22a8c51b3fSopenharmony_ciendif(BENCHMARK_FORCE_WERROR)
23a8c51b3fSopenharmony_ci
24a8c51b3fSopenharmony_ciif(NOT MSVC)
25a8c51b3fSopenharmony_ci  option(BENCHMARK_BUILD_32_BITS "Build a 32 bit version of the library." OFF)
26a8c51b3fSopenharmony_cielse()
27a8c51b3fSopenharmony_ci  set(BENCHMARK_BUILD_32_BITS OFF CACHE BOOL "Build a 32 bit version of the library - unsupported when using MSVC)" FORCE)
28a8c51b3fSopenharmony_ciendif()
29a8c51b3fSopenharmony_cioption(BENCHMARK_ENABLE_INSTALL "Enable installation of benchmark. (Projects embedding benchmark may want to turn this OFF.)" ON)
30a8c51b3fSopenharmony_cioption(BENCHMARK_ENABLE_DOXYGEN "Build documentation with Doxygen." OFF)
31a8c51b3fSopenharmony_cioption(BENCHMARK_INSTALL_DOCS "Enable installation of documentation." ON)
32a8c51b3fSopenharmony_ci
33a8c51b3fSopenharmony_ci# Allow unmet dependencies to be met using CMake's ExternalProject mechanics, which
34a8c51b3fSopenharmony_ci# may require downloading the source code.
35a8c51b3fSopenharmony_cioption(BENCHMARK_DOWNLOAD_DEPENDENCIES "Allow the downloading and in-tree building of unmet dependencies" OFF)
36a8c51b3fSopenharmony_ci
37a8c51b3fSopenharmony_ci# This option can be used to disable building and running unit tests which depend on gtest
38a8c51b3fSopenharmony_ci# in cases where it is not possible to build or find a valid version of gtest.
39a8c51b3fSopenharmony_cioption(BENCHMARK_ENABLE_GTEST_TESTS "Enable building the unit tests which depend on gtest" ON)
40a8c51b3fSopenharmony_cioption(BENCHMARK_USE_BUNDLED_GTEST "Use bundled GoogleTest. If disabled, the find_package(GTest) will be used." ON)
41a8c51b3fSopenharmony_ci
42a8c51b3fSopenharmony_cioption(BENCHMARK_ENABLE_LIBPFM "Enable performance counters provided by libpfm" OFF)
43a8c51b3fSopenharmony_ci
44a8c51b3fSopenharmony_ci# Export only public symbols
45a8c51b3fSopenharmony_ciset(CMAKE_CXX_VISIBILITY_PRESET hidden)
46a8c51b3fSopenharmony_ciset(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
47a8c51b3fSopenharmony_ci
48a8c51b3fSopenharmony_ciif(MSVC)
49a8c51b3fSopenharmony_ci    # As of CMake 3.18, CMAKE_SYSTEM_PROCESSOR is not set properly for MSVC and
50a8c51b3fSopenharmony_ci    # cross-compilation (e.g. Host=x86_64, target=aarch64) requires using the
51a8c51b3fSopenharmony_ci    # undocumented, but working variable.
52a8c51b3fSopenharmony_ci    # See https://gitlab.kitware.com/cmake/cmake/-/issues/15170
53a8c51b3fSopenharmony_ci    set(CMAKE_SYSTEM_PROCESSOR ${MSVC_CXX_ARCHITECTURE_ID})
54a8c51b3fSopenharmony_ci    if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "ARM")
55a8c51b3fSopenharmony_ci      set(CMAKE_CROSSCOMPILING TRUE)
56a8c51b3fSopenharmony_ci    endif()
57a8c51b3fSopenharmony_ciendif()
58a8c51b3fSopenharmony_ci
59a8c51b3fSopenharmony_ciset(ENABLE_ASSEMBLY_TESTS_DEFAULT OFF)
60a8c51b3fSopenharmony_cifunction(should_enable_assembly_tests)
61a8c51b3fSopenharmony_ci  if(CMAKE_BUILD_TYPE)
62a8c51b3fSopenharmony_ci    string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER)
63a8c51b3fSopenharmony_ci    if (${CMAKE_BUILD_TYPE_LOWER} MATCHES "coverage")
64a8c51b3fSopenharmony_ci      # FIXME: The --coverage flag needs to be removed when building assembly
65a8c51b3fSopenharmony_ci      # tests for this to work.
66a8c51b3fSopenharmony_ci      return()
67a8c51b3fSopenharmony_ci    endif()
68a8c51b3fSopenharmony_ci  endif()
69a8c51b3fSopenharmony_ci  if (MSVC)
70a8c51b3fSopenharmony_ci    return()
71a8c51b3fSopenharmony_ci  elseif(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
72a8c51b3fSopenharmony_ci    return()
73a8c51b3fSopenharmony_ci  elseif(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
74a8c51b3fSopenharmony_ci    # FIXME: Make these work on 32 bit builds
75a8c51b3fSopenharmony_ci    return()
76a8c51b3fSopenharmony_ci  elseif(BENCHMARK_BUILD_32_BITS)
77a8c51b3fSopenharmony_ci     # FIXME: Make these work on 32 bit builds
78a8c51b3fSopenharmony_ci    return()
79a8c51b3fSopenharmony_ci  endif()
80a8c51b3fSopenharmony_ci  find_program(LLVM_FILECHECK_EXE FileCheck)
81a8c51b3fSopenharmony_ci  if (LLVM_FILECHECK_EXE)
82a8c51b3fSopenharmony_ci    set(LLVM_FILECHECK_EXE "${LLVM_FILECHECK_EXE}" CACHE PATH "llvm filecheck" FORCE)
83a8c51b3fSopenharmony_ci    message(STATUS "LLVM FileCheck Found: ${LLVM_FILECHECK_EXE}")
84a8c51b3fSopenharmony_ci  else()
85a8c51b3fSopenharmony_ci    message(STATUS "Failed to find LLVM FileCheck")
86a8c51b3fSopenharmony_ci    return()
87a8c51b3fSopenharmony_ci  endif()
88a8c51b3fSopenharmony_ci  set(ENABLE_ASSEMBLY_TESTS_DEFAULT ON PARENT_SCOPE)
89a8c51b3fSopenharmony_ciendfunction()
90a8c51b3fSopenharmony_cishould_enable_assembly_tests()
91a8c51b3fSopenharmony_ci
92a8c51b3fSopenharmony_ci# This option disables the building and running of the assembly verification tests
93a8c51b3fSopenharmony_cioption(BENCHMARK_ENABLE_ASSEMBLY_TESTS "Enable building and running the assembly tests"
94a8c51b3fSopenharmony_ci    ${ENABLE_ASSEMBLY_TESTS_DEFAULT})
95a8c51b3fSopenharmony_ci
96a8c51b3fSopenharmony_ci# Make sure we can import out CMake functions
97a8c51b3fSopenharmony_cilist(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
98a8c51b3fSopenharmony_cilist(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
99a8c51b3fSopenharmony_ci
100a8c51b3fSopenharmony_ci
101a8c51b3fSopenharmony_ci# Read the git tags to determine the project version
102a8c51b3fSopenharmony_ciinclude(GetGitVersion)
103a8c51b3fSopenharmony_ciget_git_version(GIT_VERSION)
104a8c51b3fSopenharmony_ci
105a8c51b3fSopenharmony_ci# If no git version can be determined, use the version
106a8c51b3fSopenharmony_ci# from the project() command
107a8c51b3fSopenharmony_ciif ("${GIT_VERSION}" STREQUAL "0.0.0")
108a8c51b3fSopenharmony_ci  set(VERSION "${benchmark_VERSION}")
109a8c51b3fSopenharmony_cielse()
110a8c51b3fSopenharmony_ci  set(VERSION "${GIT_VERSION}")
111a8c51b3fSopenharmony_ciendif()
112a8c51b3fSopenharmony_ci# Tell the user what versions we are using
113a8c51b3fSopenharmony_cimessage(STATUS "Google Benchmark version: ${VERSION}")
114a8c51b3fSopenharmony_ci
115a8c51b3fSopenharmony_ci# The version of the libraries
116a8c51b3fSopenharmony_ciset(GENERIC_LIB_VERSION ${VERSION})
117a8c51b3fSopenharmony_cistring(SUBSTRING ${VERSION} 0 1 GENERIC_LIB_SOVERSION)
118a8c51b3fSopenharmony_ci
119a8c51b3fSopenharmony_ci# Import our CMake modules
120a8c51b3fSopenharmony_ciinclude(AddCXXCompilerFlag)
121a8c51b3fSopenharmony_ciinclude(CheckCXXCompilerFlag)
122a8c51b3fSopenharmony_ciinclude(CheckLibraryExists)
123a8c51b3fSopenharmony_ciinclude(CXXFeatureCheck)
124a8c51b3fSopenharmony_ci
125a8c51b3fSopenharmony_cicheck_library_exists(rt shm_open "" HAVE_LIB_RT)
126a8c51b3fSopenharmony_ci
127a8c51b3fSopenharmony_ciif (BENCHMARK_BUILD_32_BITS)
128a8c51b3fSopenharmony_ci  add_required_cxx_compiler_flag(-m32)
129a8c51b3fSopenharmony_ciendif()
130a8c51b3fSopenharmony_ci
131a8c51b3fSopenharmony_ciif (MSVC)
132a8c51b3fSopenharmony_ci  set(BENCHMARK_CXX_STANDARD 14)
133a8c51b3fSopenharmony_cielse()
134a8c51b3fSopenharmony_ci  set(BENCHMARK_CXX_STANDARD 11)
135a8c51b3fSopenharmony_ciendif()
136a8c51b3fSopenharmony_ci
137a8c51b3fSopenharmony_ciset(CMAKE_CXX_STANDARD ${BENCHMARK_CXX_STANDARD})
138a8c51b3fSopenharmony_ciset(CMAKE_CXX_STANDARD_REQUIRED YES)
139a8c51b3fSopenharmony_ciset(CMAKE_CXX_EXTENSIONS OFF)
140a8c51b3fSopenharmony_ci
141a8c51b3fSopenharmony_ciif (MSVC)
142a8c51b3fSopenharmony_ci  # Turn compiler warnings up to 11
143a8c51b3fSopenharmony_ci  string(REGEX REPLACE "[-/]W[1-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
144a8c51b3fSopenharmony_ci  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
145a8c51b3fSopenharmony_ci  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
146a8c51b3fSopenharmony_ci
147a8c51b3fSopenharmony_ci  if (NOT BENCHMARK_ENABLE_EXCEPTIONS)
148a8c51b3fSopenharmony_ci    add_cxx_compiler_flag(-EHs-)
149a8c51b3fSopenharmony_ci    add_cxx_compiler_flag(-EHa-)
150a8c51b3fSopenharmony_ci    add_definitions(-D_HAS_EXCEPTIONS=0)
151a8c51b3fSopenharmony_ci  endif()
152a8c51b3fSopenharmony_ci  # Link time optimisation
153a8c51b3fSopenharmony_ci  if (BENCHMARK_ENABLE_LTO)
154a8c51b3fSopenharmony_ci    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL")
155a8c51b3fSopenharmony_ci    set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} /LTCG")
156a8c51b3fSopenharmony_ci    set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG")
157a8c51b3fSopenharmony_ci    set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG")
158a8c51b3fSopenharmony_ci
159a8c51b3fSopenharmony_ci    set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /GL")
160a8c51b3fSopenharmony_ci    string(REGEX REPLACE "[-/]INCREMENTAL" "/INCREMENTAL:NO" CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO}")
161a8c51b3fSopenharmony_ci    set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
162a8c51b3fSopenharmony_ci    string(REGEX REPLACE "[-/]INCREMENTAL" "/INCREMENTAL:NO" CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO}")
163a8c51b3fSopenharmony_ci    set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
164a8c51b3fSopenharmony_ci    string(REGEX REPLACE "[-/]INCREMENTAL" "/INCREMENTAL:NO" CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
165a8c51b3fSopenharmony_ci    set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
166a8c51b3fSopenharmony_ci
167a8c51b3fSopenharmony_ci    set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /GL")
168a8c51b3fSopenharmony_ci    set(CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL "${CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL} /LTCG")
169a8c51b3fSopenharmony_ci    set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL} /LTCG")
170a8c51b3fSopenharmony_ci    set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} /LTCG")
171a8c51b3fSopenharmony_ci  endif()
172a8c51b3fSopenharmony_cielse()
173a8c51b3fSopenharmony_ci  # Turn compiler warnings up to 11
174a8c51b3fSopenharmony_ci  add_cxx_compiler_flag(-Wall)
175a8c51b3fSopenharmony_ci  add_cxx_compiler_flag(-Wextra)
176a8c51b3fSopenharmony_ci  add_cxx_compiler_flag(-Wshadow)
177a8c51b3fSopenharmony_ci  add_cxx_compiler_flag(-Wfloat-equal)
178a8c51b3fSopenharmony_ci  add_cxx_compiler_flag(-Wold-style-cast)
179a8c51b3fSopenharmony_ci  if(BENCHMARK_ENABLE_WERROR)
180a8c51b3fSopenharmony_ci      add_cxx_compiler_flag(-Werror)
181a8c51b3fSopenharmony_ci  endif()
182a8c51b3fSopenharmony_ci  if (NOT BENCHMARK_ENABLE_TESTING)
183a8c51b3fSopenharmony_ci    # Disable warning when compiling tests as gtest does not use 'override'.
184a8c51b3fSopenharmony_ci    add_cxx_compiler_flag(-Wsuggest-override)
185a8c51b3fSopenharmony_ci  endif()
186a8c51b3fSopenharmony_ci  add_cxx_compiler_flag(-pedantic)
187a8c51b3fSopenharmony_ci  add_cxx_compiler_flag(-pedantic-errors)
188a8c51b3fSopenharmony_ci  add_cxx_compiler_flag(-Wshorten-64-to-32)
189a8c51b3fSopenharmony_ci  add_cxx_compiler_flag(-fstrict-aliasing)
190a8c51b3fSopenharmony_ci  # Disable warnings regarding deprecated parts of the library while building
191a8c51b3fSopenharmony_ci  # and testing those parts of the library.
192a8c51b3fSopenharmony_ci  add_cxx_compiler_flag(-Wno-deprecated-declarations)
193a8c51b3fSopenharmony_ci  if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
194a8c51b3fSopenharmony_ci    # Intel silently ignores '-Wno-deprecated-declarations',
195a8c51b3fSopenharmony_ci    # warning no. 1786 must be explicitly disabled.
196a8c51b3fSopenharmony_ci    # See #631 for rationale.
197a8c51b3fSopenharmony_ci    add_cxx_compiler_flag(-wd1786)
198a8c51b3fSopenharmony_ci    add_cxx_compiler_flag(-fno-finite-math-only)
199a8c51b3fSopenharmony_ci  endif()
200a8c51b3fSopenharmony_ci  # Disable deprecation warnings for release builds (when -Werror is enabled).
201a8c51b3fSopenharmony_ci  if(BENCHMARK_ENABLE_WERROR)
202a8c51b3fSopenharmony_ci      add_cxx_compiler_flag(-Wno-deprecated)
203a8c51b3fSopenharmony_ci  endif()
204a8c51b3fSopenharmony_ci  if (NOT BENCHMARK_ENABLE_EXCEPTIONS)
205a8c51b3fSopenharmony_ci    add_cxx_compiler_flag(-fno-exceptions)
206a8c51b3fSopenharmony_ci  endif()
207a8c51b3fSopenharmony_ci
208a8c51b3fSopenharmony_ci  if (HAVE_CXX_FLAG_FSTRICT_ALIASING)
209a8c51b3fSopenharmony_ci    if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM") #ICC17u2: Many false positives for Wstrict-aliasing
210a8c51b3fSopenharmony_ci      add_cxx_compiler_flag(-Wstrict-aliasing)
211a8c51b3fSopenharmony_ci    endif()
212a8c51b3fSopenharmony_ci  endif()
213a8c51b3fSopenharmony_ci  # ICC17u2: overloaded virtual function "benchmark::Fixture::SetUp" is only partially overridden
214a8c51b3fSopenharmony_ci  # (because of deprecated overload)
215a8c51b3fSopenharmony_ci  add_cxx_compiler_flag(-wd654)
216a8c51b3fSopenharmony_ci  add_cxx_compiler_flag(-Wthread-safety)
217a8c51b3fSopenharmony_ci  if (HAVE_CXX_FLAG_WTHREAD_SAFETY)
218a8c51b3fSopenharmony_ci    cxx_feature_check(THREAD_SAFETY_ATTRIBUTES "-DINCLUDE_DIRECTORIES=${PROJECT_SOURCE_DIR}/include")
219a8c51b3fSopenharmony_ci  endif()
220a8c51b3fSopenharmony_ci
221a8c51b3fSopenharmony_ci  # On most UNIX like platforms g++ and clang++ define _GNU_SOURCE as a
222a8c51b3fSopenharmony_ci  # predefined macro, which turns on all of the wonderful libc extensions.
223a8c51b3fSopenharmony_ci  # However g++ doesn't do this in Cygwin so we have to define it ourselves
224a8c51b3fSopenharmony_ci  # since we depend on GNU/POSIX/BSD extensions.
225a8c51b3fSopenharmony_ci  if (CYGWIN)
226a8c51b3fSopenharmony_ci    add_definitions(-D_GNU_SOURCE=1)
227a8c51b3fSopenharmony_ci  endif()
228a8c51b3fSopenharmony_ci
229a8c51b3fSopenharmony_ci  if (QNXNTO)
230a8c51b3fSopenharmony_ci    add_definitions(-D_QNX_SOURCE)
231a8c51b3fSopenharmony_ci  endif()
232a8c51b3fSopenharmony_ci
233a8c51b3fSopenharmony_ci  # Link time optimisation
234a8c51b3fSopenharmony_ci  if (BENCHMARK_ENABLE_LTO)
235a8c51b3fSopenharmony_ci    add_cxx_compiler_flag(-flto)
236a8c51b3fSopenharmony_ci    add_cxx_compiler_flag(-Wno-lto-type-mismatch)
237a8c51b3fSopenharmony_ci    if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
238a8c51b3fSopenharmony_ci      find_program(GCC_AR gcc-ar)
239a8c51b3fSopenharmony_ci      if (GCC_AR)
240a8c51b3fSopenharmony_ci        set(CMAKE_AR ${GCC_AR})
241a8c51b3fSopenharmony_ci      endif()
242a8c51b3fSopenharmony_ci      find_program(GCC_RANLIB gcc-ranlib)
243a8c51b3fSopenharmony_ci      if (GCC_RANLIB)
244a8c51b3fSopenharmony_ci        set(CMAKE_RANLIB ${GCC_RANLIB})
245a8c51b3fSopenharmony_ci      endif()
246a8c51b3fSopenharmony_ci    elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
247a8c51b3fSopenharmony_ci      include(llvm-toolchain)
248a8c51b3fSopenharmony_ci    endif()
249a8c51b3fSopenharmony_ci  endif()
250a8c51b3fSopenharmony_ci
251a8c51b3fSopenharmony_ci  # Coverage build type
252a8c51b3fSopenharmony_ci  set(BENCHMARK_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG}"
253a8c51b3fSopenharmony_ci    CACHE STRING "Flags used by the C++ compiler during coverage builds."
254a8c51b3fSopenharmony_ci    FORCE)
255a8c51b3fSopenharmony_ci  set(BENCHMARK_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_DEBUG}"
256a8c51b3fSopenharmony_ci    CACHE STRING "Flags used for linking binaries during coverage builds."
257a8c51b3fSopenharmony_ci    FORCE)
258a8c51b3fSopenharmony_ci  set(BENCHMARK_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}"
259a8c51b3fSopenharmony_ci    CACHE STRING "Flags used by the shared libraries linker during coverage builds."
260a8c51b3fSopenharmony_ci    FORCE)
261a8c51b3fSopenharmony_ci  mark_as_advanced(
262a8c51b3fSopenharmony_ci    BENCHMARK_CXX_FLAGS_COVERAGE
263a8c51b3fSopenharmony_ci    BENCHMARK_EXE_LINKER_FLAGS_COVERAGE
264a8c51b3fSopenharmony_ci    BENCHMARK_SHARED_LINKER_FLAGS_COVERAGE)
265a8c51b3fSopenharmony_ci  set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
266a8c51b3fSopenharmony_ci    "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage.")
267a8c51b3fSopenharmony_ci  add_cxx_compiler_flag(--coverage COVERAGE)
268a8c51b3fSopenharmony_ciendif()
269a8c51b3fSopenharmony_ci
270a8c51b3fSopenharmony_ciif (BENCHMARK_USE_LIBCXX)
271a8c51b3fSopenharmony_ci  if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
272a8c51b3fSopenharmony_ci    add_cxx_compiler_flag(-stdlib=libc++)
273a8c51b3fSopenharmony_ci  elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
274a8c51b3fSopenharmony_ci          "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel" OR
275a8c51b3fSopenharmony_ci          "${CMAKE_CXX_COMPILER_ID}" STREQUAL "IntelLLVM")
276a8c51b3fSopenharmony_ci    add_cxx_compiler_flag(-nostdinc++)
277a8c51b3fSopenharmony_ci    message(WARNING "libc++ header path must be manually specified using CMAKE_CXX_FLAGS")
278a8c51b3fSopenharmony_ci    # Adding -nodefaultlibs directly to CMAKE_<TYPE>_LINKER_FLAGS will break
279a8c51b3fSopenharmony_ci    # configuration checks such as 'find_package(Threads)'
280a8c51b3fSopenharmony_ci    list(APPEND BENCHMARK_CXX_LINKER_FLAGS -nodefaultlibs)
281a8c51b3fSopenharmony_ci    # -lc++ cannot be added directly to CMAKE_<TYPE>_LINKER_FLAGS because
282a8c51b3fSopenharmony_ci    # linker flags appear before all linker inputs and -lc++ must appear after.
283a8c51b3fSopenharmony_ci    list(APPEND BENCHMARK_CXX_LIBRARIES c++)
284a8c51b3fSopenharmony_ci  else()
285a8c51b3fSopenharmony_ci    message(FATAL_ERROR "-DBENCHMARK_USE_LIBCXX:BOOL=ON is not supported for compiler")
286a8c51b3fSopenharmony_ci  endif()
287a8c51b3fSopenharmony_ciendif(BENCHMARK_USE_LIBCXX)
288a8c51b3fSopenharmony_ci
289a8c51b3fSopenharmony_ciset(EXTRA_CXX_FLAGS "")
290a8c51b3fSopenharmony_ciif (WIN32 AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
291a8c51b3fSopenharmony_ci  # Clang on Windows fails to compile the regex feature check under C++11
292a8c51b3fSopenharmony_ci  set(EXTRA_CXX_FLAGS "-DCMAKE_CXX_STANDARD=14")
293a8c51b3fSopenharmony_ciendif()
294a8c51b3fSopenharmony_ci
295a8c51b3fSopenharmony_ci# C++ feature checks
296a8c51b3fSopenharmony_ci# Determine the correct regular expression engine to use
297a8c51b3fSopenharmony_cicxx_feature_check(STD_REGEX ${EXTRA_CXX_FLAGS})
298a8c51b3fSopenharmony_cicxx_feature_check(GNU_POSIX_REGEX ${EXTRA_CXX_FLAGS})
299a8c51b3fSopenharmony_cicxx_feature_check(POSIX_REGEX ${EXTRA_CXX_FLAGS})
300a8c51b3fSopenharmony_ciif(NOT HAVE_STD_REGEX AND NOT HAVE_GNU_POSIX_REGEX AND NOT HAVE_POSIX_REGEX)
301a8c51b3fSopenharmony_ci  message(FATAL_ERROR "Failed to determine the source files for the regular expression backend")
302a8c51b3fSopenharmony_ciendif()
303a8c51b3fSopenharmony_ciif (NOT BENCHMARK_ENABLE_EXCEPTIONS AND HAVE_STD_REGEX
304a8c51b3fSopenharmony_ci        AND NOT HAVE_GNU_POSIX_REGEX AND NOT HAVE_POSIX_REGEX)
305a8c51b3fSopenharmony_ci  message(WARNING "Using std::regex with exceptions disabled is not fully supported")
306a8c51b3fSopenharmony_ciendif()
307a8c51b3fSopenharmony_ci
308a8c51b3fSopenharmony_cicxx_feature_check(STEADY_CLOCK)
309a8c51b3fSopenharmony_ci# Ensure we have pthreads
310a8c51b3fSopenharmony_ciset(THREADS_PREFER_PTHREAD_FLAG ON)
311a8c51b3fSopenharmony_cifind_package(Threads REQUIRED)
312a8c51b3fSopenharmony_cicxx_feature_check(PTHREAD_AFFINITY)
313a8c51b3fSopenharmony_ci
314a8c51b3fSopenharmony_ciif (BENCHMARK_ENABLE_LIBPFM)
315a8c51b3fSopenharmony_ci  find_package(PFM)
316a8c51b3fSopenharmony_ciendif()
317a8c51b3fSopenharmony_ci
318a8c51b3fSopenharmony_ci# Set up directories
319a8c51b3fSopenharmony_ciinclude_directories(${PROJECT_SOURCE_DIR}/include)
320a8c51b3fSopenharmony_ci
321a8c51b3fSopenharmony_ci# Build the targets
322a8c51b3fSopenharmony_ciadd_subdirectory(src)
323a8c51b3fSopenharmony_ci
324a8c51b3fSopenharmony_ciif (BENCHMARK_ENABLE_TESTING)
325a8c51b3fSopenharmony_ci  enable_testing()
326a8c51b3fSopenharmony_ci  if (BENCHMARK_ENABLE_GTEST_TESTS AND
327a8c51b3fSopenharmony_ci      NOT (TARGET gtest AND TARGET gtest_main AND
328a8c51b3fSopenharmony_ci           TARGET gmock AND TARGET gmock_main))
329a8c51b3fSopenharmony_ci    if (BENCHMARK_USE_BUNDLED_GTEST)
330a8c51b3fSopenharmony_ci      include(GoogleTest)
331a8c51b3fSopenharmony_ci    else()
332a8c51b3fSopenharmony_ci      find_package(GTest CONFIG REQUIRED)
333a8c51b3fSopenharmony_ci      add_library(gtest ALIAS GTest::gtest)
334a8c51b3fSopenharmony_ci      add_library(gtest_main ALIAS GTest::gtest_main)
335a8c51b3fSopenharmony_ci      add_library(gmock ALIAS GTest::gmock)
336a8c51b3fSopenharmony_ci      add_library(gmock_main ALIAS GTest::gmock_main)
337a8c51b3fSopenharmony_ci    endif()
338a8c51b3fSopenharmony_ci  endif()
339a8c51b3fSopenharmony_ci  add_subdirectory(test)
340a8c51b3fSopenharmony_ciendif()
341