Skip to content

Commit 34c5c96

Browse files
committed
CDRIVER-2145 CMake option ENABLE_MAINTAINER_FLAGS
1 parent a048098 commit 34c5c96

File tree

8 files changed

+87
-27
lines changed

8 files changed

+87
-27
lines changed

.evergreen/compile-windows.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set -o errexit # Exit the script with error if any of the commands fail
1111

1212

1313
INSTALL_DIR="C:/mongoc"
14-
CONFIGURE_FLAGS="-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DENABLE_AUTOMATIC_INIT_AND_CLEANUP:BOOL=OFF"
14+
CONFIGURE_FLAGS="-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DENABLE_AUTOMATIC_INIT_AND_CLEANUP:BOOL=OFF -DENABLE_MAINTAINER_FLAGS=ON"
1515
BUILD_FLAGS="/m" # Number of concurrent processes. No value=# of cpus
1616
CMAKE="/cygdrive/c/cmake/bin/cmake"
1717
CC=${CC:-"Visual Studio 14 2015 Win64"}

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
cmake_minimum_required(VERSION 3.1)
22

3+
set (MESSAGES_ENABLED 1)
4+
5+
function(message)
6+
list (GET ARGV 0 MessageType)
7+
if (MESSAGES_ENABLED)
8+
list (REMOVE_AT ARGV 0)
9+
_message (${MessageType} "${ARGV}")
10+
endif()
11+
endfunction()
12+
313
set (ENABLE_SSL AUTO CACHE STRING
414
"Enable TLS connections and SCRAM-SHA-1 authentication.\ Options are
515
\"DARWIN\" to use Apple's Secure Transport, \"WINDOWS\" to use Windows
@@ -15,6 +25,7 @@ set (ENABLE_SASL AUTO CACHE STRING
1525
set(ENABLE_STATIC AUTO CACHE STRING "Build static libmongoc. Set to ON/AUTO/OFF, default AUTO.")
1626
option(ENABLE_TESTS "Build MongoDB C Driver tests." ON)
1727
option(ENABLE_EXAMPLES "Build MongoDB C Driver examples." ON)
28+
option(ENABLE_MAINTAINER_FLAGS "Use strict compiler checks" OFF)
1829
option(ENABLE_AUTOMATIC_INIT_AND_CLEANUP "Enable automatic init and cleanup (GCC only)" ON)
1930
option(ENABLE_CRYPTO_SYSTEM_PROFILE "Use system crypto profile (OpenSSL only)" OFF)
2031
option(ENABLE_TRACING "Turn on verbose debug output" OFF)
@@ -45,6 +56,8 @@ if (NOT ${MONGOC_VERSION} STREQUAL ${MONGOC_RELEASED_VERSION})
4556
message("Previous release (from VERSION_RELEASED file): ${MONGOC_RELEASED_VERSION}")
4657
endif()
4758

59+
include(MaintainerFlags)
60+
4861
# The input variable BSON_ROOT_DIR is respected for backwards compatibility,
4962
# but you should use the standard CMAKE_PREFIX_PATH instead.
5063
message (STATUS "Searching for libbson CMake packages")
@@ -367,6 +380,8 @@ if (APPLE)
367380
add_definitions(-Wno-deprecated-declarations)
368381
endif()
369382

383+
include (MaintainerFlags)
384+
370385
set (SOURCES
371386
${SOURCE_DIR}/src/mongoc/mongoc-apm.c
372387
${SOURCE_DIR}/src/mongoc/mongoc-array.c

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ include examples/Makefile.am
3535
endif
3636

3737
# for EXTRA_DIST
38-
include build/cmake/Makefile.am
38+
include build/Makefile.am
3939

4040
ACLOCAL_AMFLAGS = -I build/autotools/m4 ${ACLOCAL_FLAGS}
4141
DISTCHECK_CONFIGURE_FLAGS = --enable-silent-rules --enable-man-pages --enable-html-docs --enable-sasl --enable-ssl --enable-maintainer-flags --enable-debug --with-libbson=bundled --with-snappy=bundled --with-zlib=bundled

build/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
EXTRA_DIST += build/maintainer-flags.txt
2+
3+
include build/cmake/Makefile.am

build/autotools/MaintainerFlags.m4

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
1-
old_CFLAGS="$CFLAGS"
2-
CFLAGS="-Werror"
31
AS_IF(
42
[test "x$enable_maintainer_flags" = "xyes" && test "x$GCC" = "xyes"],
53
[
6-
AX_CHECK_COMPILE_FLAG([-Wall], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Wall"])
7-
AX_CHECK_COMPILE_FLAG([-Waggregate-return], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Waggregate-return"])
8-
AX_CHECK_COMPILE_FLAG([-Wdeclaration-after-statement], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Wdeclaration-after-statement"])
9-
AX_CHECK_COMPILE_FLAG([-Wempty-body], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Wempty-body"])
10-
AX_CHECK_COMPILE_FLAG([-Wformat], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Wformat"])
11-
AX_CHECK_COMPILE_FLAG([-Wformat-nonliteral], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Wformat-nonliteral"])
12-
AX_CHECK_COMPILE_FLAG([-Wformat-security], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Wformat-security"])
13-
AX_CHECK_COMPILE_FLAG([-Winit-self], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Winit-self"])
14-
AX_CHECK_COMPILE_FLAG([-Winline], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Winline"])
15-
AX_CHECK_COMPILE_FLAG([-Wmissing-include-dirs], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Wmissing-include-dirs"])
16-
AX_CHECK_COMPILE_FLAG([-Wno-strict-aliasing], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Wno-strict-aliasing"])
17-
AX_CHECK_COMPILE_FLAG([-Wno-uninitialized], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Wno-uninitialized"])
18-
AX_CHECK_COMPILE_FLAG([-Wredundant-decls], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Wredundant-decls"])
19-
AX_CHECK_COMPILE_FLAG([-Wreturn-type], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Wreturn-type"])
20-
AX_CHECK_COMPILE_FLAG([-Wshadow], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Wshadow"])
21-
AX_CHECK_COMPILE_FLAG([-Wswitch-default], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Wswitch-default"])
22-
AX_CHECK_COMPILE_FLAG([-Wswitch-enum], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Wswitch-enum"])
23-
AX_CHECK_COMPILE_FLAG([-Wundef], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Wundef"])
24-
AX_CHECK_COMPILE_FLAG([-Wuninitialized], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Wuninitialized"])
25-
AX_CHECK_COMPILE_FLAG([-Wexpansion-to-defined], [MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS -Wexpansion-to-defined"])
4+
# clang only warns if it doesn't support a warning option, turn it into an
5+
# error so we really know if whether it supports it.
6+
AX_CHECK_COMPILE_FLAG(
7+
"-Werror=unknown-warning-option",
8+
[WERROR_UNKNOWN_OPTION="-Werror=unknown-warning-option"],
9+
[WERROR_UNKNOWN_OPTION=""])
10+
11+
# Read maintainer-flags.txt and apply each flag that the compiler supports.
12+
m4_foreach([MAINTAINER_FLAG], m4_split(m4_normalize(m4_esyscmd(cat build/maintainer-flags.txt))), [
13+
AX_CHECK_COMPILE_FLAG(
14+
MAINTAINER_FLAG,
15+
[MAINTAINER_CFLAGS="$MAINTAINER_CFLAGS MAINTAINER_FLAG"],
16+
[],
17+
[$WERROR_UNKNOWN_OPTION])
18+
])
2619
]
20+
21+
AC_SUBST(MAINTAINER_CFLAGS)
2722
)
28-
AC_SUBST(MAINTAINER_CFLAGS)
29-
CFLAGS="$old_CFLAGS"

build/cmake/MaintainerFlags.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
if (ENABLE_MAINTAINER_FLAGS)
2+
include(CheckCCompilerFlag)
3+
4+
message(STATUS "Detecting available maintainer flags")
5+
file (READ "build/maintainer-flags.txt" MAINTAINER_FLAGS)
6+
7+
# Convert file contents into a CMake list (where each element in the list
8+
# is one line of the file)
9+
#
10+
string (REGEX REPLACE ";" "\\\\;" MAINTAINER_FLAGS "${MAINTAINER_FLAGS}")
11+
string (REGEX REPLACE "\n" ";" MAINTAINER_FLAGS "${MAINTAINER_FLAGS}")
12+
13+
foreach (MAINTAINER_FLAG ${MAINTAINER_FLAGS})
14+
# Avoid useless "Performing Test FLAG_OK" message.
15+
set (MESSAGES_ENABLED 0)
16+
check_c_compiler_flag ("${MAINTAINER_FLAG}" FLAG_OK)
17+
set (MESSAGES_ENABLED 1)
18+
if (FLAG_OK)
19+
message (STATUS "C compiler accepts ${MAINTAINER_FLAG}")
20+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MAINTAINER_FLAG}")
21+
else ()
22+
message (STATUS "C compiler does not accept ${MAINTAINER_FLAG}")
23+
endif ()
24+
unset (FLAG_OK CACHE)
25+
endforeach ()
26+
27+
message(STATUS "Maintainer flags: ${CMAKE_C_FLAGS}")
28+
endif ()

build/cmake/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ EXTRA_DIST += \
66
build/cmake/libmongoc-1.0-config-version.cmake.in \
77
build/cmake/libmongoc-static-1.0-config.cmake.in \
88
build/cmake/libmongoc-static-1.0-config-version.cmake.in \
9-
build/cmake/LoadVersion.cmake
9+
build/cmake/LoadVersion.cmake \
10+
build/cmake/MaintainerFlags.cmake

build/maintainer-flags.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-Wall
2+
-Waggregate-return
3+
-Wdeclaration-after-statement
4+
-Wempty-body
5+
-Wformat
6+
-Wformat-nonliteral
7+
-Wformat-security
8+
-Winit-self
9+
-Winline
10+
-Wmissing-include-dirs
11+
-Wno-strict-aliasing
12+
-Wno-uninitialized
13+
-Wredundant-decls
14+
-Wreturn-type
15+
-Wshadow
16+
-Wswitch-default
17+
-Wswitch-enum
18+
-Wundef
19+
-Wuninitialized
20+
-Wexpansion-to-defined

0 commit comments

Comments
 (0)