diff options
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | CMakeScripts/DefineDependsandFlags.cmake | 19 |
2 files changed, 18 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index a359dc8ed..0905b5daf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,7 @@ option(WITH_LIBVISIO "Compile with support of libvisio for Microsoft Visio Diagr option(WITH_LIBWPG "Compile with support of libwpg for WordPerfect Graphics" ON) option(WITH_NLS "Compile with Native Language Support (using gettext)" ON) option(WITH_JEMALLOC "Compile with JEMALLOC support" OFF) +option(WITH_ASAN "Compile with Clang's AddressSanitizer (for debugging purposes)" OFF) option(WITH_FUZZ "Compile for fuzzing purpose (use 'make fuzz' only)" OFF) mark_as_advanced(WITH_FUZZ) diff --git a/CMakeScripts/DefineDependsandFlags.cmake b/CMakeScripts/DefineDependsandFlags.cmake index 3be793621..e38eaef4a 100644 --- a/CMakeScripts/DefineDependsandFlags.cmake +++ b/CMakeScripts/DefineDependsandFlags.cmake @@ -10,13 +10,28 @@ list(APPEND INKSCAPE_INCS ${PROJECT_SOURCE_DIR} ${CMAKE_BINARY_DIR}/include ) +# AddressSanitizer +# Clang's AddressSanitizer can detect more memory errors and is more powerful +# than compiling with _FORTIFY_SOURCE but has a performance impact (approx. 2x +# slower), so it's not suitable for release builds. +if(WITH_ASAN) + if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) + message(FATAL_ERROR "Compiler must be Clang for WITH_ASAN=ON") + endif() + list(APPEND INKSCAPE_CXX_FLAGS "-fsanitize=address -fno-omit-frame-pointer") + list(APPEND INKSCAPE_LIBS "-fsanitize=address") +else() + # Undefine first, to suppress 'warning: "_FORTIFY_SOURCE" redefined' + list(APPEND INKSCAPE_CXX_FLAGS "-U_FORTIFY_SOURCE") + list(APPEND INKSCAPE_CXX_FLAGS "-D_FORTIFY_SOURCE=2") +endif() + # Errors for common mistakes list(APPEND INKSCAPE_CXX_FLAGS "-Werror=format") # e.g.: printf("%s", std::string("foo")) list(APPEND INKSCAPE_CXX_FLAGS "-Werror=format-security") # e.g.: printf(variable); -list(APPEND INKSCAPE_CXX_FLAGS "-D_FORTIFY_SOURCE=2") +list(APPEND INKSCAPE_CXX_FLAGS_DEBUG "-Og") # for _FORTIFY_SOURCE list(APPEND INKSCAPE_CXX_FLAGS_DEBUG "-D_GLIBCXX_ASSERTIONS") if (CMAKE_COMPILER_IS_GNUCC) - list(APPEND INKSCAPE_CXX_FLAGS_DEBUG "-Og") # for _FORTIFY_SOURCE list(APPEND INKSCAPE_CXX_FLAGS_DEBUG "-fexceptions -fstack-protector-strong -grecord-gcc-switches -fasynchronous-unwind-tables") if(CXX_COMPILER_VERSION VERSION_GREATER 8.0) list(APPEND INKSCAPE_CXX_FLAGS_DEBUG "-fstack-clash-protection -fcf-protection") |
