Skip to content

Commit c9106a7

Browse files
authoredSep 26, 2023
Audit MSVC references in cmake files to consider clang++ (google#1669)
There are three major compilers on Windows targeting the MSVC ABI (i.e. linking with microsofts STL etc.): - `MSVC` - `clang-cl` aka clang with the MSVC compatible CLI - `clang++` aka clang with gcc compatible CLI The cmake variable `MSVC` is only set for the first two as it defined in terms of the CLI interface provided: > Set to true when the compiler is some version of Microsoft Visual > C++ or another compiler simulating the Visual C++ cl command-line syntax. (from cmake docs) For many of the tests in the library its the ABI that matters not the cmdline, so check `CMAKE_CXX_SIMULATE_ID` too, if it is `MSVC` the current compiler is targeting the MSVC ABI. This handles `clang++`
1 parent 3441176 commit c9106a7

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed
 

‎AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Evgeny Safronov <division494@gmail.com>
3131
Fabien Pichot <pichot.fabien@gmail.com>
3232
Federico Ficarelli <federico.ficarelli@gmail.com>
3333
Felix Homann <linuxaudio@showlabor.de>
34+
Gergely Meszaros <maetveis@gmail.com>
3435
Gergő Szitár <szitar.gergo@gmail.com>
3536
Google Inc.
3637
Henrique Bucher <hbucher@gmail.com>

‎CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if(BENCHMARK_FORCE_WERROR)
2121
set(BENCHMARK_ENABLE_WERROR ON)
2222
endif(BENCHMARK_FORCE_WERROR)
2323

24-
if(NOT MSVC)
24+
if(NOT (MSVC OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC"))
2525
option(BENCHMARK_BUILD_32_BITS "Build a 32 bit version of the library." OFF)
2626
else()
2727
set(BENCHMARK_BUILD_32_BITS OFF CACHE BOOL "Build a 32 bit version of the library - unsupported when using MSVC)" FORCE)
@@ -45,7 +45,7 @@ option(BENCHMARK_ENABLE_LIBPFM "Enable performance counters provided by libpfm"
4545
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
4646
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
4747

48-
if(MSVC)
48+
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
4949
# As of CMake 3.18, CMAKE_SYSTEM_PROCESSOR is not set properly for MSVC and
5050
# cross-compilation (e.g. Host=x86_64, target=aarch64) requires using the
5151
# undocumented, but working variable.
@@ -66,7 +66,7 @@ function(should_enable_assembly_tests)
6666
return()
6767
endif()
6868
endif()
69-
if (MSVC)
69+
if (MSVC OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
7070
return()
7171
elseif(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
7272
return()
@@ -128,7 +128,7 @@ if (BENCHMARK_BUILD_32_BITS)
128128
add_required_cxx_compiler_flag(-m32)
129129
endif()
130130

131-
if (MSVC)
131+
if (MSVC OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
132132
set(BENCHMARK_CXX_STANDARD 14)
133133
else()
134134
set(BENCHMARK_CXX_STANDARD 11)

‎CONTRIBUTORS

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Fanbo Meng <fanbo.meng@ibm.com>
5151
Federico Ficarelli <federico.ficarelli@gmail.com>
5252
Felix Homann <linuxaudio@showlabor.de>
5353
Geoffrey Martin-Noble <gcmn@google.com> <gmngeoffrey@gmail.com>
54+
Gergely Meszaros <maetveis@gmail.com>
5455
Gergő Szitár <szitar.gergo@gmail.com>
5556
Hannes Hauswedell <h2@fsfe.org>
5657
Henrique Bucher <hbucher@gmail.com>

‎test/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ compile_output_test(memory_manager_test)
183183
add_test(NAME memory_manager_test COMMAND memory_manager_test --benchmark_min_time=0.01s)
184184

185185
# MSVC does not allow to set the language standard to C++98/03.
186-
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
186+
if(NOT (MSVC OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC"))
187187
compile_benchmark_test(cxx03_test)
188188
set_target_properties(cxx03_test
189189
PROPERTIES

0 commit comments

Comments
 (0)
Please sign in to comment.