diff options
author | Vladislav Vaintroub <wlad@mariadb.com> | 2018-02-20 21:17:36 +0000 |
---|---|---|
committer | Vladislav Vaintroub <wlad@mariadb.com> | 2018-02-20 21:17:36 +0000 |
commit | 56e7b7eaede52e8d2123e909d7d42220f8c63143 (patch) | |
tree | 73e1dc4b2e53d68c3a9d5269f9140142ef08c187 /cmake | |
parent | 9d97e6010ebdeab0579a8371d01f34118c518b30 (diff) | |
download | mariadb-git-56e7b7eaede52e8d2123e909d7d42220f8c63143.tar.gz |
Make possible to use clang on Windows (clang-cl)
-DWITH_ASAN can be used as well now, on x64
Fix many clang-cl warnings.
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/maintainer.cmake | 4 | ||||
-rw-r--r-- | cmake/os/Windows.cmake | 50 |
2 files changed, 50 insertions, 4 deletions
diff --git a/cmake/maintainer.cmake b/cmake/maintainer.cmake index 6993bae3975..4a13edceece 100644 --- a/cmake/maintainer.cmake +++ b/cmake/maintainer.cmake @@ -13,6 +13,10 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +IF(MSVC) + RETURN() +ENDIF() + # Common warning flags for GCC, G++, Clang and Clang++ SET(MY_WARNING_FLAGS -Wall diff --git a/cmake/os/Windows.cmake b/cmake/os/Windows.cmake index aa948a7f5b2..3935894781e 100644 --- a/cmake/os/Windows.cmake +++ b/cmake/os/Windows.cmake @@ -59,7 +59,41 @@ IF(MINGW AND CMAKE_SIZEOF_VOID_P EQUAL 4) ADD_DEFINITIONS(-march=i486) ENDIF() +FUNCTION(ENABLE_ASAN) + IF(NOT (MSVC AND CMAKE_CXX_COMPILER_ID MATCHES Clang)) + MESSAGE(FATAL_ERROR "clang-cl is necessary to enable asan") + ENDIF() + # currently, asan is broken with static CRT. + IF(NOT(MSVC_CRT_TYPE STREQUAL "/MD")) + MESSAGE(FATAL_ERROR "-DWITH_ASAN cmake parameter also requires -DMSVC_CRT_TYPE=/MD") + ENDIF() + IF(CMAKE_SIZEOF_VOID_P EQUAL 4) + MESSAGE(FATAL_ERROR "-DWITH_ASAN on Windows requires 64bit build") + ENDIF() + # After installation, clang lib directory should be added to PATH + # (e.g C:/Program Files/LLVM/lib/clang/5.0.1/lib/windows) + FIND_LIBRARY(CLANG_RT_ASAN_DYNAMIC clang_rt.asan_dynamic-x86_64.lib) + IF(NOT CLANG_RT_ASAN_DYNAMIC) + MESSAGE(FATAL_ERROR "Can't enable ASAN : missing clang_rt.asan_dynamic-x86_64.lib") + ENDIF() + + FIND_LIBRARY(CLANG_RT_ASAN_DYNAMIC_THUNK clang_rt.asan_dynamic_runtime_thunk-x86_64.lib) + IF(NOT CLANG_RT_ASAN_DYNAMIC_THUNK) + MESSAGE(FATAL_ERROR "Can't enable ASAN : missing clang_rt.asan_dynamic_runtime_thunk-x86_64.lib") + ENDIF() + + STRING(APPEND CMAKE_C_FLAGS " -fsanitize=address") + STRING(APPEND CMAKE_CXX_FLAGS " -fsanitize=address") + + LINK_LIBRARIES(${CLANG_RT_ASAN_DYNAMIC} ${CLANG_RT_ASAN_DYNAMIC_THUNK}) +ENDFUNCTION() + + IF(MSVC) + IF(WITH_ASAN) + ENABLE_ASAN() + ENDIF() + # Disable mingw based pkg-config found in Strawberry perl SET(PKG_CONFIG_EXECUTABLE 0 CACHE INTERNAL "") SET(MSVC_CRT_TYPE /MT CACHE STRING @@ -119,8 +153,16 @@ IF(MSVC) STRING(APPEND ${flag} " /Z7") ENDIF() ENDFOREACH() - - + + IF(CMAKE_CXX_COMPILER_ID MATCHES Clang) + SET(CLANG_CL_FLAGS +"-Wno-unused-parameter -Wno-unused-command-line-argument -Wno-pointer-sign -Wno-deprecated-register \ +-Wno-missing-braces -Wno-unused-function -msse4.2 " + ) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CLANG_CL_FLAGS}") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CLANG_CL_FLAGS}") + ENDIF() + # Fix CMake's predefined huge stack size FOREACH(type EXE SHARED MODULE) STRING(REGEX REPLACE "/STACK:([^ ]+)" "" CMAKE_${type}_LINKER_FLAGS "${CMAKE_${type}_LINKER_FLAGS}") @@ -139,7 +181,7 @@ IF(MSVC) ENDIF() # Speed up multiprocessor build - IF (MSVC_VERSION GREATER 1400) + IF (MSVC_VERSION GREATER 1400 AND (NOT CMAKE_CXX_COMPILER_ID MATCHES Clang)) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") ENDIF() @@ -147,7 +189,7 @@ 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) + IF(MSVC_VERSION GREATER 1910 AND (NOT CMAKE_CXX_COMPILER_ID MATCHES Clang)) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-") ENDIF() ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_WARNINGS) |