[polly] r247470 - Introspect llvm-config --assertion-mode in cmake out-of-tree builds

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 13:47:14 PDT 2015


Author: meinersbur
Date: Fri Sep 11 15:47:14 2015
New Revision: 247470

URL: http://llvm.org/viewvc/llvm-project?rev=247470&view=rev
Log:
Introspect llvm-config --assertion-mode in cmake out-of-tree builds

When compiling Polly without LLVM sources but with system-installed
LLVM, the build process would not honor the LLVM_ENABLE_ASSERTIONS
setting LLVM was compiled with, but effectively assume that it is
switched off when compiling. During unit-tests llvm-lit would still
query the LLVM_ENABLE_ASSERTIONS flag and enable tests which require
assertions. Even if enabled for LLVM, Polly does not output its debug
info and statistics in this this mode such that 7 tests fail.

To fix, we query llvm-config --assertion-mode and if on, enable
assertions as HandleLLVMOptions.cmake would do.

We cannot reliably use HandleLLVMOptions.cmake itself as the host's
LLVM build might have been built using automake and distributions
change file locations (e.g. Debian to
/usr/share/llvm-${VERSION}/cmake/HandleLLVMOptions.cmake).


Modified:
    polly/trunk/CMakeLists.txt

Modified: polly/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/CMakeLists.txt?rev=247470&r1=247469&r2=247470&view=diff
==============================================================================
--- polly/trunk/CMakeLists.txt (original)
+++ polly/trunk/CMakeLists.txt Fri Sep 11 15:47:14 2015
@@ -55,6 +55,34 @@ if (NOT DEFINED LLVM_MAIN_SRC_DIR)
                   OUTPUT_STRIP_TRAILING_WHITESPACE)
   set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${LLVM_CXX_FLAGS})
 
+  # Check LLVM_ENABLE_ASSERTIONS
+  execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --assertion-mode
+                  OUTPUT_VARIABLE LLVM_ENABLE_ASSERTIONS
+                  OUTPUT_STRIP_TRAILING_WHITESPACE)
+  # Copied from LLVM's HandleLLVMOptions.cmake
+  if( LLVM_ENABLE_ASSERTIONS )
+    # MSVC doesn't like _DEBUG on release builds. See PR 4379.
+    if( NOT MSVC )
+      add_definitions( -D_DEBUG )
+    endif()
+    # On non-Debug builds cmake automatically defines NDEBUG, so we
+    # explicitly undefine it:
+    if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
+      add_definitions( -UNDEBUG )
+      # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines.
+      foreach (flags_var_to_scrub
+          CMAKE_CXX_FLAGS_RELEASE
+          CMAKE_CXX_FLAGS_RELWITHDEBINFO
+          CMAKE_CXX_FLAGS_MINSIZEREL
+          CMAKE_C_FLAGS_RELEASE
+          CMAKE_C_FLAGS_RELWITHDEBINFO
+          CMAKE_C_FLAGS_MINSIZEREL)
+        string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " "
+          "${flags_var_to_scrub}" "${${flags_var_to_scrub}}")
+      endforeach()
+    endif()
+  endif()
+
   # Make sure the isl c files are built as fPIC
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
 endif(NOT DEFINED LLVM_MAIN_SRC_DIR)




More information about the llvm-commits mailing list