Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add -no-pie flag to thread sanitizer (see https://bugs.debian.org/cgi-bin/bugreport...
[simgrid.git] / tools / cmake / GCCFlags.cmake
index 0a17197..3ca7309 100644 (file)
@@ -19,12 +19,14 @@ if(enable_compile_warnings)
     set(warnCFLAGS "${warnCFLAGS} -Wclobbered -Wno-error=clobbered  -Wno-unused-local-typedefs -Wno-error=attributes")
   endif()
 
-  set(warnCXXFLAGS "${warnCFLAGS} -Wall -Wextra -Wunused -Wmissing-declarations -Wpointer-arith -Wchar-subscripts -Wcomment  -Wformat -Wwrite-strings -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing -Wno-format-nonliteral -Werror")
+  set(warnCXXFLAGS "${warnCFLAGS} -Wall -Wextra -Wunused -Wmissing-declarations -Wpointer-arith -Wchar-subscripts -Wcomment  -Wformat -Wwrite-strings -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing -Wno-format-nonliteral")
   if(CMAKE_COMPILER_IS_GNUCXX)
     set(warnCXXFLAGS "${warnCXXFLAGS} -Wclobbered -Wno-error=clobbered  -Wno-unused-local-typedefs -Wno-error=attributes")
   endif()
-  if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # don't care about class that become struct
-    set(warnCXXFLAGS "${warnCXXFLAGS} -Wno-mismatched-tags")
+  if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+    # don't care about class that become struct, avoid issue of empty C structs
+    # size (coming from libunwind.h)
+    set(warnCXXFLAGS "${warnCXXFLAGS} -Wno-mismatched-tags -Wno-extern-c-compat")
   endif()
 
   # the one specific to C but refused by C++
@@ -37,6 +39,7 @@ endif()
 # NDEBUG gives a lot of "initialized but unused variables" errors. Don't die anyway.
 if(enable_compile_warnings AND enable_debug)
   set(warnCFLAGS "${warnCFLAGS} -Werror")
+  set(warnCXXFLAGS "${warnCXXFLAGS} -Werror")
 endif()
 
 # Activate the warnings on #if FOOBAR when FOOBAR has no value
@@ -162,6 +165,25 @@ if(enable_coverage)
   endif()
 endif()
 
+if(enable_address_sanitizer)
+    set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
+    set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -fsanitize=address")
+    set(TESH_OPTION --enable-sanitizers)
+endif()
+
+if(enable_thread_sanitizer)
+    set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -fsanitize=thread -fno-omit-frame-pointer -no-pie")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -fno-omit-frame-pointer -no-pie")
+    set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -fsanitize=thread -no-pie")
+endif()
+
+if(enable_undefined_sanitizer)
+    set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -fsanitize=undefined -fno-omit-frame-pointer")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fno-omit-frame-pointer")
+    set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -fsanitize=undefined")
+endif()
+
 if(NOT $ENV{CFLAGS} STREQUAL "")
   message(STATUS "Add CFLAGS: \"$ENV{CFLAGS}\" to CMAKE_C_FLAGS")
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{CFLAGS}")
@@ -192,7 +214,7 @@ if(MINGW)
   set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -Wl,--add-stdcall-alias")
   
   # Specify the data model that we are using (yeah it may help Java)
-  if(ARCH_32_BITS) 
+  if(CMAKE_SIZEOF_VOID_P EQUAL 4) # 32 bits
     set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS}   -m32")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
   else()