Skip to content

Commit 21cefc1

Browse files
authoredFeb 21, 2025
ci: always set values for command line defines (#5126)
1 parent 60adeb4 commit 21cefc1

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed
 

‎CMakeLists.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ endif ()
165165
if(BUILD_TESTING AND BUILD_SHARED_LIBS OR S2N_FUZZ_TEST)
166166
target_compile_options(${PROJECT_NAME} PRIVATE -fvisibility=default)
167167
else()
168-
target_compile_options(${PROJECT_NAME} PRIVATE -fvisibility=hidden -DS2N_EXPORTS)
168+
target_compile_options(${PROJECT_NAME} PRIVATE -fvisibility=hidden -DS2N_EXPORTS=1)
169169
endif()
170170

171171
if(S2N_LTO)
@@ -197,7 +197,7 @@ target_compile_options(${PROJECT_NAME} PRIVATE -include "${S2N_PRELUDE}")
197197
# Match on Release, RelWithDebInfo and MinSizeRel
198198
# See: https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html#variable:CMAKE_BUILD_TYPE
199199
if(CMAKE_BUILD_TYPE MATCHES Rel)
200-
add_definitions(-DS2N_BUILD_RELEASE)
200+
add_definitions(-DS2N_BUILD_RELEASE=1)
201201
endif()
202202

203203
if(NO_STACK_PROTECTOR)
@@ -251,7 +251,7 @@ endif()
251251

252252
if (NOT S2N_OVERRIDE_LIBCRYPTO_RAND_ENGINE)
253253
message(STATUS "Disabling libcrypto RAND engine override")
254-
add_definitions(-DS2N_DISABLE_RAND_ENGINE_OVERRIDE)
254+
add_definitions(-DS2N_DISABLE_RAND_ENGINE_OVERRIDE=1)
255255
endif()
256256

257257
# For interning, we need to find the static libcrypto library. Cmake configs
@@ -316,7 +316,7 @@ function(feature_probe_result PROBE_NAME IS_AVAILABLE)
316316

317317
# define the probe if available
318318
if(NORMALIZED)
319-
add_definitions(-D${PROBE_NAME})
319+
add_definitions(-D${PROBE_NAME}=1)
320320
endif()
321321
endfunction()
322322

@@ -426,7 +426,7 @@ if (S2N_INTERN_LIBCRYPTO)
426426
DEPENDS libcrypto.symbols
427427
)
428428
add_dependencies(${PROJECT_NAME} s2n_libcrypto)
429-
add_definitions(-DS2N_INTERN_LIBCRYPTO)
429+
add_definitions(-DS2N_INTERN_LIBCRYPTO=1)
430430

431431
if ((BUILD_SHARED_LIBS AND BUILD_TESTING) OR NOT BUILD_SHARED_LIBS)
432432
# if libcrypto needs to be interned, rewrite libcrypto references so use of internal functions will link correctly

‎codebuild/bin/grep_simple_mistakes.sh

+14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@
1414

1515
FAILED=0
1616

17+
#############################################
18+
# Grep for command line defines without values
19+
#############################################
20+
EMPTY_DEFINES=$(grep -Eon "\-D[^=]+=?" CMakeLists.txt | grep -v =)
21+
if [ ! -z "${EMPTY_DEFINES}" ]; then
22+
FAILED=1
23+
printf "\e[1;34mCommand line define is missing value:\e[0m "
24+
printf "Compilers SHOULD set a default value of 1 when no default is given, "
25+
printf "but that behavior is not required by any official spec. Set a value just in case. "
26+
printf "For example: -DS2N_FOO=1 instead of -DS2N_FOO.\n"
27+
printf "Found: \n"
28+
echo "$EMPTY_DEFINES"
29+
fi
30+
1731
#############################################
1832
# Grep for bindings methods without C documentation links.
1933
#############################################

‎s2n.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ bindir ?= $(exec_prefix)/bin
134134
libdir ?= $(exec_prefix)/lib64
135135
includedir ?= $(exec_prefix)/include
136136

137-
feature_probe = $(shell $(CC) $(CFLAGS) $(shell cat $(S2N_ROOT)/tests/features/GLOBAL.flags) $(shell cat $(S2N_ROOT)/tests/features/$(1).flags) -c -o tmp.o $(S2N_ROOT)/tests/features/$(1).c > /dev/null 2>&1 && echo "-D$(1)"; rm tmp.o > /dev/null 2>&1)
137+
feature_probe = $(shell $(CC) $(CFLAGS) $(shell cat $(S2N_ROOT)/tests/features/GLOBAL.flags) $(shell cat $(S2N_ROOT)/tests/features/$(1).flags) -c -o tmp.o $(S2N_ROOT)/tests/features/$(1).c > /dev/null 2>&1 && echo "-D$(1)=1"; rm tmp.o > /dev/null 2>&1)
138138

139139
FEATURES := $(notdir $(patsubst %.c,%,$(wildcard $(S2N_ROOT)/tests/features/*.c)))
140140
SUPPORTED_FEATURES := $(foreach feature,$(FEATURES),$(call feature_probe,$(feature)))

0 commit comments

Comments
 (0)
Failed to load comments.