https://github.com/jwillikers/sanitizer-build-types
A CMake module for adding the necessary flags for the various sanitizers.
https://github.com/jwillikers/sanitizer-build-types
asan build-types c clang cmake cmake-module cmake-modules cpp gcc msan sanitizer sanitizers tsan
Last synced: 6 months ago
JSON representation
A CMake module for adding the necessary flags for the various sanitizers.
- Host: GitHub
- URL: https://github.com/jwillikers/sanitizer-build-types
- Owner: jwillikers
- License: apache-2.0
- Archived: true
- Created: 2020-02-26T00:49:58.000Z (over 5 years ago)
- Default Branch: develop
- Last Pushed: 2020-02-26T17:47:11.000Z (over 5 years ago)
- Last Synced: 2025-04-06T21:52:14.314Z (6 months ago)
- Topics: asan, build-types, c, clang, cmake, cmake-module, cmake-modules, cpp, gcc, msan, sanitizer, sanitizers, tsan
- Language: CMake
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
Awesome Lists containing this project
README
= sanitizer-build-types
Jordan Williams
ifdef::env-github[]
:tip-caption: :bulb:
:note-caption: :information_source:
:important-caption: :heavy_exclamation_mark:
:caution-caption: :fire:
:warning-caption: :warning:
endif::[]== Summary
A CMake module for adding the necessary flags for the various sanitizers.
The flags are added to the designated build types / configurations provided by the caller.NOTE: Only LLVM Clang and GCC are supported at this time.
MSVC supports ASAN for 32-bit builds at the time of this writing, but this has not been implemented yet.== Configure
It is easy to incorporate this project directly at configure time by using CMake's https://cmake.org/cmake/help/latest/module/FetchContent.html[FetchContent] module.
[source,cmake]
----
include(FetchContent)
FetchContent_Declare(sanitizer-build-types GIT_REPOSITORY https://github.com/jwillikers/sanitizer-build-types GIT_TAG 0.1.0)
FetchContent_GetProperties(sanitizer-build-types)
if(NOT sanitizer-build-types_POPULATED)
FetchContent_Populate(sanitizer-build-types)
list(APPEND CMAKE_MODULE_PATH ${sanitizer-build-types_SOURCE_DIR}/cmake/modules)
endif()
----== Usage
To use, just include the `SanitizerBuildTypes` module, and call the `sanitizer_build_types` function as follows.
[source,cmake]
----
include(SanitizerBuildTypes)
sanitizer_build_types(ASAN AddressSanitizer LSAN LeakSanitizer MSAN MemorySanitizer TSAN ThreadSanitizer UBSAN UndefinedBehaviorSanitizer)
----The only arguments required are the names of the configurations.
In the previous example, the build type `AddressSanitizer` has been configured as a debug build and given the necessary compile and link flags to enable the Address Sanitizer.
For a single-configuration generator, this build type can be enabled from the build directory like so:[source,cmake]
----
cmake -DCMAKE_BUILD_TYPE=AddressSanitizer ..
----For multi-configuration generators, use the `--config` flag in conjunction with the `--build` flag to designate the build configuration.
[source,cmake]
----
cmake --build .. --config AddressSanitizer
----NOTE: It is not necessary to define build types for _all_ 5 sanitizers.
Feel free to omit those you don't want.== License
This project is licensed under the link:./LICENSE[Apache 2.0 License].
== Authors
https://github.com/jwillikers[{author}]