summaryrefslogtreecommitdiffhomepage
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2023-11-02 00:31:59 +0100
committerJo-Philipp Wich <jo@mein.io>2023-11-02 00:31:59 +0100
commitcfb24ea4f12131dcefe4f1ede2f51d3d16b88dec (patch)
tree0ec82123631c4296f0708920845065e5599acedb /CMakeLists.txt
parent448c7632dbe12c0cd0385e25503288d54a86c1e7 (diff)
build: avoid redefining _FORTIFY_SOURCE
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>
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt7
1 files changed, 6 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e3cc37e..41fedb6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)