about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorMartinNowack <martin.nowack@gmail.com>2017-07-25 15:51:46 +0200
committerGitHub <noreply@github.com>2017-07-25 15:51:46 +0200
commit3b4b79215b124cc7072e81bc79efdb76927e7100 (patch)
tree57b5659661145d6987774d0a7ef4e66993aacc60
parent810f7ebd99a06c46d632b1289ef2a7a3335d48f4 (diff)
parentdf899b02e279ed65dc94f55d4b671560f667497b (diff)
downloadklee-3b4b79215b124cc7072e81bc79efdb76927e7100.tar.gz
Merge pull request #726 from delcypher/cmake_fix_llvm_built_with_no_asserts
[CMake] Handle building against LLVM built without assertions
-rw-r--r--CMakeLists.txt15
-rw-r--r--cmake/find_llvm.cmake13
2 files changed, 28 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b9d7e61a..e066b89e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -224,6 +224,21 @@ else()
   unset(ENABLE_KLEE_DEBUG) # for config.h
 endif()
 
+# Warn about mixing build types.
+# This is likely a bad idea because some of LLVM's header files use the NDEBUG
+# macro which can change things like data layout.
+if (LLVM_ENABLE_ASSERTIONS AND (NOT ENABLE_KLEE_ASSERTS))
+  message(WARNING
+    "LLVM was built with assertions but KLEE will be built without them.\n"
+    "This might lead to unexpected behaviour."
+  )
+elseif ((NOT LLVM_ENABLE_ASSERTIONS) AND ENABLE_KLEE_ASSERTS)
+  message(WARNING
+    "LLVM was built without assertions but KLEE will be built with them.\n"
+    "This might lead to unexpected behaviour."
+  )
+endif()
+
 if (LLVM_ENABLE_VISIBILITY_INLINES_HIDDEN)
   list(APPEND KLEE_COMPONENT_CXX_FLAGS "-fvisibility-inlines-hidden")
 endif()
diff --git a/cmake/find_llvm.cmake b/cmake/find_llvm.cmake
index 770fca84..49ca51d4 100644
--- a/cmake/find_llvm.cmake
+++ b/cmake/find_llvm.cmake
@@ -227,3 +227,16 @@ else()
     set(${OUTPUT_VAR} ${targets_to_return} PARENT_SCOPE)
   endfunction()
 endif()
+
+# Filter out `-DNEBUG` from LLVM_DEFINITIONS.  The caller can use
+# `LLVM_ENABLE_ASSERTIONS` to decide how to set their defines.
+set(_new_llvm_definitions "")
+foreach (llvm_define ${LLVM_DEFINITIONS})
+  if ("${llvm_define}" STREQUAL "-DNDEBUG")
+    # Skip
+  else()
+    list(APPEND _new_llvm_definitions "${llvm_define}")
+  endif()
+endforeach()
+set(LLVM_DEFINITIONS "${_new_llvm_definitions}")
+unset(_new_llvm_definitions)