From 1b58ef7d3f9d9913437f7a53d11ba7b03ea91cf7 Mon Sep 17 00:00:00 2001
From: Vladislav Vaintroub <wlad@mariadb.com>
Date: Wed, 25 Mar 2020 15:09:14 +0100
Subject: [PATCH] Build cleanups.

Fix clang-cl built
---
 cmake/mysql_version.cmake       |  2 +-
 cmake/os/Windows.cmake          | 15 ++++++++++-----
 extra/mariabackup/xtrabackup.cc | 10 +++++-----
 3 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/cmake/mysql_version.cmake b/cmake/mysql_version.cmake
index 85273136a32..cf95620e4ba 100644
--- a/cmake/mysql_version.cmake
+++ b/cmake/mysql_version.cmake
@@ -115,7 +115,7 @@ ENDIF()
 # Add version information to the exe and dll files
 # Refer to http://msdn.microsoft.com/en-us/library/aa381058(VS.85).aspx
 # for more info.
-IF(MSVC)
+IF(MSVC AND NOT CLANG_CL)
     # Tiny version is used to identify the build, it can be set with cmake -DTINY_VERSION=<number>
     # to bzr revno for example (in the CI builds)
     IF(NOT TINY_VERSION)
diff --git a/cmake/os/Windows.cmake b/cmake/os/Windows.cmake
index 1fbb1774bf7..6845bd86a26 100644
--- a/cmake/os/Windows.cmake
+++ b/cmake/os/Windows.cmake
@@ -46,6 +46,10 @@ IF(CMAKE_C_COMPILER MATCHES "icl")
  SET(MSVC TRUE)
 ENDIF()
 
+IF(MSVC  AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
+ SET(CLANG_CL TRUE)
+ENDIF()
+
 ADD_DEFINITIONS(-D_WINDOWS -D__WIN__ -D_CRT_SECURE_NO_DEPRECATE)
 ADD_DEFINITIONS(-D_WIN32_WINNT=0x0A00)
 # We do not want the windows.h macros min/max
@@ -60,7 +64,7 @@ IF(MINGW AND CMAKE_SIZEOF_VOID_P EQUAL 4)
 ENDIF()
 
 FUNCTION(ENABLE_ASAN)
-  IF(NOT (MSVC AND CMAKE_CXX_COMPILER_ID MATCHES Clang))
+  IF(NOT CLANG_CL)
     MESSAGE(FATAL_ERROR "clang-cl is necessary to enable asan")
   ENDIF()
   # currently, asan is broken with static CRT.
@@ -141,7 +145,7 @@ IF(MSVC)
    ENDIF()
   ENDFOREACH()
 
-  IF(CMAKE_CXX_COMPILER_ID MATCHES Clang)
+  IF(CLANG_CL)
      SET(CLANG_CL_FLAGS
 "-Wno-unknown-warning-option -Wno-unused-private-field \
 -Wno-unused-parameter -Wno-inconsistent-missing-override \
@@ -173,7 +177,7 @@ IF(MSVC)
   ENDIF()
   
   # Speed up multiprocessor build
-  IF (NOT CMAKE_CXX_COMPILER_ID MATCHES Clang)
+  IF (NOT CLANG_CL)
     SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
   ENDIF()
@@ -181,13 +185,14 @@ IF(MSVC)
   #TODO: update the code and remove the disabled warnings
   SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /we4700 /we4311 /we4477 /we4302 /we4090")
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /we4099 /we4700 /we4311 /we4477 /we4302 /we4090")
-  IF(MSVC_VERSION GREATER 1910  AND (NOT CMAKE_CXX_COMPILER_ID MATCHES Clang))
+  IF(MSVC_VERSION GREATER 1910  AND NOT CLANG_CL)
     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-")
   ENDIF()
   ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_WARNINGS)
   IF(MYSQL_MAINTAINER_MODE MATCHES "ERR")
     SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
+	MESSAGE("MEH")
     FOREACH(type EXE SHARED MODULE)
       FOREACH(cfg RELEASE DEBUG RELWITHDEBINFO)
         SET(CMAKE_${type}_LINKER_FLAGS_${cfg} "${CMAKE_${type}_LINKER_FLAGS_${cfg}} /WX")
@@ -198,7 +203,7 @@ IF(MSVC)
     # Noisy warning C4800: 'type': forcing value to bool 'true' or 'false' (performance warning),
     # removed in VS2017
     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4800")
-  ELSEIF (NOT (CMAKE_CXX_COMPILER_ID MATCHES Clang))
+  ELSEIF (NOT CLANG_CL)
     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /d2OptimizeHugeFunctions")
   ENDIF()
 ENDIF()
diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc
index 6896205238b..3328e0a535e 100644
--- a/extra/mariabackup/xtrabackup.cc
+++ b/extra/mariabackup/xtrabackup.cc
@@ -229,8 +229,8 @@ parameters are declared in mysqld.cc: */
 
 long innobase_buffer_pool_awe_mem_mb = 0;
 long innobase_file_io_threads = 4;
-long innobase_read_io_threads = 4;
-long innobase_write_io_threads = 4;
+ulong innobase_read_io_threads = 4;
+ulong innobase_write_io_threads = 4;
 
 longlong innobase_page_size = (1LL << 14); /* 16KB */
 char*	innobase_buffer_pool_filename = NULL;
@@ -1879,8 +1879,8 @@ static bool innodb_init_param()
 	srv_buf_pool_chunk_unit = (ulong)srv_buf_pool_size;
 
 	srv_n_file_io_threads = (ulint) innobase_file_io_threads;
-	srv_n_read_io_threads = (ulint) innobase_read_io_threads;
-	srv_n_write_io_threads = (ulint) innobase_write_io_threads;
+	srv_n_read_io_threads = innobase_read_io_threads;
+	srv_n_write_io_threads = innobase_write_io_threads;
 
 	srv_max_n_open_files = ULINT_UNDEFINED - 5;
 
@@ -3803,7 +3803,7 @@ end:
 	return static_cast<ulong>(max_file_limit);
 }
 #else
-# define xb_set_max_open_files(x) 0
+# define xb_set_max_open_files(x) 0UL
 #endif
 
 static void stop_backup_threads()