Skip to content

Commit 2a2e30d

Browse files
committed
Bug#19187034: ADD COMPILER VERSION CHECKS TO CMAKE
Add CMake checks for minimum version of supported compilers: gcc (Linux, Solaris): 4.4 Sun Studio (Solaris client lib): 12u2 clang (Mac OS X, FreeBSD): 3.3 A similar check for Visual Studio 2013 already exists. The patch also adds a new CMake option -DFORCE_UNSPPORTED_COMPILER which if set disables the compiler version check.
1 parent 72858cc commit 2a2e30d

File tree

6 files changed

+91
-3
lines changed

6 files changed

+91
-3
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ ENDIF()
232232
IF(NOT WITHOUT_SERVER)
233233
OPTION (WITH_UNIT_TESTS "Compile MySQL with unit tests" ON)
234234
ENDIF()
235-
MARK_AS_ADVANCED(WITHOUT_SERVER DISABLE_SHARED)
235+
OPTION(FORCE_UNSUPPORTED_COMPILER "Disable compiler version checks" OFF)
236+
MARK_AS_ADVANCED(WITHOUT_SERVER DISABLE_SHARED FORCE_UNSUPPORTED_COMPILER)
236237

237238

238239
include(CheckCSourceCompiles)

cmake/os/Darwin.cmake

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -15,6 +15,25 @@
1515

1616
# This file includes OSX specific options and quirks, related to system checks
1717

18+
INCLUDE(CheckCSourceRuns)
19+
20+
# We require at least Clang 3.3 (XCode 5).
21+
IF(NOT FORCE_UNSUPPORTED_COMPILER)
22+
IF(CMAKE_C_COMPILER_ID MATCHES "Clang")
23+
CHECK_C_SOURCE_RUNS("
24+
int main()
25+
{
26+
return (__clang_major__ < 3) ||
27+
(__clang_major__ == 3 && __clang_minor__ < 3);
28+
}" HAVE_SUPPORTED_CLANG_VERSION)
29+
IF(NOT HAVE_SUPPORTED_CLANG_VERSION)
30+
MESSAGE(FATAL_ERROR "Clang 3.3 or newer is required!")
31+
ENDIF()
32+
ELSE()
33+
MESSAGE(FATAL_ERROR "Unsupported compiler!")
34+
ENDIF()
35+
ENDIF()
36+
1837
# This is used for the version_compile_machine variable.
1938
IF(CMAKE_SIZEOF_VOID_P MATCHES 8)
2039
SET(MYSQL_MACHINE_TYPE "x86_64")

cmake/os/FreeBSD.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@
1616

1717
# This file includes FreeBSD specific options and quirks, related to system checks
1818

19+
INCLUDE(CheckCSourceRuns)
20+
21+
# We require at least Clang 3.3.
22+
IF(NOT FORCE_UNSUPPORTED_COMPILER)
23+
IF(CMAKE_C_COMPILER_ID MATCHES "Clang")
24+
CHECK_C_SOURCE_RUNS("
25+
int main()
26+
{
27+
return (__clang_major__ < 3) ||
28+
(__clang_major__ == 3 && __clang_minor__ < 3);
29+
}" HAVE_SUPPORTED_CLANG_VERSION)
30+
IF(NOT HAVE_SUPPORTED_CLANG_VERSION)
31+
MESSAGE(FATAL_ERROR "Clang 3.3 or newer is required!")
32+
ENDIF()
33+
ELSE()
34+
MESSAGE(FATAL_ERROR "Unsupported compiler!")
35+
ENDIF()
36+
ENDIF()
37+
1938
# Should not be needed any more, but kept for easy resurrection if needed
2039
# #Legacy option, maybe not needed anymore , taken as is from autotools build
2140
# ADD_DEFINITIONS(-DNET_RETRY_COUNT=1000000)

cmake/os/Linux.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@
1717
# This file includes Linux specific options and quirks, related to system checks
1818

1919
INCLUDE(CheckSymbolExists)
20+
INCLUDE(CheckCSourceRuns)
21+
22+
# We require at least GCC 4.4 or Clang 3.3.
23+
IF(NOT FORCE_UNSUPPORTED_COMPILER)
24+
IF(CMAKE_COMPILER_IS_GNUCC)
25+
EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -dumpversion
26+
OUTPUT_VARIABLE GCC_VERSION)
27+
IF(GCC_VERSION VERSION_LESS 4.4)
28+
MESSAGE(FATAL_ERROR "GCC 4.4 or newer is required!")
29+
ENDIF()
30+
ELSEIF(CMAKE_C_COMPILER_ID MATCHES "Clang")
31+
CHECK_C_SOURCE_RUNS("
32+
int main()
33+
{
34+
return (__clang_major__ < 3) ||
35+
(__clang_major__ == 3 && __clang_minor__ < 3);
36+
}" HAVE_SUPPORTED_CLANG_VERSION)
37+
IF(NOT HAVE_SUPPORTED_CLANG_VERSION)
38+
MESSAGE(FATAL_ERROR "Clang 3.3 or newer is required!")
39+
ENDIF()
40+
ELSE()
41+
MESSAGE(FATAL_ERROR "Unsupported compiler!")
42+
ENDIF()
43+
ENDIF()
2044

2145
# ISO C89, ISO C99, POSIX.1, POSIX.2, BSD, SVID, X/Open, LFS, and GNU extensions.
2246
ADD_DEFINITIONS(-D_GNU_SOURCE)

cmake/os/SunOS.cmake

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@ INCLUDE(CheckCSourceRuns)
1818
INCLUDE(CheckCSourceCompiles)
1919
INCLUDE(CheckCXXSourceCompiles)
2020

21+
# We require at least GCC 4.4 or SunStudio 12u2 (CC 5.11)
22+
IF(NOT FORCE_UNSUPPORTED_COMPILER)
23+
IF(CMAKE_COMPILER_IS_GNUCC)
24+
EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -dumpversion
25+
OUTPUT_VARIABLE GCC_VERSION)
26+
IF(GCC_VERSION VERSION_LESS 4.4)
27+
MESSAGE(FATAL_ERROR "GCC 4.4 or newer is required!")
28+
ENDIF()
29+
ELSEIF(CMAKE_C_COMPILER_ID MATCHES "SunPro")
30+
EXECUTE_PROCESS(
31+
COMMAND ${CMAKE_CXX_COMPILER} "-V"
32+
OUTPUT_VARIABLE stdout
33+
ERROR_VARIABLE stderr
34+
RESULT_VARIABLE result
35+
)
36+
STRING(REGEX MATCH "CC: Sun C\\+\\+ 5\\.([0-9]+)" VERSION_STRING ${stderr})
37+
SET(MINOR_VERSION ${CMAKE_MATCH_1})
38+
IF(${MINOR_VERSION} LESS 11)
39+
MESSAGE(FATAL_ERROR "SunStudio 12u2 or newer is required!")
40+
ENDIF()
41+
ELSE()
42+
MESSAGE(FATAL_ERROR "Unsupported compiler!")
43+
ENDIF()
44+
ENDIF()
45+
2146
# Enable 64 bit file offsets
2247
ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64)
2348

cmake/os/Windows.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ GET_FILENAME_COMPONENT(_SCRIPT_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
3636
INCLUDE(${_SCRIPT_DIR}/WindowsCache.cmake)
3737

3838
# We require at least Visual Studio 2013 (aka 12.0) which has version nr 1800.
39-
IF(MSVC_VERSION LESS 1800)
39+
IF(NOT FORCE_UNSUPPORTED_COMPILER AND MSVC_VERSION LESS 1800)
4040
MESSAGE(FATAL_ERROR "Visual Studio 2013 or newer is required!")
4141
ENDIF()
4242

0 commit comments

Comments
 (0)