[llvm] 9b84dab - build: only pass -UNDEBUG when compiling C/C++

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 2 13:20:22 PST 2020


Author: Saleem Abdulrasool
Date: 2020-02-02T13:19:23-08:00
New Revision: 9b84dabc5f36f7e027c62b5c00ea97e21cfcacdd

URL: https://github.com/llvm/llvm-project/commit/9b84dabc5f36f7e027c62b5c00ea97e21cfcacdd
DIFF: https://github.com/llvm/llvm-project/commit/9b84dabc5f36f7e027c62b5c00ea97e21cfcacdd.diff

LOG: 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!

Added: 
    

Modified: 
    llvm/cmake/modules/HandleLLVMOptions.cmake

Removed: 
    


################################################################################
diff  --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index d519a7e8e9f0..0942bb98a26f 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -57,7 +57,10 @@ if( LLVM_ENABLE_ASSERTIONS )
   # On non-Debug builds cmake automatically defines NDEBUG, so we
   # explicitly undefine it:
   if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
-    add_definitions( -UNDEBUG )
+    # NOTE: use `add_compile_options` rather than `add_definitions` since
+    # `add_definitions` does not support generator expressions.
+    add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-UNDEBUG>)
+
     # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines.
     foreach (flags_var_to_scrub
         CMAKE_CXX_FLAGS_RELEASE


        


More information about the llvm-commits mailing list