Skip to content

Commit

Permalink
build: avoid redefining _FORTIFY_SOURCE
Browse files Browse the repository at this point in the history
Check if `-D_FORTIFY_SOURCE` was already passed via the CFLAGS environment
variable and only add the flag if not already present.

Fixes: ea046bd ("build: enable source fortification by default")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
  • Loading branch information
jow- committed Nov 1, 2023
1 parent 448c763 commit cfb24ea
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ include(CheckFunctionExists)
include(CheckSymbolExists)

project(ucode C)
add_definitions(-Os -Wall -Werror --std=gnu99 -ffunction-sections -fwrapv -D_GNU_SOURCE -D_FORTIFY_SOURCE=2)
add_definitions(-Os -Wall -Werror --std=gnu99 -ffunction-sections -fwrapv -D_GNU_SOURCE)

if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 6)
add_definitions(-Wextra -Werror=implicit-function-declaration)
add_definitions(-Wformat -Werror=format-security -Werror=format-nonliteral)
endif()

if(NOT CMAKE_C_FLAGS MATCHES -D_FORTIFY_SOURCE=)
add_definitions(-D_FORTIFY_SOURCE=2)
endif()

add_definitions(-Wmissing-declarations -Wno-error=unused-variable -Wno-unused-parameter)

include_directories(include)
Expand Down

0 comments on commit cfb24ea

Please sign in to comment.