Skip to content

Commit

Permalink
Converge warning-flags in Makefile and CMake builds
Browse files Browse the repository at this point in the history
Use Werror in CMake builds and enable -pedantic in Makefile.

Signed-off-by: Björn Svensson <[email protected]>
  • Loading branch information
bjosv committed Aug 13, 2024
1 parent 9188dbd commit 6fd71f3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 6fd71f3

Please sign in to comment.