Skip to content

Commit 23d20b1

Browse files
committed
Rename Default STL hardening to Performance
1 parent bb2c413 commit 23d20b1

File tree

1 file changed

+56
-49
lines changed

1 file changed

+56
-49
lines changed

CMakeLists.txt

Lines changed: 56 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -160,67 +160,74 @@ endif()
160160
# really only be used where maximum performance is critical and the extra
161161
# safety can be sacrificed.
162162
#
163-
# ALSOFT_STL_HARDENING=Default enables some STL hardening, checking for more
163+
# ALSOFT_STL_HARDENING=Performance enables some STL hardening, checking for more
164164
# significant issues that can also be done "fast", that's easier to optimize
165165
# away when unneeded and/or not become a bottleneck. This is generally
166-
# considered fine for production use, hence being the default here.
166+
# considered fine for production use, and is the default here.
167167
#
168168
# ALSOFT_STL_HARDENING=Debug enables even more STL hardening, which has a much
169169
# higher runtime cost for less benefit. It's not intended for production use.
170-
set(ALSOFT_STL_HARDENING "Default" CACHE STRING
171-
"Specifies the level of C++ STL hardening. None, Default, Debug")
170+
set(ALSOFT_STL_HARDENING "Performance" CACHE STRING
171+
"Specifies the level of C++ STL hardening. None, Performance, Debug")
172+
if(ALSOFT_STL_HARDENING STREQUAL "Default")
173+
message(NOTICE "STL hardening option \"${ALSOFT_STL_HARDENING}\" deprecated, please set \"Performance\"")
174+
set(ALSOFT_STL_HARDENING "Performance" CACHE STRING
175+
"Specifies the level of C++ STL hardening. None, Performance, Debug" FORCE)
176+
endif()
172177

173-
set(HARDENING_LEVEL "None")
174178
check_cxx_symbol_exists(__GLIBCXX__ "version" HAVE_LIBSTDCXX)
175179
check_cxx_symbol_exists(_LIBCPP_VERSION "version" HAVE_LIBCXX)
176180
check_cxx_symbol_exists(_MSVC_STL_UPDATE "version" HAVE_MSSTL)
177-
if(HAVE_LIBSTDCXX)
178-
if(ALSOFT_STL_HARDENING STREQUAL "Debug")
179-
add_compile_definitions("_GLIBCXX_DEBUG=1")
180-
set(HARDENING_LEVEL "Debug")
181-
elseif(ALSOFT_STL_HARDENING STREQUAL "None")
182-
# TODO: Not sure how to fully disable STL hardening with libstdc++,
183-
# aside from not defining anything and using the compiler's default.
184-
# _GLIBCXX_NO_ASSERTIONS can explicitly disable the hardening
185-
# assertions, but not all STL debugging functionality.
186-
add_compile_definitions("_GLIBCXX_NO_ASSERTIONS=1")
187-
set(HARDENING_LEVEL "None")
188-
else()
189-
if(NOT (ALSOFT_STL_HARDENING STREQUAL "Default"))
190-
message(NOTICE "Unsupported STL hardening option \"${ALSOFT_STL_HARDENING}\", using Default")
181+
set(HARDENING_LEVEL "Default")
182+
if(NOT (ALSOFT_STL_HARDENING STREQUAL ""))
183+
if(HAVE_LIBSTDCXX)
184+
if(ALSOFT_STL_HARDENING STREQUAL "Debug")
185+
add_compile_definitions("_GLIBCXX_DEBUG=1")
186+
set(HARDENING_LEVEL "Debug")
187+
elseif(ALSOFT_STL_HARDENING STREQUAL "None")
188+
# TODO: Not sure how to fully disable STL hardening with libstdc++,
189+
# aside from not defining anything and using the compiler's
190+
# default. _GLIBCXX_NO_ASSERTIONS can explicitly disable the
191+
# hardening assertions, but not all STL debugging functionality.
192+
add_compile_definitions("_GLIBCXX_NO_ASSERTIONS=1")
193+
set(HARDENING_LEVEL "None")
194+
else()
195+
if(NOT (ALSOFT_STL_HARDENING STREQUAL "Performance"))
196+
message(NOTICE "Unsupported STL hardening option \"${ALSOFT_STL_HARDENING}\", using Performance")
197+
endif()
198+
add_compile_definitions("_GLIBCXX_ASSERTIONS=1")
199+
set(HARDENING_LEVEL "Performance")
191200
endif()
192-
add_compile_definitions("_GLIBCXX_ASSERTIONS=1")
193-
set(HARDENING_LEVEL "Default")
194-
endif()
195-
elseif(HAVE_LIBCXX)
196-
if(ALSOFT_STL_HARDENING STREQUAL "Debug")
197-
add_compile_definitions("_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG")
198-
set(HARDENING_LEVEL "Debug")
199-
elseif(ALSOFT_STL_HARDENING STREQUAL "None")
200-
add_compile_definitions("_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE")
201-
set(HARDENING_LEVEL "None")
202-
else()
203-
if(NOT (ALSOFT_STL_HARDENING STREQUAL "Default"))
204-
message(NOTICE "Unsupported STL hardening option \"${ALSOFT_STL_HARDENING}\", using Default")
201+
elseif(HAVE_LIBCXX)
202+
if(ALSOFT_STL_HARDENING STREQUAL "Debug")
203+
add_compile_definitions("_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG")
204+
set(HARDENING_LEVEL "Debug")
205+
elseif(ALSOFT_STL_HARDENING STREQUAL "None")
206+
add_compile_definitions("_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE")
207+
set(HARDENING_LEVEL "None")
208+
else()
209+
if(NOT (ALSOFT_STL_HARDENING STREQUAL "Performance"))
210+
message(NOTICE "Unsupported STL hardening option \"${ALSOFT_STL_HARDENING}\", using Performance")
211+
endif()
212+
add_compile_definitions("_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST")
213+
set(HARDENING_LEVEL "Performance")
205214
endif()
206-
add_compile_definitions("_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST")
207-
set(HARDENING_LEVEL "Default")
208-
endif()
209-
elseif(HAVE_MSSTL)
210-
if(ALSOFT_STL_HARDENING STREQUAL "Debug")
211-
# TODO: Is there anything more reasonable for heavier debugging (non-
212-
# production use) checks, where performance is not so important?
213-
add_compile_definitions("_MSVC_STL_HARDENING=1")
214-
set(HARDENING_LEVEL "Default")
215-
elseif(ALSOFT_STL_HARDENING STREQUAL "None")
216-
add_compile_definitions("_MSVC_STL_HARDENING=0")
217-
set(HARDENING_LEVEL "None")
218-
else()
219-
if(NOT (ALSOFT_STL_HARDENING STREQUAL "Default"))
220-
message(NOTICE "Unsupported STL hardening option \"${ALSOFT_STL_HARDENING}\", using Default")
215+
elseif(HAVE_MSSTL)
216+
# MSVC doesn't seem to have anything more than an on/off switch for STL
217+
# hardening, so Debug and Performance are the same here.
218+
if(ALSOFT_STL_HARDENING STREQUAL "Debug")
219+
add_compile_definitions("_MSVC_STL_HARDENING=1")
220+
set(HARDENING_LEVEL "Enabled")
221+
elseif(ALSOFT_STL_HARDENING STREQUAL "None")
222+
add_compile_definitions("_MSVC_STL_HARDENING=0")
223+
set(HARDENING_LEVEL "None")
224+
else()
225+
if(NOT (ALSOFT_STL_HARDENING STREQUAL "Performance"))
226+
message(NOTICE "Unsupported STL hardening option \"${ALSOFT_STL_HARDENING}\", using Performance")
227+
endif()
228+
add_compile_definitions("_MSVC_STL_HARDENING=1")
229+
set(HARDENING_LEVEL "Enabled")
221230
endif()
222-
add_compile_definitions("_MSVC_STL_HARDENING=1")
223-
set(HARDENING_LEVEL "Default")
224231
endif()
225232
endif()
226233

0 commit comments

Comments
 (0)