Skip to content

Commit f2ab664

Browse files
committed
adding sanitizer
1 parent 5b20cde commit f2ab664

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

.github/workflows/macos-ci.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ jobs:
77
runs-on: macos-latest
88
steps:
99
- uses: actions/checkout@v2
10-
- name: Use cmake
10+
- name: Use cmake (default)
1111
run: |
12-
mkdir build
13-
cd build
14-
cmake ..
15-
cmake --build .
16-
ctest . --output-on-failure
12+
cmake -B build -D CMAKE_BUILD_TYPE=Release
13+
cmake --build build
14+
ctest --test-dir build --output-on-failure
15+
- name: Use cmake (debug)
16+
run: |
17+
cmake -B build -D CMAKE_BUILD_TYPE=Debug
18+
cmake --build build
19+
ctest --test-dir build --output-on-failure

.github/workflows/ubuntu-ci.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@ jobs:
1515

1616
steps:
1717
- uses: actions/checkout@v2
18-
- name: Build and Test
18+
- name: Use cmake (default)
1919
run: |
20-
mkdir build
21-
cd build
22-
cmake ..
23-
cmake --build .
24-
ctest . --output-on-failure
20+
cmake -B build -D CMAKE_BUILD_TYPE=Release
21+
cmake --build build
22+
ctest --test-dir build --output-on-failure
23+
- name: Use cmake (debug)
24+
run: |
25+
cmake -B build -D CMAKE_BUILD_TYPE=Debug
26+
cmake --build build
27+
ctest --test-dir build --output-on-failure
28+
- name: Use cmake (sanitizers)
29+
run: |
30+
cmake -B build -D FASTPFOR_SANITIZE=ON
31+
cmake --build build
32+
ctest --test-dir build --output-on-failure

CMakeLists.txt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ set (CMAKE_CXX_STANDARD 11) # for constexpr specifier and other goodies
99
set(CMAKE_CXX_STANDARD_REQUIRED True)
1010
set (CMAKE_C_STANDARD 99)
1111
set(CMAKE_C_STANDARD_REQUIRED True)
12-
if (NOT CMAKE_BUILD_TYPE)
13-
message(STATUS "No build type selected, default to Release")
14-
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
15-
endif()
16-
MESSAGE( STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE} )
1712

1813
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules")
1914
include(AppendCompilerFlags)
@@ -71,14 +66,31 @@ target_sources(FastPFOR PRIVATE
7166
src/streamvbyte.c
7267
)
7368
set_target_properties(FastPFOR PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
69+
70+
option(FASTPFOR_SANITIZE "Use sanitizers" OFF)
71+
72+
if(FASTPFOR_SANITIZE)
73+
message(STATUS "Enabling Sanitizers")
74+
target_compile_options(FastPFOR PUBLIC -fsanitize=address -fno-omit-frame-pointer -fno-sanitize-recover=all)
75+
target_compile_definitions(FastPFOR PUBLIC ASAN_OPTIONS=detect_leaks=1)
76+
target_link_libraries(FastPFOR PUBLIC -fsanitize=address -fno-omit-frame-pointer -fno-sanitize-recover=all)
77+
endif()
78+
79+
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES AND NOT FASTPFOR_SANITIZE)
80+
message(STATUS "No build type selected, default to Release")
81+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
82+
endif()
83+
MESSAGE( STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE} )
84+
85+
7486
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang")
7587
target_compile_options(FastPFOR PRIVATE -Wall -Wextra)
7688
endif()
7789
include(CheckCXXCompilerFlag)
7890
unset(FASTPFOR_COMPILER_SUPPORTS_MARCH_NATIVE CACHE)
7991
CHECK_CXX_COMPILER_FLAG(-march=native FASTPFOR_COMPILER_SUPPORTS_MARCH_NATIVE)
8092
if(FASTPFOR_COMPILER_SUPPORTS_MARCH_NATIVE)
81-
add_compile_options(-march=native)
93+
target_compile_options(FastPFOR PRIVATE -march=native)
8294
else()
8395
message(STATUS "native target not supported")
8496
endif()
@@ -161,9 +173,9 @@ else()
161173
target_link_libraries(inmemorybenchmarksnappy FastPFOR ${snappy_LIBRARIES})
162174
endif()
163175

164-
option(WITH_TEST "Build with Google Test" ON)
176+
option(FASTPFOR_WITH_TEST "Build with Google Test" ON)
165177

166-
if(WITH_TEST)
178+
if(FASTPFOR_WITH_TEST)
167179
CPMAddPackage(
168180
NAME googletest
169181
GITHUB_REPOSITORY google/googletest

0 commit comments

Comments
 (0)