From 8c4fa9ba51e93c8e0b9da6671c5c6cedd58b9cc4 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Wed, 7 Nov 2018 15:23:00 +0100 Subject: [PATCH] CMake: Add ASan option --- CMakeLists.txt | 8 ++++++++ src/CMakeLists.txt | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0656b824e..bcdb67684 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ option(SLIC3R_PROFILE "Compile Slic3r with an invasive Shiny profiler" 0) option(SLIC3R_MSVC_COMPILE_PARALLEL "Compile on Visual Studio in parallel" 1) option(SLIC3R_MSVC_PDB "Generate PDB files on MSVC in Release mode" 1) option(SLIC3R_PERL_XS "Compile XS Perl module and enable Perl unit and integration tests" 0) +option(SLIC3R_ASAN "Enable ASan on Clang and GCC" 0) if (MSVC) if (SLIC3R_MSVC_COMPILE_PARALLEL) @@ -89,6 +90,13 @@ endif() if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # On GCC and Clang, no return from a non-void function is a warning only. Here, we make it an error. add_compile_options(-Werror=return-type) + + if (SLIC3R_ASAN) + add_compile_options(-fsanitize=address -fno-omit-frame-pointer) + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan") + endif () + endif () endif() # Where all the bundled libraries reside? diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a101fd522..32d2c5b03 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -78,7 +78,7 @@ if (APPLE) target_link_libraries(slic3r "-liconv -framework IOKit" "-framework CoreFoundation" -lc++) elseif (MSVC) # Manifest is provided through slic3r.rc, don't generate your own. - set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO") else () target_link_libraries(slic3r -ldl -lstdc++) endif ()