Skip to content

Commit

Permalink
add address sanitizer flags in CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdcvlsc committed May 30, 2024
1 parent f7cc534 commit 7947b16
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/ctests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
run: ctest --test-dir tests --build-config Debug
15 changes: 11 additions & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.16)
project(extended_precision_integers VERSION 1.0.0)

file(GLOB SOURCES "*.cpp")

Expand All @@ -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 $<TARGET_FILE:${test_exec_name}>
)
endforeach(test_src_code ${SOURCES})
endforeach(test_src_code ${SOURCES})

0 comments on commit 7947b16

Please sign in to comment.