Skip to content

Commit

Permalink
cmake: fix adding of compiler flags, and now it will
Browse files Browse the repository at this point in the history
- add_compiler_flags() must accept array IOW just ARGN will be enoough
- add_compiler_flags() called with variable name instead of it's value

P.S. and fix some alignments issues
P.P.S. more cmake issues expected since now CFLAGS actually works
P.P.P.S. some issues with cmake cache is possible, so just reset it
  • Loading branch information
azat committed Mar 9, 2016
1 parent f29f59e commit 36588e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
39 changes: 20 additions & 19 deletions CMakeLists.txt
Expand Up @@ -145,15 +145,15 @@ endif()
# Setup compiler flags for coverage.
if (EVENT__COVERAGE)
if ((NOT CMAKE_COMPILER_IS_GNUCC) AND (NOT ${CMAKE_CXX_COMPILER_ID} STREQAL "Clang"))
message(FATAL_ERROR"Trying to compile coverage support, but compiler is not GNU gcc! Try CC=/usr/bin/gcc CXX=/usr/bin/g++ cmake <options> ..")
message(FATAL_ERROR "Trying to compile coverage support, but compiler is not GNU gcc! Try CC=/usr/bin/gcc CXX=/usr/bin/g++ cmake <options> ..")
endif()

if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(FATAL_ERROR "Coverage requires -DCMAKE_BUILD_TYPE=Debug")
endif()

message(STATUS "Setting coverage compiler flags")
add_compiler_flags(-g -O0 -fprofile-arcs -ftest-coverage)
add_compiler_flags(-g -O0 -fprofile-arcs -ftest-coverage)
endif()

# GCC specific options.
Expand All @@ -163,44 +163,45 @@ if (CMAKE_COMPILER_IS_GNUCC)
option(EVENT__ENABLE_GCC_FUNCTION_SECTIONS "Enable gcc function sections" OFF)
option(EVENT__ENABLE_GCC_WARNINGS "Make all GCC warnings into errors" OFF)

list(APPEND __FLAGS -Wall -Wswitch)
list(APPEND __FLAGS -Wall -Wswitch)

if (EVENT__DISABLE_GCC_WARNINGS)
list(APPEND __FLAGS -w)
list(APPEND __FLAGS -w)
endif()

if (EVENT__ENABLE_GCC_HARDENING)
list(APPEND __FLAGS
-fstack-protector-all
-fwrapv
-fPIE
-Wstack-protector
"--param ssp-buffer-size=1")

add_definitions(-D_FORTIFY_SOURCE=2)
list(APPEND __FLAGS
-fstack-protector-all
-fwrapv
-fPIE
-Wstack-protector
"--param ssp-buffer-size=1")

add_definitions(-D_FORTIFY_SOURCE=2)
endif()

if (EVENT__ENABLE_GCC_FUNCTION_SECTIONS)
list(APPEND __FLAGS -ffunction-sections)
list(APPEND __FLAGS -ffunction-sections)
# TODO: Add --gc-sections support. We need some checks for NetBSD to ensure this works.
endif()

if (EVENT__ENABLE_GCC_WARNINGS)
list(APPEND __FLAGS -Werror)
list(APPEND __FLAGS -Werror)
endif()

# We need to test for at least gcc 2.95 here, because older versions don't
# have -fno-strict-aliasing
list(APPEND __FLAGS -fno-strict-aliasing)
list(APPEND __FLAGS -fno-strict-aliasing)

add_compiler_flags(__FLAGS)
add_compiler_flags(${__FLAGS})
endif()

if (APPLE)
# Get rid of deprecated warnings for OpenSSL on OSX 10.7 and greater.
add_compiler_flags(
-Wno-error=deprecated-declarations
-Qunused-arguments)
add_compiler_flags(
-Wno-error=deprecated-declarations
-Qunused-arguments
)
endif()

# Winsock.
Expand Down
6 changes: 2 additions & 4 deletions cmake/AddCompilerFlags.cmake
@@ -1,7 +1,7 @@
include(CheckCCompilerFlag)

macro(add_compiler_flags _flags)
foreach(flag ${_flags})
macro(add_compiler_flags)
foreach(flag ${ARGN})
string(REGEX REPLACE "[-.+/:= ]" "_" _flag_esc "${flag}")

check_c_compiler_flag("${flag}" check_c_compiler_flag_${_flag_esc})
Expand All @@ -11,5 +11,3 @@ macro(add_compiler_flags _flags)
endif()
endforeach()
endmacro()


0 comments on commit 36588e1

Please sign in to comment.