From 7947b1604007d1505e57a21f84740559c3217fb6 Mon Sep 17 00:00:00 2001 From: mrdcvlsc Date: Thu, 30 May 2024 12:14:48 +0800 Subject: [PATCH] add address sanitizer flags in CMake --- .github/workflows/ctests.yml | 19 +++++++++++-------- tests/CMakeLists.txt | 15 +++++++++++---- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ctests.yml b/.github/workflows/ctests.yml index 496799a..e90fa4a 100644 --- a/.github/workflows/ctests.yml +++ b/.github/workflows/ctests.yml @@ -15,13 +15,13 @@ jobs: fail-fast: false matrix: platform: - - { name: Windows VS2019, ls: dir, os: windows-2019} - - { name: Windows VS2022, ls: dir, os: windows-2022} - - { name: Windows Clang, ls: dir, os: windows-2022, flags: -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++} - - { name: Windows GCC, ls: dir, os: windows-2022, flags: -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++} - - { name: Linux Clang, ls: ls, os: ubuntu-latest, flags: -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ } - - { name: Linux, ls: ls, os: ubuntu-latest} - - { name: MacOS XCode, ls: ls, os: macos-latest} + - { name: Windows VS2019, ls: dir, os: windows-2019, flags: -DCMAKE_BUILD_TYPE=Debug } + - { name: Windows VS2022, ls: dir, os: windows-2022, flags: -DCMAKE_BUILD_TYPE=Debug } + - { name: Windows Clang, ls: dir, os: windows-2022, flags: -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ } + - { name: Windows GCC, ls: dir, os: windows-2022, flags: -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ } + - { name: Linux Clang, ls: ls, os: ubuntu-latest, flags: -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ } + - { name: Linux, ls: ls, os: ubuntu-latest, flags: -DCMAKE_BUILD_TYPE=Debug } + - { name: MacOS XCode, ls: ls, os: macos-latest, flags: -DCMAKE_BUILD_TYPE=Debug } config: - { cxx_version: 20 } - { cxx_version: 23 } @@ -35,5 +35,8 @@ jobs: - name: Build run: cmake --build tests --config Debug + - name: View Test Executables + run: cd tests && ${{matrix.platform.ls}} && cd .. + - name: Tests - run: ${{matrix.platform.ls}} tests && ctest --test-dir tests \ No newline at end of file + run: ctest --test-dir tests --build-config Debug \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5bd659d..6a2c974 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 3.16) +project(extended_precision_integers VERSION 1.0.0) file(GLOB SOURCES "*.cpp") @@ -7,16 +8,22 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) # add_compile_definitions(USER_DEFINITION) +if(WIN32) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fsanitize=address") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fsanitize=address") +else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") +endif() + enable_testing() foreach(test_src_code ${SOURCES}) get_filename_component(test_exec_name ${test_src_code} NAME_WE) add_executable(${test_exec_name} ${test_src_code}) - # target_compile_features(${test_exec_name} PRIVATE cxx_std_11) - target_compile_options(${test_exec_name} PRIVATE -fsanitize=address) - target_link_options(${test_exec_name} PRIVATE -fsanitize=address) add_test( NAME ${test_exec_name} COMMAND $ ) -endforeach(test_src_code ${SOURCES}) \ No newline at end of file +endforeach(test_src_code ${SOURCES}) +