diff options
author | George Karpenkov <ekarpenkov@apple.com> | 2017-07-28 17:32:37 +0000 |
---|---|---|
committer | George Karpenkov <ekarpenkov@apple.com> | 2017-07-28 17:32:37 +0000 |
commit | b8f4c3386545a540eebf0d64473e8827373fcdf2 (patch) | |
tree | a5216bab48102ff009178e9e9a5e99580ff13204 /cmake | |
parent | 540a1c9dd6a85ee76473f85b8865aff3bd1bb991 (diff) |
[sanitizer tests CMake] Factor out CMake logic for compiling sanitizer tests
Currently there's a large amount of CMake logic duplication for
compiling sanitizer tests.
If we add more sanitizers, the duplication will get even worse.
This change factors out common compilation commands into a macro
available to all sanitizers.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@309405 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/Modules/CompilerRTCompile.cmake | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/cmake/Modules/CompilerRTCompile.cmake b/cmake/Modules/CompilerRTCompile.cmake index 30663b695..b39ca4ef8 100644 --- a/cmake/Modules/CompilerRTCompile.cmake +++ b/cmake/Modules/CompilerRTCompile.cmake @@ -24,6 +24,41 @@ function(translate_msvc_cflags out_flags msvc_flags) set(${out_flags} "${clang_flags}" PARENT_SCOPE) endfunction() +# Compile a sanitizer test with a freshly built clang +# for a given architecture, adding the result to the object list. +# - obj_list: output list of objects, populated by path +# of the generated object file. +# - source: source file of a test. +# - arch: architecture to compile for. +# sanitizer_test_compile(<obj_list> <source> <arch> +# KIND <custom namespace> +# COMPILE_DEPS <list of compile-time dependencies> +# DEPS <list of dependencies> +# CFLAGS <list of flags> +# ) +macro(sanitizer_test_compile obj_list source arch) + cmake_parse_arguments(TEST + "" "" "KIND;COMPILE_DEPS;DEPS;CFLAGS" ${ARGN}) + get_filename_component(basename ${source} NAME) + if(CMAKE_CONFIGURATION_TYPES) + set(output_obj + "${CMAKE_CFG_INTDIR}/${obj_list}.${basename}.${arch}${TEST_KIND}.o") + else() + set(output_obj "${obj_list}.${basename}.${arch}${TEST_KIND}.o") + endif() + + # Write out architecture-specific flags into TARGET_CFLAGS variable. + get_target_flags_for_arch(${arch} TARGET_CFLAGS) + set(COMPILE_DEPS ${TEST_COMPILE_DEPS}) + if(NOT COMPILER_RT_STANDALONE_BUILD) + list(APPEND COMPILE_DEPS ${TEST_DEPS}) + endif() + clang_compile(${output_obj} ${source} + CFLAGS ${TEST_CFLAGS} ${TARGET_CFLAGS} + DEPS ${TEST_COMPILE_DEPS}) + list(APPEND ${obj_list} ${output_obj}) +endmacro() + # Compile a source into an object file with COMPILER_RT_TEST_COMPILER using # a provided compile flags and dependenices. # clang_compile(<object> <source> |