]> source.dussan.org Git - tigervnc.git/commitdiff
Add address sanitizer switch
authorPierre Ossman <ossman@cendio.se>
Tue, 29 Sep 2015 07:40:20 +0000 (09:40 +0200)
committerPierre Ossman <ossman@cendio.se>
Tue, 29 Sep 2015 07:40:20 +0000 (09:40 +0200)
Useful for debugging memory leaks and access violations. It is
not available on Windows though, and there is some problem compiling
ObjectiveC++ with it turned on.

CMakeLists.txt
cmake/StaticBuild.cmake

index a46679b82fbdf58c1dc903d477a0878f3ba63044..08ef25ccd0350cb1ca5e9e7a11a9f67566eb3f2e 100644 (file)
@@ -76,6 +76,12 @@ IF(CMAKE_BUILD_TYPE MATCHES Debug)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
 ENDIF()
 
+option(ENABLE_ASAN "Enable address sanitizer support" OFF)
+if(ENABLE_ASAN AND NOT WIN32 AND NOT APPLE)
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
+endif()
+
 if(NOT DEFINED BUILD_WINVNC)
   set(BUILD_WINVNC 1)
 endif()
index cc03487b1b3c7b435fa4d64dbcdc7a4b0e986560..25c1077724685d77a7f96a9b794a64c804638c36 100644 (file)
@@ -109,6 +109,9 @@ if(BUILD_STATIC)
   # This ensures that we don't depend on libstdc++ or libgcc_s
   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nodefaultlibs")
   set(STATIC_BASE_LIBRARIES "-Wl,-Bstatic -lstdc++ -Wl,-Bdynamic")
+  if(ENABLE_ASAN AND NOT WIN32 AND NOT APPLE)
+    set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -Wl,-Bstatic -lasan -Wl,-Bdynamic -ldl -lm -lpthread")
+  endif()
   if(WIN32)
     set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -lmingw32 -lgcc_eh -lgcc -lmoldname -lmingwex -lmsvcrt")
     set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -luser32 -lkernel32 -ladvapi32 -lshell32")