Skip to content

Commit 9b84dab

Browse files
committed
build: only pass -UNDEBUG when compiling C/C++
This patch limits adding -UNDEBUG to C and C++ files so that projects can include files compiled with compilers that don't recognize this argument (Swift e.g.). add_definitions does not expand generators, hence the change from add_definitions to add_compile_options. Patch by Evan Wilde!
1 parent 34cd354 commit 9b84dab

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ if( LLVM_ENABLE_ASSERTIONS )
5757
# On non-Debug builds cmake automatically defines NDEBUG, so we
5858
# explicitly undefine it:
5959
if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
60-
add_definitions( -UNDEBUG )
60+
# NOTE: use `add_compile_options` rather than `add_definitions` since
61+
# `add_definitions` does not support generator expressions.
62+
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-UNDEBUG>)
63+
6164
# Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines.
6265
foreach (flags_var_to_scrub
6366
CMAKE_CXX_FLAGS_RELEASE

0 commit comments

Comments
 (0)