Skip to content

jwillikers/sanitizer-build-types

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

sanitizer-build-types

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.

ℹ️
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 FetchContent module.

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.

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:

cmake -DCMAKE_BUILD_TYPE=AddressSanitizer ..

For multi-configuration generators, use the --config flag in conjunction with the --build flag to designate the build configuration.

cmake --build .. --config AddressSanitizer
ℹ️
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 Apache 2.0 License.

Authors

Releases

No releases published

Packages

No packages published

Languages