From 7ed4d11f0c6cf5ad2c65206183c6f0c65f7a6365 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 5 Aug 2019 21:22:33 -0700 Subject: [PATCH] cmake: Add options for debugging This adds std library assertions and address sanitizer options. They are not yet enabled by default for debug builds as they are not compatible with our inline assembler --- CMakeLists.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb41e0c155..16a7205a52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,14 @@ option( KICAD_SPICE "Build KiCad with internal Spice simulator." ON ) +option( KICAD_SANITIZE + "Build KiCad with sanitizer options. WARNING: Not compatible with gold linker" + OFF ) + +option( KICAD_STDLIB_DEBUG + "Build KiCad with libstdc++ debug flags enabled." + OFF ) + option( KICAD_BUILD_PARALLEL_CL_MP "Build in parallel using the /MP compiler option (default OFF for safety reasons)" OFF ) @@ -321,6 +329,14 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) set( CMAKE_C_FLAGS_DEBUG "-g3 -ggdb3 -DDEBUG" ) set( CMAKE_CXX_FLAGS_DEBUG "-g3 -ggdb3 -DDEBUG -Wno-deprecated-declarations" ) endif() + + if( KICAD_SANITIZE ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_SANITIZE_VECTOR -fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer" ) + endif() + + if( KICAD_STDLIB_DEBUG ) + set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG" ) + endif() if( MINGW ) set( CMAKE_EXE_LINKER_FLAGS_RELEASE "-s" )