cmake: Fix build with Clang/CL

It is possible to use the Clang/CL compiler when targeting MSVC;
unfortunately, not only this flavour requires using the same flags
as GCC to handle intrinsics codegen, the default is solely SSE2
(like with stock Clang, and unlike MSVC's own default of SSE4.1 [1]).
The MSVC STL also requires C++14. For this reason, when the GNU
flavour is detected, we apply the correct flag style and use C++14
as the C++ standard.

An additional fix is also needed so that the glibc math library
isn't linked against when using this kind of Clang compiler.

This fixes compiling aom with Clang/CL 15.0.1 (MSVC 17.6 Preview 3).

[1]: https://learn.microsoft.com/en-us/cpp/build/reference/arch-x64
for the x86_64 case.

Change-Id: I54140a1645f539944657c2b18dd801b57e422216
(cherry picked from commit 9763f658502e19b352ec2ae66a06b5bf6491e50b)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8324401..68828d7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -297,7 +297,7 @@
   endif()
 endif()
 
-if(NOT MSVC AND NOT APPLE)
+if(NOT WIN32 AND NOT APPLE)
   target_link_libraries(aom ${AOM_LIB_LINK_TYPE} m)
   if(BUILD_SHARED_LIBS)
     target_link_libraries(aom_static ${AOM_LIB_LINK_TYPE} m)
@@ -309,7 +309,7 @@
               "${AOM_ROOT}/av1/ratectrl_rtc.cc")
   add_library(aom_av1_rc ${AOM_AV1_RC_SOURCES})
   target_link_libraries(aom_av1_rc ${AOM_LIB_LINK_TYPE} aom)
-  if(NOT MSVC AND NOT APPLE)
+  if(NOT WIN32 AND NOT APPLE)
     target_link_libraries(aom_av1_rc ${AOM_LIB_LINK_TYPE} m)
   endif()
 endif()
diff --git a/build/cmake/aom_configure.cmake b/build/cmake/aom_configure.cmake
index ee566af..c878665 100644
--- a/build/cmake/aom_configure.cmake
+++ b/build/cmake/aom_configure.cmake
@@ -248,7 +248,7 @@
 set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
 aom_check_source_compiles("unistd_check" "#include <unistd.h>" HAVE_UNISTD_H)
 
-if(NOT MSVC)
+if(NOT WIN32)
   aom_push_var(CMAKE_REQUIRED_LIBRARIES "m")
   aom_check_c_compiles("fenv_check" "#define _GNU_SOURCE
                         #include <fenv.h>
@@ -300,7 +300,11 @@
   endif()
 else()
   require_c_flag("-std=c99" YES)
-  require_cxx_flag_nomsvc("-std=c++11" YES)
+  if(WIN32 AND NOT MINGW)
+    require_cxx_flag_nomsvc("-std=c++14" YES)
+  else()
+    require_cxx_flag_nomsvc("-std=c++11" YES)
+  endif()
   add_compiler_flag_if_supported("-Wall")
   add_compiler_flag_if_supported("-Wdisabled-optimization")
   add_compiler_flag_if_supported("-Wextra")
diff --git a/build/cmake/aom_optimization.cmake b/build/cmake/aom_optimization.cmake
index 1dd6c3b..e48c52b 100644
--- a/build/cmake/aom_optimization.cmake
+++ b/build/cmake/aom_optimization.cmake
@@ -46,7 +46,8 @@
   add_library(${target_name} OBJECT ${${sources}})
   set_property(TARGET ${target_name} PROPERTY FOLDER ${AOM_TARGET_CPU})
 
-  if(MSVC)
+  # Clang/CL requires the -mXXX flag. The MSVC version is not granular enough.
+  if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
     get_msvc_intrinsic_flag("${flag}" "flag")
   endif()