diff options
author | George Karpenkov <ekarpenkov@apple.com> | 2017-07-28 00:50:56 +0000 |
---|---|---|
committer | George Karpenkov <ekarpenkov@apple.com> | 2017-07-28 00:50:56 +0000 |
commit | 33aba8c1c12302cd0e59995896a49338993022f6 (patch) | |
tree | 7f632539839fa37005821ff8b678c0d8f57f534a | |
parent | 5215325996151915d06feb6917b9b9d54ea8dec9 (diff) | |
download | compiler-rt-33aba8c1c12302cd0e59995896a49338993022f6.tar.gz |
[sanitizers] Sanitizer tests CMake clean up: try #2
This patch addresses two issues:
Most of the time, hacks with `if/else` in order to get support for
multi-configuration builds are superfluous.
The variable `CMAKE_CFG_INTDIR` was created precisely for this purpose: it
expands to `.` on all single-configuration builds, and to a configuration
name otherwise.
The `if/else` hacks for the library name generation should also not be
done, as CMake has `TARGET_FILE` generator expression precisely for this
purpose, as it expands to the exact filename of the resulting target.
Differential Revision: https://reviews.llvm.org/D35952
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@309341 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | cmake/Modules/AddCompilerRT.cmake | 5 | ||||
-rw-r--r-- | lib/asan/tests/CMakeLists.txt | 34 | ||||
-rw-r--r-- | lib/interception/tests/CMakeLists.txt | 17 | ||||
-rw-r--r-- | lib/sanitizer_common/tests/CMakeLists.txt | 17 |
5 files changed, 15 insertions, 64 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index f997c5341..6d176bc5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,12 @@ list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" ) +if(CMAKE_CONFIGURATION_TYPES) + set(CMAKE_CFG_RESOLVED_INTDIR "${CMAKE_CFG_INTDIR}/") +else() + set(CMAKE_CFG_RESOLVED_INTDIR "") +endif() + include(base-config-ix) include(CompilerRTUtils) diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake index bc5fb9ff7..78663353c 100644 --- a/cmake/Modules/AddCompilerRT.cmake +++ b/cmake/Modules/AddCompilerRT.cmake @@ -301,10 +301,7 @@ macro(add_compiler_rt_test test_suite test_name) if(TEST_SUBDIR) set(output_bin "${output_bin}/${TEST_SUBDIR}") endif() - if(CMAKE_CONFIGURATION_TYPES) - set(output_bin "${output_bin}/${CMAKE_CFG_INTDIR}") - endif() - set(output_bin "${output_bin}/${test_name}") + set(output_bin "${output_bin}/${CMAKE_CFG_RESOLVED_INTDIR}${test_name}") if(MSVC) set(output_bin "${output_bin}.exe") endif() diff --git a/lib/asan/tests/CMakeLists.txt b/lib/asan/tests/CMakeLists.txt index 8089d51ef..9342fa4f7 100644 --- a/lib/asan/tests/CMakeLists.txt +++ b/lib/asan/tests/CMakeLists.txt @@ -129,11 +129,7 @@ append_list_if(ANDROID atomic ASAN_UNITTEST_NOINST_LIBS) # options in ${ARGN}, and add it to the object list. macro(asan_compile obj_list source arch kind) get_filename_component(basename ${source} NAME) - if(CMAKE_CONFIGURATION_TYPES) - set(output_obj "${CMAKE_CFG_INTDIR}/${obj_list}.${basename}.${arch}${kind}.o") - else() - set(output_obj "${obj_list}.${basename}.${arch}${kind}.o") - endif() + set(output_obj "${CMAKE_CFG_RESOLVED_INTDIR}${obj_list}.${basename}.${arch}${kind}.o") get_target_flags_for_arch(${arch} TARGET_CFLAGS) set(COMPILE_DEPS ${ASAN_UNITTEST_HEADERS} ${ASAN_BLACKLIST_FILE}) if(NOT COMPILER_RT_STANDALONE_BUILD) @@ -156,17 +152,7 @@ macro(add_asan_test test_suite test_name arch kind) endif() if(TEST_WITH_TEST_RUNTIME) list(APPEND TEST_DEPS ${ASAN_TEST_RUNTIME}) - if(CMAKE_CONFIGURATION_TYPES) - set(configuration_path "${CMAKE_CFG_INTDIR}/") - else() - set(configuration_path "") - endif() - if(NOT MSVC) - set(asan_test_runtime_path ${configuration_path}lib${ASAN_TEST_RUNTIME}.a) - else() - set(asan_test_runtime_path ${configuration_path}${ASAN_TEST_RUNTIME}.lib) - endif() - list(APPEND TEST_OBJECTS ${asan_test_runtime_path}) + list(APPEND TEST_OBJECTS $<TARGET_FILE:${ASAN_TEST_RUNTIME}>) endif() add_compiler_rt_test(${test_suite} ${test_name} SUBDIR ${TEST_SUBDIR} @@ -245,13 +231,7 @@ macro(add_asan_tests_for_arch_and_kind arch kind) endif() # Create the 'default' folder where ASAN tests are produced. - if(CMAKE_CONFIGURATION_TYPES) - foreach(build_mode ${CMAKE_CONFIGURATION_TYPES}) - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/default/${build_mode}") - endforeach() - else() - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/default") - endif() + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/default/${CMAKE_CFG_RESOLVED_INTDIR}") add_asan_test(AsanUnitTests "Asan-${arch}${kind}-Test" ${arch} ${kind} SUBDIR "default" @@ -259,13 +239,7 @@ macro(add_asan_tests_for_arch_and_kind arch kind) LINK_FLAGS ${ASAN_UNITTEST_INSTRUMENTED_LINK_FLAGS}) if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME) # Create the 'dynamic' folder where ASAN tests are produced. - if(CMAKE_CONFIGURATION_TYPES) - foreach(build_mode ${CMAKE_CONFIGURATION_TYPES}) - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/dynamic/${build_mode}") - endforeach() - else() - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/dynamic") - endif() + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/dynamic/${CMAKE_CFG_RESOLVED_INTDIR}") add_asan_test(AsanDynamicUnitTests "Asan-${arch}${kind}-Dynamic-Test" ${arch} ${kind} SUBDIR "dynamic" diff --git a/lib/interception/tests/CMakeLists.txt b/lib/interception/tests/CMakeLists.txt index 5ea943f9a..5f4033104 100644 --- a/lib/interception/tests/CMakeLists.txt +++ b/lib/interception/tests/CMakeLists.txt @@ -74,16 +74,7 @@ function(get_interception_lib_for_arch arch lib lib_name) set(tgt_name "RTInterception.test.${arch}") endif() set(${lib} "${tgt_name}" PARENT_SCOPE) - if(CMAKE_CONFIGURATION_TYPES) - set(configuration_path "${CMAKE_CFG_INTDIR}/") - else() - set(configuration_path "") - endif() - if(NOT MSVC) - set(${lib_name} "${configuration_path}lib${tgt_name}.a" PARENT_SCOPE) - else() - set(${lib_name} "${configuration_path}${tgt_name}.lib" PARENT_SCOPE) - endif() + set(${lib_name} $<TARGET_FILE:${tgt_name}> PARENT_SCOPE) endfunction() # Interception unit tests testsuite. @@ -103,11 +94,7 @@ macro(add_interception_tests_for_arch arch) set(INTERCEPTION_TEST_OBJECTS) foreach(source ${INTERCEPTION_TEST_SOURCES}) get_filename_component(basename ${source} NAME) - if(CMAKE_CONFIGURATION_TYPES) - set(output_obj "${CMAKE_CFG_INTDIR}/${basename}.${arch}.o") - else() - set(output_obj "${basename}.${arch}.o") - endif() + set(output_obj "${CMAKE_CFG_RESOLVED_INTDIR}${basename}.${arch}.o") clang_compile(${output_obj} ${source} CFLAGS ${INTERCEPTION_TEST_CFLAGS_COMMON} ${TARGET_FLAGS} DEPS ${INTERCEPTION_TEST_COMPILE_DEPS}) diff --git a/lib/sanitizer_common/tests/CMakeLists.txt b/lib/sanitizer_common/tests/CMakeLists.txt index 2acedd0ef..13c016314 100644 --- a/lib/sanitizer_common/tests/CMakeLists.txt +++ b/lib/sanitizer_common/tests/CMakeLists.txt @@ -127,16 +127,7 @@ function(get_sanitizer_common_lib_for_arch arch lib lib_name) set(tgt_name "RTSanitizerCommon.test.${arch}") endif() set(${lib} "${tgt_name}" PARENT_SCOPE) - if(CMAKE_CONFIGURATION_TYPES) - set(configuration_path "${CMAKE_CFG_INTDIR}/") - else() - set(configuration_path "") - endif() - if(NOT MSVC) - set(${lib_name} "${configuration_path}lib${tgt_name}.a" PARENT_SCOPE) - else() - set(${lib_name} "${configuration_path}${tgt_name}.lib" PARENT_SCOPE) - endif() + set(${lib_name} $<TARGET_FILE:${tgt_name}> PARENT_SCOPE) endfunction() # Sanitizer_common unit tests testsuite. @@ -164,11 +155,7 @@ macro(add_sanitizer_tests_for_arch arch) set(SANITIZER_TEST_OBJECTS) foreach(source ${SANITIZER_TEST_SOURCES}) get_filename_component(basename ${source} NAME) - if(CMAKE_CONFIGURATION_TYPES) - set(output_obj "${CMAKE_CFG_INTDIR}/${basename}.${arch}.o") - else() - set(output_obj "${basename}.${arch}.o") - endif() + set(output_obj "${CMAKE_CFG_RESOLVED_INTDIR}${basename}.${arch}.o") clang_compile(${output_obj} ${source} CFLAGS ${SANITIZER_TEST_CFLAGS_COMMON} ${TARGET_FLAGS} DEPS ${SANITIZER_TEST_COMPILE_DEPS}) |