3
0
mirror of https://github.com/triqs/dft_tools synced 2024-07-17 16:33:46 +02:00
dft_tools/share/cmake/Findlibubsan_rt.cmake

64 lines
1.9 KiB
CMake
Raw Normal View History

# Copyright Nils Wentzell 2018
# Distributed under the GNU GENERAL PUBLIC LICENSE Version 3.0.
# See accompanying file LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt
#
# This cmake find module looks for the LLVM Undefined Behavior Sanitizer Runtime Library
# It sets up : UBSAN_RT_LIBRARY
# This module finds the LLVM Undefined Behavior Sanitizer Runtime Library
# latter case skip to the "Boost CMake" section below. For the former
#
# Use this module by invoking find_package with the form::
#
# find_package(libubsan_rt [REQUIRED])
#
# Results are reported in::
#
# UBSAN_RT_LIBRARY Undefined Behavior Sanitizer Runtime Library
# [UBSAN_MINIMAL_RT_LIBRARY] Minimal version of UBSan Runtime, To be used in combination with Asan
set(TRIAL_PATHS
ENV LIBRARY_PATH
ENV LD_INCLUDE_PATH
/usr/lib
/usr/local/lib
/usr/lib/gcc/7/*
/usr/lib/gcc/*/*
/usr/lib/clang/*/lib/linux
/usr/lib/llvm-*/lib/clang/*/lib/linux
/usr/local/opt/llvm/lib/clang/*/lib/darwin
)
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
set(name clang_rt.ubsan_standalone-x86_64)
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
set(name ubsan)
else()
message(FATAL_ERROR "Undefined Behavior Sanitizer is not available for your compiler")
endif()
find_library(UBSAN_RT_LIBRARY
NAMES ${name}
PATHS ${TRIAL_PATHS}
)
# Try to find UBSan Minimal Runtime for Clang
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
find_library(UBSAN_MINIMAL_RT_LIBRARY
NAMES clang_rt.ubsan_minimal-x86_64
PATHS ${TRIAL_PATHS}
)
endif()
mark_as_advanced(UBSAN_RT_LIBRARY)
# Imported target
add_library(libubsan_rt SHARED IMPORTED)
set_property(TARGET libubsan_rt PROPERTY IMPORTED_LOCATION ${UBSAN_RT_LIBRARY})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args("Undefined Behavior Sanitizer Runtime Library"
REQUIRED_VARS UBSAN_RT_LIBRARY
FAIL_MESSAGE "Undefined Behavior Sanitizer Runtime Libraries not found! Consider installing for additional checks!"
)