cmake: Add ASAN support.
authorMathias Preiner <mathias.preiner@gmail.com>
Fri, 17 Aug 2018 23:59:09 +0000 (16:59 -0700)
committerMathias Preiner <mathias.preiner@gmail.com>
Sat, 22 Sep 2018 23:30:59 +0000 (16:30 -0700)
CMakeLists.txt

index aa4f5fa796308beebea05e8f5012966713d04ba8..204e1016982f8ec2a824e591798b5d4f28cba32f 100644 (file)
@@ -132,6 +132,7 @@ option(ENABLE_GPL                "Enable GPL dependencies" OFF)
 # General build options
 # >> 3-valued: INGORE ON OFF, allows to detect if set by user
 #              this is only necessary for options set for build types!
+cvc4_option(ENABLE_ASAN          "Enable ASAN build")
 cvc4_option(ENABLE_ASSERTIONS    "Enable assertions")
 cvc4_option(ENABLE_DEBUG_SYMBOLS "Enable debug symbols")
 cvc4_option(ENABLE_DUMPING       "Enable dumpin")
@@ -191,12 +192,17 @@ include_directories(${GMP_INCLUDE_DIR})
 add_check_c_cxx_flag("-O${OPT_LEVEL}")
 add_check_c_flag("-fexceptions")
 add_check_c_cxx_flag("-Wno-deprecated")
-add_check_c_cxx_flag("-Wsuggest-override")
+add_check_cxx_flag("-Wsuggest-override")
 add_check_cxx_flag("-Wnon-virtual-dtor")
 
 #-----------------------------------------------------------------------------#
 # Build types
 
+if(ENABLE_ASAN)
+  set(CMAKE_BUILD_TYPE Debug)
+endif()
+
+# Set the default build type to Production
 if(NOT CMAKE_BUILD_TYPE)
   set(CMAKE_BUILD_TYPE Production CACHE STRING "Options are: ${BUILD_TYPES}" FORCE)
   # Provide drop down menu options in cmake-gui
@@ -220,6 +226,14 @@ endif()
 
 #-----------------------------------------------------------------------------#
 
+if(ENABLE_ASAN)
+  set(CMAKE_REQUIRED_LIBRARIES -fsanitize=address)
+  add_required_c_cxx_flag("-fsanitize=address")
+  unset(CMAKE_REQUIRED_LIBRARIES)
+  add_required_c_cxx_flag("-fno-omit-frame-pointer")
+  add_check_c_cxx_flag("-fsanitize-recover=address")
+endif()
+
 if(ENABLE_ASSERTIONS)
   add_definitions(-DCVC4_ASSERTIONS)
 endif()