Skip to content

Commit 01c0ab7

Browse files
authored
Fix Clang builds on Windows (google#1021)
Fixes google#974. The `cxx_feature_check` now has an additional optional argument which can be used to supply extra cmake flags to pass to the `try_compile` command. The `CMAKE_CXX_STANDARD=14` flag was determined to be the minimum flag necessary to correctly compile and run the regex feature checks when compiling with Clang under Windows (n.b. this does *not* refer to clang-cl, the frontend to the MSVC compiler). The additional flag is not enabled for any other compiler/platform tuple.
1 parent 4857962 commit 01c0ab7

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,18 +245,25 @@ if (BENCHMARK_USE_LIBCXX)
245245
endif()
246246
endif(BENCHMARK_USE_LIBCXX)
247247

248+
set(EXTRA_CXX_FLAGS "")
249+
if (WIN32 AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
250+
# Clang on Windows fails to compile the regex feature check under C++11
251+
set(EXTRA_CXX_FLAGS "-DCMAKE_CXX_STANDARD=14")
252+
endif()
253+
248254
# C++ feature checks
249255
# Determine the correct regular expression engine to use
250-
cxx_feature_check(STD_REGEX)
251-
cxx_feature_check(GNU_POSIX_REGEX)
252-
cxx_feature_check(POSIX_REGEX)
256+
cxx_feature_check(STD_REGEX ${EXTRA_CXX_FLAGS})
257+
cxx_feature_check(GNU_POSIX_REGEX ${EXTRA_CXX_FLAGS})
258+
cxx_feature_check(POSIX_REGEX ${EXTRA_CXX_FLAGS})
253259
if(NOT HAVE_STD_REGEX AND NOT HAVE_GNU_POSIX_REGEX AND NOT HAVE_POSIX_REGEX)
254260
message(FATAL_ERROR "Failed to determine the source files for the regular expression backend")
255261
endif()
256262
if (NOT BENCHMARK_ENABLE_EXCEPTIONS AND HAVE_STD_REGEX
257263
AND NOT HAVE_GNU_POSIX_REGEX AND NOT HAVE_POSIX_REGEX)
258264
message(WARNING "Using std::regex with exceptions disabled is not fully supported")
259265
endif()
266+
260267
cxx_feature_check(STEADY_CLOCK)
261268
# Ensure we have pthreads
262269
set(THREADS_PREFER_PTHREAD_FLAG ON)

cmake/CXXFeatureCheck.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ function(cxx_feature_check FILE)
2727
return()
2828
endif()
2929

30+
if (ARGC GREATER 1)
31+
message(STATUS "Enabling additional flags: ${ARGV1}")
32+
list(APPEND BENCHMARK_CXX_LINKER_FLAGS ${ARGV1})
33+
endif()
34+
3035
if (NOT DEFINED COMPILE_${FEATURE})
3136
message(STATUS "Performing Test ${FEATURE}")
3237
if(CMAKE_CROSSCOMPILING)

0 commit comments

Comments
 (0)