From f9f6ea4b205a8128b1528faf48a8ea0ec72bc08c Mon Sep 17 00:00:00 2001 From: Alexander Wilson Date: Mon, 13 Apr 2020 01:40:03 +0100 Subject: [PATCH] Address Sanitizer --- CMakeLists.txt | 89 ++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f1ed1f7..c46ab43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.6.2) -set (CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_FLAGS "-Wall -Wno-unused-function -Werror") +set (CMAKE_CXX_STANDARD 17) +set (CMAKE_CXX_FLAGS "-Wall -Wno-unused-function -Werror") project(acc) @@ -120,49 +120,52 @@ install( ) IF(CMAKE_BUILD_TYPE MATCHES Debug) - # Don't Install Google Test if its already installed. - IF(NOT GTEST_INSTALLED MATCHES TRUE) + set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") + set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") +ENDIF(CMAKE_BUILD_TYPE MATCHES Debug) + +# Don't Install Google Test if its already installed. +IF(NOT GTEST_INSTALLED MATCHES TRUE) + + find_package(Threads REQUIRED) + + # Enable ExternalProject CMake module + include(ExternalProject) + + # Download and install GoogleTest + ExternalProject_Add( + gtest + URL https://github.com/google/googletest/archive/release-1.8.1.zip + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/gtest + # Disable install step + INSTALL_COMMAND "" + ) - find_package(Threads REQUIRED) - - # Enable ExternalProject CMake module - include(ExternalProject) - - # Download and install GoogleTest - ExternalProject_Add( - gtest - URL https://github.com/google/googletest/archive/release-1.8.1.zip - PREFIX ${CMAKE_CURRENT_BINARY_DIR}/gtest - # Disable install step - INSTALL_COMMAND "" - ) - - # Get GTest source and binary directories from CMake project - ExternalProject_Get_Property(gtest source_dir binary_dir) + # Get GTest source and binary directories from CMake project + ExternalProject_Get_Property(gtest source_dir binary_dir) - # Create a libgtest target to be used as a dependency by test programs - add_library(libgtest IMPORTED STATIC GLOBAL) - add_dependencies(libgtest gtest) - - # Set libgtest properties - set_target_properties(libgtest PROPERTIES - "IMPORTED_LOCATION" "${binary_dir}/googlemock/gtest/libgtest.a" - "IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}" - ) - - # Create a libgmock target to be used as a dependency by test programs - add_library(libgmock IMPORTED STATIC GLOBAL) - add_dependencies(libgmock gtest) - - # Set libgmock properties - set_target_properties(libgmock PROPERTIES - "IMPORTED_LOCATION" "${binary_dir}/googlemock/libgmock.a" - "IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}" - ) - ENDIF(NOT GTEST_INSTALLED MATCHES TRUE) - enable_testing() - add_subdirectory(test) -ENDIF(CMAKE_BUILD_TYPE MATCHES Debug) + # Create a libgtest target to be used as a dependency by test programs + add_library(libgtest IMPORTED STATIC GLOBAL) + add_dependencies(libgtest gtest) + + # Set libgtest properties + set_target_properties(libgtest PROPERTIES + "IMPORTED_LOCATION" "${binary_dir}/googlemock/gtest/libgtest.a" + "IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}" + ) + + # Create a libgmock target to be used as a dependency by test programs + add_library(libgmock IMPORTED STATIC GLOBAL) + add_dependencies(libgmock gtest) + + # Set libgmock properties + set_target_properties(libgmock PROPERTIES + "IMPORTED_LOCATION" "${binary_dir}/googlemock/libgmock.a" + "IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}" + ) +ENDIF(NOT GTEST_INSTALLED MATCHES TRUE) +enable_testing() +add_subdirectory(test) add_executable(acc main.cpp) add_dependencies(acc atl)