summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorJon Olav Hauglid <jon.hauglid@oracle.com>2014-10-13 09:52:28 +0200
committerJon Olav Hauglid <jon.hauglid@oracle.com>2014-10-13 09:52:28 +0200
commit8b64f825058a2439903e9420552641ca6105d9d6 (patch)
tree5e4595b95c1636b3a7f3d889de96da08676d4b19 /cmake
parenta3cc647dbdbdeb0f2e9c9ac55ffe062c659d82dc (diff)
downloadmariadb-git-8b64f825058a2439903e9420552641ca6105d9d6.tar.gz
Bug#17633291: SET PROPER COMPILE OPTIONS FOR CLANG
Bug#17959689: MAKE GCC AND CLANG GIVE CONSISTENT COMPILATION WARNINGS Bug#18313717: ENABLE -WERROR IN MAINTANER MODE WHEN COMPILING WITH CLANG Bug#18510941: REMOVE CMAKE WORKAROUNDS FOR OLDER VERSIONS OF OS X/XCODE Backport from mysql-5.6 to mysql-5.5
Diffstat (limited to 'cmake')
-rw-r--r--cmake/build_configurations/mysql_release.cmake19
-rw-r--r--cmake/compile_flags.cmake44
-rw-r--r--cmake/maintainer.cmake67
-rw-r--r--cmake/os/Darwin.cmake21
4 files changed, 87 insertions, 64 deletions
diff --git a/cmake/build_configurations/mysql_release.cmake b/cmake/build_configurations/mysql_release.cmake
index e2b815ef830..b0d3de10299 100644
--- a/cmake/build_configurations/mysql_release.cmake
+++ b/cmake/build_configurations/mysql_release.cmake
@@ -189,15 +189,16 @@ IF(UNIX)
ENDIF()
ENDIF()
- # OSX flags
- IF(APPLE)
- SET(COMMON_C_FLAGS "-g -fno-common -fno-strict-aliasing")
- # XXX: why are we using -felide-constructors on OSX?
- SET(COMMON_CXX_FLAGS "-g -fno-common -felide-constructors -fno-strict-aliasing")
- SET(CMAKE_C_FLAGS_DEBUG "-O ${COMMON_C_FLAGS}")
- SET(CMAKE_CXX_FLAGS_DEBUG "-O ${COMMON_CXX_FLAGS}")
- SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-Os ${COMMON_C_FLAGS}")
- SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Os ${COMMON_CXX_FLAGS}")
+ # Default Clang flags
+ IF(CMAKE_C_COMPILER_ID MATCHES "Clang")
+ SET(COMMON_C_FLAGS "-g -fno-omit-frame-pointer -fno-strict-aliasing")
+ SET(CMAKE_C_FLAGS_DEBUG "${COMMON_C_FLAGS}")
+ SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 ${COMMON_C_FLAGS}")
+ ENDIF()
+ IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ SET(COMMON_CXX_FLAGS "-g -fno-omit-frame-pointer -fno-strict-aliasing")
+ SET(CMAKE_CXX_FLAGS_DEBUG "${COMMON_CXX_FLAGS}")
+ SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 ${COMMON_CXX_FLAGS}")
ENDIF()
# Solaris flags
diff --git a/cmake/compile_flags.cmake b/cmake/compile_flags.cmake
new file mode 100644
index 00000000000..5e872f981b0
--- /dev/null
+++ b/cmake/compile_flags.cmake
@@ -0,0 +1,44 @@
+# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+## ADD_COMPILE_FLAGS(<source files> COMPILE_FLAGS <flags>)
+MACRO(ADD_COMPILE_FLAGS)
+ SET(FILES "")
+ SET(FLAGS "")
+ SET(COMPILE_FLAGS)
+ FOREACH(ARG ${ARGV})
+ IF(ARG STREQUAL "COMPILE_FLAGS")
+ SET(COMPILE_FLAGS "COMPILE_FLAGS")
+ ELSEIF(COMPILE_FLAGS)
+ LIST(APPEND FLAGS ${ARG})
+ ELSE()
+ LIST(APPEND FILES ${ARG})
+ ENDIF()
+ ENDFOREACH()
+ FOREACH(FILE ${FILES})
+ FOREACH(FLAG ${FLAGS})
+ GET_SOURCE_FILE_PROPERTY(PROP ${FILE} COMPILE_FLAGS)
+ IF(NOT PROP)
+ SET(PROP ${FLAG})
+ ELSE()
+ SET(PROP "${PROP} ${FLAG}")
+ ENDIF()
+ SET_SOURCE_FILES_PROPERTIES(
+ ${FILE} PROPERTIES COMPILE_FLAGS "${PROP}"
+ )
+ ENDFOREACH()
+ ENDFOREACH()
+ENDMACRO()
diff --git a/cmake/maintainer.cmake b/cmake/maintainer.cmake
index a91905a281b..c537d00260f 100644
--- a/cmake/maintainer.cmake
+++ b/cmake/maintainer.cmake
@@ -1,4 +1,4 @@
-# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -13,42 +13,39 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-INCLUDE(CheckCCompilerFlag)
+# Common warning flags for GCC, G++, Clang and Clang++
+SET(MY_WARNING_FLAGS "-Wall -Wextra -Wformat-security")
+MY_CHECK_C_COMPILER_FLAG("-Wvla" HAVE_WVLA) # Requires GCC 4.3+ or Clang
+IF(HAVE_WVLA)
+ SET(MY_WARNING_FLAGS "${MY_WARNING_FLAGS} -Wvla")
+ENDIF()
-# Setup GCC (GNU C compiler) warning options.
-MACRO(SET_MYSQL_MAINTAINER_GNU_C_OPTIONS)
- SET(MY_MAINTAINER_WARNINGS
- "-Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Werror")
- CHECK_C_COMPILER_FLAG("-Wdeclaration-after-statement"
- HAVE_DECLARATION_AFTER_STATEMENT)
- IF(HAVE_DECLARATION_AFTER_STATEMENT)
- SET(MY_MAINTAINER_DECLARATION_AFTER_STATEMENT
- "-Wdeclaration-after-statement")
- ENDIF()
- SET(MY_MAINTAINER_C_WARNINGS
- "${MY_MAINTAINER_WARNINGS} ${MY_MAINTAINER_DECLARATION_AFTER_STATEMENT}"
- CACHE STRING "C warning options used in maintainer builds.")
- # Do not make warnings in checks into errors.
- SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wno-error")
-ENDMACRO()
+# Common warning flags for GCC and Clang
+SET(MY_C_WARNING_FLAGS
+ "${MY_WARNING_FLAGS} -Wwrite-strings -Wdeclaration-after-statement")
-# Setup G++ (GNU C++ compiler) warning options.
-MACRO(SET_MYSQL_MAINTAINER_GNU_CXX_OPTIONS)
- SET(MY_MAINTAINER_CXX_WARNINGS
- "${MY_MAINTAINER_WARNINGS} -Wno-unused-parameter -Woverloaded-virtual"
- CACHE STRING "C++ warning options used in maintainer builds.")
-ENDMACRO()
+# Common warning flags for G++ and Clang++
+SET(MY_CXX_WARNING_FLAGS
+ "${MY_WARNING_FLAGS} -Woverloaded-virtual -Wno-unused-parameter")
-# Setup ICC (Intel C Compiler) warning options.
-MACRO(SET_MYSQL_MAINTAINER_INTEL_C_OPTIONS)
- SET(MY_MAINTAINER_WARNINGS "-Wcheck")
- SET(MY_MAINTAINER_C_WARNINGS "${MY_MAINTAINER_WARNINGS}"
- CACHE STRING "C warning options used in maintainer builds.")
-ENDMACRO()
+# Extra warning flags for Clang++
+IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ SET(MY_CXX_WARNING_FLAGS
+ "${MY_CXX_WARNING_FLAGS} -Wno-null-conversion -Wno-unused-private-field")
+ENDIF()
-# Setup ICPC (Intel C++ Compiler) warning options.
-MACRO(SET_MYSQL_MAINTAINER_INTEL_CXX_OPTIONS)
- SET(MY_MAINTAINER_CXX_WARNINGS "${MY_MAINTAINER_WARNINGS}"
- CACHE STRING "C++ warning options used in maintainer builds.")
-ENDMACRO()
+# Turn on Werror (warning => error) when using maintainer mode.
+IF(MYSQL_MAINTAINER_MODE)
+ SET(MY_C_WARNING_FLAGS "${MY_C_WARNING_FLAGS} -Werror")
+ SET(MY_CXX_WARNING_FLAGS "${MY_CXX_WARNING_FLAGS} -Werror")
+ SET(COMPILE_FLAG_WERROR 1)
+ENDIF()
+# Set warning flags for GCC/Clang
+IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_C_WARNING_FLAGS}")
+ENDIF()
+# Set warning flags for G++/Clang++
+IF(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MY_CXX_WARNING_FLAGS}")
+ENDIF()
diff --git a/cmake/os/Darwin.cmake b/cmake/os/Darwin.cmake
index 0d8bac106f0..4ac72070e8b 100644
--- a/cmake/os/Darwin.cmake
+++ b/cmake/os/Darwin.cmake
@@ -1,5 +1,4 @@
-# Copyright (c) 2010 Sun Microsystems, Inc.
-# Use is subject to license terms.
+# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -15,21 +14,3 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# This file includes OSX specific options and quirks, related to system checks
-
-# Workaround for CMake bug#9051
-# (CMake does not pass CMAKE_OSX_SYSROOT and CMAKE_OSX_DEPLOYMENT_TARGET when
-# running TRY_COMPILE)
-
-IF(CMAKE_OSX_SYSROOT)
- SET(ENV{CMAKE_OSX_SYSROOT} ${CMAKE_OSX_SYSROOT})
-ENDIF()
-IF(CMAKE_OSX_SYSROOT)
- SET(ENV{MACOSX_DEPLOYMENT_TARGET} ${OSX_DEPLOYMENT_TARGET})
-ENDIF()
-
-IF(CMAKE_OSX_DEPLOYMENT_TARGET)
- # Workaround linker problems on OSX 10.4
- IF(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS "10.5")
- ADD_DEFINITIONS(-fno-common)
- ENDIF()
-ENDIF()