Skip to content

Commit a68397c

Browse files
committed
Add address sanitizer as an option for GCC & Clang
Add corresponding option SQLITECPP_USE_ASAN Also formalize previously existing SQLITECPP_USE_GCOV option
1 parent 9b00034 commit a68397c

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ before_install:
171171
before_script:
172172
- mkdir build
173173
- cd build
174-
- cmake -DCMAKE_BUILD_TYPE=Debug -DSQLITECPP_USE_GCOV=ON -DSQLITECPP_BUILD_EXAMPLES=ON -DSQLITECPP_BUILD_TESTS=ON ..
174+
- cmake -DCMAKE_BUILD_TYPE=Debug -DSQLITECPP_USE_ASAN=ON -DSQLITECPP_USE_GCOV=ON -DSQLITECPP_BUILD_EXAMPLES=ON -DSQLITECPP_BUILD_TESTS=ON ..
175175

176176
# build examples, and run tests (ie make & make test)
177177
script:

CMakeLists.txt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,10 @@ else (MSVC)
4242
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++0x-compat") # C++ only
4343
if (CMAKE_COMPILER_IS_GNUCXX)
4444
# GCC flags
45-
if (SQLITECPP_USE_GCOV AND CMAKE_COMPILER_IS_GNUCXX)
46-
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
47-
message (STATUS "Using GCov instrumentation")
48-
else ()
49-
message (WARNING "GCov instrumentation works best in Debug mode")
50-
endif ()
51-
add_compile_options (-coverage) # NOTE would be usefull but not working with current google test and gcc 4.8 -fkeep-inline-functions
45+
option(SQLITECPP_USE_GCOV "USE GCov instrumentation." OFF)
46+
if (SQLITECPP_USE_GCOV)
47+
message (STATUS "Using GCov instrumentation")
48+
add_compile_options (-coverage) # NOTE -fkeep-inline-functions would be usefull but not working with current google test and gcc 4.8
5249
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -coverage")
5350
endif ()
5451
endif (CMAKE_COMPILER_IS_GNUCXX)
@@ -206,6 +203,18 @@ install(EXPORT ${PROJECT_NAME}Config DESTINATION lib/cmake/${PROJECT_NAME})
206203
# set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-DSQLITECPP_HAS_MEM_STRUCT")
207204
#endif()
208205

206+
option(SQLITECPP_USE_ASAN "Use Address Sanitizer." OFF)
207+
if (SQLITECPP_USE_ASAN)
208+
if ((CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 6) OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"))
209+
message (STATUS "Using Address Sanitizer")
210+
set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-fsanitize=address -fno-omit-frame-pointer")
211+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
212+
if (CMAKE_COMPILER_IS_GNUCXX)
213+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
214+
endif ()
215+
endif ()
216+
endif (SQLITECPP_USE_ASAN)
217+
209218
option(SQLITECPP_INTERNAL_SQLITE "Add the internal SQLite3 source to the project." ON)
210219
if (SQLITECPP_INTERNAL_SQLITE)
211220
# build the SQLite3 C library (for ease of use/compatibility) versus Linux sqlite3-dev package

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mkdir -p build
1111
cd build
1212

1313
# Generate a Makefile for GCC (or Clang, depanding on CC/CXX envvar)
14-
cmake -DCMAKE_BUILD_TYPE=Debug -DSQLITECPP_USE_GCOV=OFF -DSQLITECPP_BUILD_EXAMPLES=ON -DSQLITECPP_BUILD_TESTS=ON ..
14+
cmake -DCMAKE_BUILD_TYPE=Debug -DSQLITECPP_USE_ASAN=ON -DSQLITECPP_USE_GCOV=OFF -DSQLITECPP_BUILD_EXAMPLES=ON -DSQLITECPP_BUILD_TESTS=ON ..
1515

1616
# Build (ie 'make')
1717
cmake --build .

0 commit comments

Comments
 (0)