aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2018-09-02 10:50:35 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-09-02 11:13:58 +0200
commitb60a26650ea528acbf51cc2aa4b59ae31ef99f6e (patch)
tree77eb08874fbd86b499f2025b1c6886f54af9760e /cmake
parent5ccaafb31c1b19d9db088aa79ca59722d0d6390d (diff)
downloadcmocka-b60a26650ea528acbf51cc2aa4b59ae31ef99f6e.tar.gz
cmocka-b60a26650ea528acbf51cc2aa4b59ae31ef99f6e.tar.xz
cmocka-b60a26650ea528acbf51cc2aa4b59ae31ef99f6e.zip
cmake: Add support for AddressSanitizer
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Modules/AddCMockaTest.cmake29
1 files changed, 19 insertions, 10 deletions
diff --git a/cmake/Modules/AddCMockaTest.cmake b/cmake/Modules/AddCMockaTest.cmake
index 19de66e..60cccbe 100644
--- a/cmake/Modules/AddCMockaTest.cmake
+++ b/cmake/Modules/AddCMockaTest.cmake
@@ -1,7 +1,7 @@
-# - ADD_CMOCKA_TEST(test_name test_source linklib1 ... linklibN)
+# - add_cmocka_test(test_name test_source linklib1 ... linklibN)
# Copyright (c) 2007 Daniel Gollub <dgollub@suse.de>
-# Copyright (c) 2007-2010 Andreas Schneider <asn@cynapses.org>
+# Copyright (c) 2007-2018 Andreas Schneider <asn@cryptomilk.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
@@ -9,15 +9,24 @@
enable_testing()
include(CTest)
-if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
- set(CMAKE_C_FLAGS_PROFILING "-g -O0 -Wall -W -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wwrite-strings -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Compiler Flags")
- set(CMAKE_SHARED_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags")
- set(CMAKE_MODULE_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags")
- set(CMAKE_EXEC_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags")
-endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
+if((CMAKE_C_COMPILER_ID MATCHES "(GNU|Clang)") AND NOT MINGW)
+ # Activate with: -DCMAKE_BUILD_TYPE=Profiling
+ set(CMAKE_C_FLAGS_PROFILING "-g -O0 -fprofile-arcs -ftest-coverage")
+ set(CMAKE_SHARED_LINKER_FLAGS_PROFILING "-fprofile-arcs -ftest-coverage")
+ set(CMAKE_MODULE_LINKER_FLAGS_PROFILING "-fprofile-arcs -ftest-coverage")
+ set(CMAKE_EXEC_LINKER_FLAGS_PROFILING "-fprofile-arcs -ftest-coverage")
-function (ADD_CMOCKA_TEST _testName _testSource)
+ # Activate with: -DCMAKE_BUILD_TYPE=AddressSanitizer
+ set(CMAKE_C_FLAGS_ADDRESSSANITIZER "-g -O1 -fsanitize=address -fno-omit-frame-pointer")
+ set(CMAKE_SHARED_LINKER_FLAGS_ADDRESSSANITIZER "-fsanitize=address")
+ set(CMAKE_MODULE_LINKER_FLAGS_ADDRESSSANITIZER "-fsanitize=address")
+ set(CMAKE_EXEC_LINKER_FLAGS_ADDRESSSANITIZER "-fsanitize=address")
+endif()
+
+function(ADD_CMOCKA_TEST _testName _testSource)
add_executable(${_testName} ${_testSource})
+
target_link_libraries(${_testName} ${ARGN})
+
add_test(${_testName} ${CMAKE_CURRENT_BINARY_DIR}/${_testName})
-endfunction (ADD_CMOCKA_TEST)
+endfunction()