aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Bühler <stbuehler@web.de>2019-08-25 13:16:45 +0200
committerStefan Bühler <stbuehler@web.de>2019-08-25 13:16:45 +0200
commitafc537d3454bc1fcb046ba118a1ca384e083e1c9 (patch)
treeba9a9835ab4d966671b1f32a041af2b9591aafb8
parentbdd50b7910ebfd04f70e39cb688e3a4851505ac4 (diff)
downloadmultiwatch-afc537d3454bc1fcb046ba118a1ca384e083e1c9.tar.gz
multiwatch-afc537d3454bc1fcb046ba118a1ca384e083e1c9.zip
[build] improve (warning) compile flagsHEADmaster
-rw-r--r--CMakeLists.txt26
-rw-r--r--configure.ac14
2 files changed, 32 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9e29fbc..4e3b070 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,6 +27,21 @@ IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+OPTION(BUILD_EXTRA_WARNINGS "extra warnings")
+
+# default to ON
+set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "Default value for ``POSITION_INDEPENDENT_CODE`` of targets.")
+
+IF(BUILD_EXTRA_WARNINGS)
+ SET(WARN_CFLAGS "-g -O2 -g2 -Wall -Wmissing-declarations -Wdeclaration-after-statement -Wcast-align -Wsign-compare -Wnested-externs -Wpointer-arith -Wmissing-prototypes -Wshadow -Wno-pointer-sign -Wformat-security")
+ SET(WARN_LDFLAGS "-g -O2 -g2 -Wall -Wl,--as-needed -Wl,--no-undefined")
+ # -Wl,--as-needed
+ # -Werror -Wbad-function-cast -Wmissing-prototypes
+ELSE(BUILD_EXTRA_WARNINGS)
+ SET(WARN_CFLAGS "")
+ SET(WARN_LDFLAGS "")
+ENDIF(BUILD_EXTRA_WARNINGS)
+
# libev
CHECK_INCLUDE_FILES(ev.h HAVE_EV_H)
@@ -61,7 +76,16 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
add_executable(multiwatch ${MAIN_SOURCE})
-ADD_TARGET_PROPERTIES(multiwatch COMPILE_FLAGS "-std=gnu99 -Wall -g -Wshadow -W -pedantic -fPIC -D_GNU_SOURCE")
+IF(CMAKE_COMPILER_IS_GNUCC)
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -g -Wshadow -W -pedantic")
+ SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
+ SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
+ SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} -O2")
+ ADD_DEFINITIONS(-D_GNU_SOURCE)
+ENDIF(CMAKE_COMPILER_IS_GNUCC)
+
+ADD_TARGET_PROPERTIES(multiwatch COMPILE_FLAGS "${WARN_CFLAGS}")
+TARGET_LINK_LIBRARIES(multiwatch ${WARN_LDFLAGS})
# libev
TARGET_LINK_LIBRARIES(multiwatch "${EV_LIBRARIES}")
diff --git a/configure.ac b/configure.ac
index 725931b..4b55e81 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,9 +23,9 @@ PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16.0, [
# lib ev
AC_CHECK_HEADERS([ev.h], [], [AC_MSG_ERROR("ev.h not found")])
AC_CHECK_LIB([ev], [ev_time], [
- LIBS="-lev ${LIBS}"
- AC_DEFINE([HAVE_LIBEV], [1], [ev_time in -lev])
- ], [AC_MSG_ERROR("libev not found")])
+ LIBS="-lev ${LIBS}"
+ AC_DEFINE([HAVE_LIBEV], [1], [ev_time in -lev])
+], [AC_MSG_ERROR("libev not found")])
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h unistd.h], [])
@@ -41,16 +41,16 @@ if test "${GCC}" = "yes"; then
CFLAGS="${CFLAGS} -Wall -W -Wshadow -pedantic -std=gnu99"
fi
-AC_ARG_ENABLE(extra-warnings,
- AC_HELP_STRING([--enable-extra-warnings],[enable extra warnings (gcc specific)]),
+AC_ARG_ENABLE([extra-warnings],
+ [AS_HELP_STRING([--enable-extra-warnings],[enable extra warnings (gcc specific)])],
[case "${enableval}" in
yes) extrawarnings=true ;;
no) extrawarnings=false ;;
- *) AC_MSG_ERROR(bad value ${enableval} for --enable-extra-warnings) ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --enable-extra-warnings]) ;;
esac],[extrawarnings=false])
if test x$extrawarnings = xtrue; then
- CFLAGS="${CFLAGS} -g -O2 -g2 -Wall -Wmissing-declarations -Wdeclaration-after-statement -Wno-pointer-sign -Wcast-align -Winline -Wsign-compare -Wnested-externs -Wpointer-arith -Wl,--as-needed -Wformat-security"
+ CFLAGS="${CFLAGS} -g -O2 -g2 -Wall -Wmissing-declarations -Wdeclaration-after-statement -Wcast-align -Wsign-compare -Wnested-externs -Wpointer-arith -Wmissing-prototypes -Wshadow -Wno-pointer-sign -Wformat-security -Wl,--as-needed -Wl,--no-undefined"
fi
AC_CONFIG_FILES([Makefile])