From 6fd71f3719b63185c0370e52aea5cc00dbbffc46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= Date: Fri, 2 Aug 2024 17:56:58 +0200 Subject: [PATCH] Converge warning-flags in Makefile and CMake builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use Werror in CMake builds and enable -pedantic in Makefile. Signed-off-by: Björn Svensson --- .github/workflows/build.yml | 6 ------ CMakeLists.txt | 12 ++++++++---- Makefile | 2 +- tests/CMakeLists.txt | 4 +--- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bea47918..da857c5b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,8 +22,6 @@ jobs: - name: Build using cmake env: EXTRA_CMAKE_OPTS: -DENABLE_EXAMPLES:BOOL=ON -DENABLE_SSL:BOOL=ON - CFLAGS: -Werror - CXXFLAGS: -Werror run: mkdir build && cd build && cmake .. && make - name: Build using makefile @@ -57,8 +55,6 @@ jobs: - name: Build using cmake env: EXTRA_CMAKE_OPTS: -DENABLE_EXAMPLES:BOOL=ON -DENABLE_SSL:BOOL=ON - CFLAGS: -Werror - CXXFLAGS: -Werror run: mkdir build && cd build && cmake3 .. && make - name: Build using Makefile @@ -102,8 +98,6 @@ jobs: - name: Build using cmake env: EXTRA_CMAKE_OPTS: -DENABLE_EXAMPLES:BOOL=ON -DENABLE_SSL:BOOL=ON - CFLAGS: -Werror - CXXFLAGS: -Werror run: mkdir build && cd build && cmake .. && make - name: Build using Makefile diff --git a/CMakeLists.txt b/CMakeLists.txt index f9af3054..431c2d9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,14 @@ OPTION(ENABLE_RDMA "Build valkey_rdma for RDMA support" OFF) SET(CMAKE_C_STANDARD 99) SET(CMAKE_DEBUG_POSTFIX d) +# Set target-common flags +if(NOT WIN32) + add_compile_options(-Werror -Wall -Wextra -pedantic) + add_compile_options(-Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers) +else() + add_definitions(-D_CRT_SECURE_NO_WARNINGS -DWIN32_LEAN_AND_MEAN) +endif() + SET(valkey_sources src/adlist.c src/alloc.c @@ -45,10 +53,6 @@ SET(valkey_sources src/valkeycluster.c src/vkutil.c) -IF(WIN32) - ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -DWIN32_LEAN_AND_MEAN) -ENDIF() - ADD_LIBRARY(valkey ${valkey_sources}) ADD_LIBRARY(valkey::valkey ALIAS valkey) set(valkey_export_name valkey CACHE STRING "Name of the exported target") diff --git a/Makefile b/Makefile index a1593e33..350fe42a 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ export VALKEY_TEST_CONFIG CC := $(if $(shell command -v $(firstword $(CC)) >/dev/null 2>&1 && echo OK),$(CC),gcc) OPTIMIZATION?=-O3 -WARNINGS=-Wall -Wextra -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers +WARNINGS=-Wall -Wextra -pedantic -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers USE_WERROR?=1 ifeq ($(USE_WERROR),1) WARNINGS+=-Werror diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 64768035..81d4ed83 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -53,12 +53,10 @@ find_path(LIBEVENT_INCLUDES event2/event.h) if(LIBEVENT_INCLUDES) include_directories(${LIBEVENT_INCLUDES}) endif() - if(MSVC OR MINGW) find_library(LIBEVENT_LIBRARY Libevent) else() - add_compile_options(-Wall -Wextra -pedantic -Werror) - # Debug mode for tests + # Use the Debug configuration when building tests (no -DNDEBUG) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "" FORCE) endif()