[PATCH] D38511: [cmake] Add LLVM_DEBUG variable which can be used to replace NDEBUG

Don Hinton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 3 12:40:23 PDT 2017


hintonda created this revision.
Herald added a subscriber: mgorny.

Remove the dependancy on `NDEBUG`, especially in public headers, by using
a new variable, `LLVM_DEBUG`, which will make it easier to include llvm 
headers in other applications which may define NDEBUG differently.

This change only defines the new variable, but if accepted, the following 
changes can be made to headers as needed:

s/#ifndef NDEBUG/#ifdef LLVM_DEBUG/
s/!defined(NDEBUG)/defined(LLVM_DEBUG)/

This is similar to changes originally proposed by @tstellar:
https://reviews.llvm.org/D11833 and https://reviews.llvm.org/D11834

- This patch includes changes to CMakeLists.txt from https://reviews.llvm.org/D38406

which is still under review.


https://reviews.llvm.org/D38511

Files:
  CMakeLists.txt
  include/llvm/Config/llvm-config.h.cmake


Index: include/llvm/Config/llvm-config.h.cmake
===================================================================
--- include/llvm/Config/llvm-config.h.cmake
+++ include/llvm/Config/llvm-config.h.cmake
@@ -14,6 +14,9 @@
 #ifndef LLVM_CONFIG_H
 #define LLVM_CONFIG_H
 
+/* Define if CMAKE_BUILD_TYPE is Debug */
+#cmakedefine LLVM_DEBUG
+
 /* Define if we link Polly to the tools */
 #cmakedefine LINK_POLLY_INTO_TOOLS
 
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -388,16 +388,18 @@
 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
 
-option(LLVM_ENABLE_DUMP "Enable dump functions in release builds" OFF)
-
 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
   option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
+  option(LLVM_FORCE_ENABLE_DUMP "Enable dump functions in release builds" OFF)
 else()
   option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
+  option(LLVM_FORCE_ENABLE_DUMP "Enable dump functions in release builds" ON)
+  set(LLVM_DEBUG ON)
 endif()
 
-if( LLVM_ENABLE_ASSERTIONS )
+if( LLVM_ENABLE_ASSERTIONS OR LLVM_FORCE_ENABLE_DUMP )
   set(LLVM_ENABLE_DUMP ON)
+  set(LLVM_DEBUG ON)
 endif()
 
 option(LLVM_ENABLE_EXPENSIVE_CHECKS "Enable expensive checks" OFF)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38511.117563.patch
Type: text/x-patch
Size: 1373 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171003/33ffa124/attachment.bin>


More information about the llvm-commits mailing list