aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Bühler <stbuehler@web.de>2019-08-25 13:58:30 +0200
committerStefan Bühler <stbuehler@web.de>2019-08-25 13:58:30 +0200
commite256c300ee0e93df73bf3c6dcccd0a2d5fb980bf (patch)
tree36a5191b91854122f84d735a5e2a85e2f20c58e7
parent0d41910e8101f3bea0e911300bf6430a4ab691b8 (diff)
downloadscgi-cgi-master.tar.gz
scgi-cgi-master.zip
[build] improve (warning) compile flagsHEADmaster
-rw-r--r--CMakeLists.txt23
-rw-r--r--cmake/AddTargetProperties.cmake2
-rw-r--r--configure.ac8
3 files changed, 27 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 00d98b0..379104e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,6 +18,26 @@ IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
OPTION(GCC_LIBEVENT_STATIC "link libevent static")
+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")
+ELSE(BUILD_EXTRA_WARNINGS)
+ SET(WARN_CFLAGS "")
+ SET(WARN_LDFLAGS "")
+ENDIF(BUILD_EXTRA_WARNINGS)
+
+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)
# libevent
pkg_check_modules (LIBEVENT REQUIRED libevent>=2.0)
@@ -38,7 +58,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
add_executable(scgi-cgi ${MAIN_SOURCE})
-ADD_TARGET_PROPERTIES(scgi-cgi COMPILE_FLAGS "-std=gnu99 -Wall -g -Wshadow -W -pedantic -fPIC")
+ADD_TARGET_PROPERTIES(scgi-cgi COMPILE_FLAGS "${WARN_FLAGS}")
+TARGET_LINK_LIBRARIES(scgi-cgi ${WARN_LDFLAGS})
# libev
TARGET_LINK_LIBRARIES(scgi-cgi ${MYLIBEVENT_LDFLAGS})
diff --git a/cmake/AddTargetProperties.cmake b/cmake/AddTargetProperties.cmake
index 17ee774..e1256d2 100644
--- a/cmake/AddTargetProperties.cmake
+++ b/cmake/AddTargetProperties.cmake
@@ -4,7 +4,7 @@ MACRO(ADD_TARGET_PROPERTIES _target _name)
SET(_properties "${_properties} ${_prop}")
ENDFOREACH(_prop)
GET_TARGET_PROPERTY(_old_properties ${_target} ${_name})
- MESSAGE(STATUS "adding property to ${_target} ${_name}:" ${_properties})
+ #MESSAGE(STATUS "adding property to ${_target} ${_name}:" ${_properties})
IF(NOT _old_properties)
# in case it's NOTFOUND
SET(_old_properties)
diff --git a/configure.ac b/configure.ac
index eb1d7c6..7984c8e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,16 +33,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])