Commit 8cc239b7 authored by Tom Finegan's avatar Tom Finegan

Add sanitizer support to CMake build.

Enabled via addition of -DSANITIZE=<sanitizer> to CMake
command line at generation time.

Change-Id: I32b5fc547bcd0329703d9012aa864d6a9cd6cb64
parent ba47c842
......@@ -47,6 +47,7 @@ include("${AOM_ROOT}/aom_scale/aom_scale.cmake")
include("${AOM_ROOT}/aom_util/aom_util.cmake")
include("${AOM_ROOT}/av1/av1.cmake")
include("${AOM_ROOT}/test/test.cmake")
include("${AOM_ROOT}/build/cmake/sanitizers.cmake")
include("${AOM_ROOT}/build/cmake/util.cmake")
set(AOM_RTCD_SOURCES
......
......@@ -480,7 +480,7 @@ function (setup_av1_targets)
endif ()
if (HAVE_SSE2)
require_flag_nomsvc("-msse2" NO)
require_compiler_flag_nomsvc("-msse2" NO)
add_intrinsics_object_library("-msse2" "sse2" "aom_av1_common"
"AOM_AV1_COMMON_INTRIN_SSE2" "aom")
if (CONFIG_AV1_DECODER)
......@@ -502,7 +502,7 @@ function (setup_av1_targets)
endif ()
if (HAVE_SSSE3)
require_flag_nomsvc("-mssse3" NO)
require_compiler_flag_nomsvc("-mssse3" NO)
add_intrinsics_object_library("-mssse3" "ssse3" "aom_av1_common"
"AOM_AV1_COMMON_INTRIN_SSSE3" "aom")
......@@ -520,7 +520,7 @@ function (setup_av1_targets)
endif ()
if (HAVE_SSE4_1)
require_flag_nomsvc("-msse4.1" NO)
require_compiler_flag_nomsvc("-msse4.1" NO)
add_intrinsics_object_library("-msse4.1" "sse4" "aom_av1_common"
"AOM_AV1_COMMON_INTRIN_SSE4_1" "aom")
......@@ -538,7 +538,7 @@ function (setup_av1_targets)
endif ()
if (HAVE_AVX2)
require_flag_nomsvc("-mavx2" NO)
require_compiler_flag_nomsvc("-mavx2" NO)
add_intrinsics_object_library("-mavx2" "avx2" "aom_av1_common"
"AOM_AV1_COMMON_INTRIN_AVX2" "aom")
......
......@@ -293,12 +293,12 @@ endif()
if (CONFIG_GCOV)
message("--- Testing for CONFIG_GCOV support.")
require_flag("-fprofile-arcs -ftest-coverage" YES)
require_compiler_flag("-fprofile-arcs -ftest-coverage" YES)
endif ()
if (CONFIG_GPROF)
message("--- Testing for CONFIG_GPROF support.")
require_flag("-pg" YES)
require_compiler_flag("-pg" YES)
endif ()
if (NOT MSVC)
......
......@@ -13,6 +13,7 @@ set(AOM_BUILD_CMAKE_COMPILER_FLAGS_CMAKE_ 1)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include("${AOM_ROOT}/build/cmake/compiler_tests.cmake")
# Strings used to cache failed C/CXX flags.
set(AOM_FAILED_C_FLAGS)
......@@ -113,7 +114,7 @@ endfunction ()
# Checks for support of $flag by both the C and CXX compilers. Terminates
# generation when support is not present in both compilers.
function (require_flag flag update_cmake_flags)
function (require_compiler_flag flag update_cmake_flags)
require_c_flag(${flag} ${update_cmake_flags})
require_cxx_flag(${flag} ${update_cmake_flags})
endfunction ()
......@@ -137,7 +138,7 @@ endfunction ()
# Checks only non-MSVC targets for support of $flag by both the C and CXX
# compilers. Terminates generation when support is not present in both
# compilers.
function (require_flag_nomsvc flag update_cmake_flags)
function (require_compiler_flag_nomsvc flag update_cmake_flags)
require_c_flag_nomsvc(${flag} ${update_cmake_flags})
require_cxx_flag_nomsvc(${flag} ${update_cmake_flags})
endfunction ()
......@@ -241,4 +242,18 @@ function (append_link_flag_to_target target flags)
set_target_properties(${target} PROPERTIES LINK_FLAGS ${target_link_flags})
endfunction ()
# Adds $flag to executable linker flags, and makes sure C/CXX builds still work.
function (require_linker_flag flag)
append_exe_linker_flag(${flag})
unset(c_passed)
aom_check_c_compiles("LINKER_FLAG_C_TEST(${flag})" "" c_passed)
unset(cxx_passed)
aom_check_cxx_compiles("LINKER_FLAG_CXX_TEST(${flag})" "" cxx_passed)
if (NOT c_passed OR NOT cxx_passed)
message(FATAL_ERROR "Linker flag test for ${flag} failed.")
endif ()
endfunction ()
endif () # AOM_BUILD_CMAKE_COMPILER_FLAGS_CMAKE_
##
## Copyright (c) 2017, Alliance for Open Media. All rights reserved
##
## This source code is subject to the terms of the BSD 2 Clause License and
## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
## was not distributed with this source code in the LICENSE file, you can
## obtain it at www.aomedia.org/license/software. If the Alliance for Open
## Media Patent License 1.0 was not distributed with this source code in the
## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
##
if (NOT AOM_BUILD_CMAKE_SANITIZERS_CMAKE_)
set(AOM_BUILD_CMAKE_SANITIZERS_CMAKE_ 1)
if (MSVC OR NOT SANITIZE)
return ()
endif ()
include("${AOM_ROOT}/build/cmake/compiler_flags.cmake")
string(TOLOWER ${SANITIZE} SANITIZE)
# Require the sanitizer requested.
require_compiler_flag("-fsanitize=${SANITIZE}" YES)
require_linker_flag("-fsanitize=${SANITIZE}")
# Make callstacks accurate.
require_compiler_flag("-fno-omit-frame-pointer -fno-optimize-sibling-calls" YES)
endif() # AOM_BUILD_CMAKE_SANITIZERS_CMAKE_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment