Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 33aba8c

Browse files
author
George Karpenkov
committed
[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
1 parent 5215325 commit 33aba8c

File tree

5 files changed

+15
-64
lines changed

5 files changed

+15
-64
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ list(INSERT CMAKE_MODULE_PATH 0
2121
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
2222
)
2323

24+
if(CMAKE_CONFIGURATION_TYPES)
25+
set(CMAKE_CFG_RESOLVED_INTDIR "${CMAKE_CFG_INTDIR}/")
26+
else()
27+
set(CMAKE_CFG_RESOLVED_INTDIR "")
28+
endif()
29+
2430
include(base-config-ix)
2531
include(CompilerRTUtils)
2632

cmake/Modules/AddCompilerRT.cmake

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,7 @@ macro(add_compiler_rt_test test_suite test_name)
301301
if(TEST_SUBDIR)
302302
set(output_bin "${output_bin}/${TEST_SUBDIR}")
303303
endif()
304-
if(CMAKE_CONFIGURATION_TYPES)
305-
set(output_bin "${output_bin}/${CMAKE_CFG_INTDIR}")
306-
endif()
307-
set(output_bin "${output_bin}/${test_name}")
304+
set(output_bin "${output_bin}/${CMAKE_CFG_RESOLVED_INTDIR}${test_name}")
308305
if(MSVC)
309306
set(output_bin "${output_bin}.exe")
310307
endif()

lib/asan/tests/CMakeLists.txt

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,7 @@ append_list_if(ANDROID atomic ASAN_UNITTEST_NOINST_LIBS)
129129
# options in ${ARGN}, and add it to the object list.
130130
macro(asan_compile obj_list source arch kind)
131131
get_filename_component(basename ${source} NAME)
132-
if(CMAKE_CONFIGURATION_TYPES)
133-
set(output_obj "${CMAKE_CFG_INTDIR}/${obj_list}.${basename}.${arch}${kind}.o")
134-
else()
135-
set(output_obj "${obj_list}.${basename}.${arch}${kind}.o")
136-
endif()
132+
set(output_obj "${CMAKE_CFG_RESOLVED_INTDIR}${obj_list}.${basename}.${arch}${kind}.o")
137133
get_target_flags_for_arch(${arch} TARGET_CFLAGS)
138134
set(COMPILE_DEPS ${ASAN_UNITTEST_HEADERS} ${ASAN_BLACKLIST_FILE})
139135
if(NOT COMPILER_RT_STANDALONE_BUILD)
@@ -156,17 +152,7 @@ macro(add_asan_test test_suite test_name arch kind)
156152
endif()
157153
if(TEST_WITH_TEST_RUNTIME)
158154
list(APPEND TEST_DEPS ${ASAN_TEST_RUNTIME})
159-
if(CMAKE_CONFIGURATION_TYPES)
160-
set(configuration_path "${CMAKE_CFG_INTDIR}/")
161-
else()
162-
set(configuration_path "")
163-
endif()
164-
if(NOT MSVC)
165-
set(asan_test_runtime_path ${configuration_path}lib${ASAN_TEST_RUNTIME}.a)
166-
else()
167-
set(asan_test_runtime_path ${configuration_path}${ASAN_TEST_RUNTIME}.lib)
168-
endif()
169-
list(APPEND TEST_OBJECTS ${asan_test_runtime_path})
155+
list(APPEND TEST_OBJECTS $<TARGET_FILE:${ASAN_TEST_RUNTIME}>)
170156
endif()
171157
add_compiler_rt_test(${test_suite} ${test_name}
172158
SUBDIR ${TEST_SUBDIR}
@@ -245,27 +231,15 @@ macro(add_asan_tests_for_arch_and_kind arch kind)
245231
endif()
246232

247233
# Create the 'default' folder where ASAN tests are produced.
248-
if(CMAKE_CONFIGURATION_TYPES)
249-
foreach(build_mode ${CMAKE_CONFIGURATION_TYPES})
250-
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/default/${build_mode}")
251-
endforeach()
252-
else()
253-
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/default")
254-
endif()
234+
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/default/${CMAKE_CFG_RESOLVED_INTDIR}")
255235

256236
add_asan_test(AsanUnitTests "Asan-${arch}${kind}-Test"
257237
${arch} ${kind} SUBDIR "default"
258238
OBJECTS ${ASAN_INST_TEST_OBJECTS}
259239
LINK_FLAGS ${ASAN_UNITTEST_INSTRUMENTED_LINK_FLAGS})
260240
if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
261241
# Create the 'dynamic' folder where ASAN tests are produced.
262-
if(CMAKE_CONFIGURATION_TYPES)
263-
foreach(build_mode ${CMAKE_CONFIGURATION_TYPES})
264-
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/dynamic/${build_mode}")
265-
endforeach()
266-
else()
267-
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/dynamic")
268-
endif()
242+
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/dynamic/${CMAKE_CFG_RESOLVED_INTDIR}")
269243

270244
add_asan_test(AsanDynamicUnitTests "Asan-${arch}${kind}-Dynamic-Test"
271245
${arch} ${kind} SUBDIR "dynamic"

lib/interception/tests/CMakeLists.txt

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,7 @@ function(get_interception_lib_for_arch arch lib lib_name)
7474
set(tgt_name "RTInterception.test.${arch}")
7575
endif()
7676
set(${lib} "${tgt_name}" PARENT_SCOPE)
77-
if(CMAKE_CONFIGURATION_TYPES)
78-
set(configuration_path "${CMAKE_CFG_INTDIR}/")
79-
else()
80-
set(configuration_path "")
81-
endif()
82-
if(NOT MSVC)
83-
set(${lib_name} "${configuration_path}lib${tgt_name}.a" PARENT_SCOPE)
84-
else()
85-
set(${lib_name} "${configuration_path}${tgt_name}.lib" PARENT_SCOPE)
86-
endif()
77+
set(${lib_name} $<TARGET_FILE:${tgt_name}> PARENT_SCOPE)
8778
endfunction()
8879

8980
# Interception unit tests testsuite.
@@ -103,11 +94,7 @@ macro(add_interception_tests_for_arch arch)
10394
set(INTERCEPTION_TEST_OBJECTS)
10495
foreach(source ${INTERCEPTION_TEST_SOURCES})
10596
get_filename_component(basename ${source} NAME)
106-
if(CMAKE_CONFIGURATION_TYPES)
107-
set(output_obj "${CMAKE_CFG_INTDIR}/${basename}.${arch}.o")
108-
else()
109-
set(output_obj "${basename}.${arch}.o")
110-
endif()
97+
set(output_obj "${CMAKE_CFG_RESOLVED_INTDIR}${basename}.${arch}.o")
11198
clang_compile(${output_obj} ${source}
11299
CFLAGS ${INTERCEPTION_TEST_CFLAGS_COMMON} ${TARGET_FLAGS}
113100
DEPS ${INTERCEPTION_TEST_COMPILE_DEPS})

lib/sanitizer_common/tests/CMakeLists.txt

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,7 @@ function(get_sanitizer_common_lib_for_arch arch lib lib_name)
127127
set(tgt_name "RTSanitizerCommon.test.${arch}")
128128
endif()
129129
set(${lib} "${tgt_name}" PARENT_SCOPE)
130-
if(CMAKE_CONFIGURATION_TYPES)
131-
set(configuration_path "${CMAKE_CFG_INTDIR}/")
132-
else()
133-
set(configuration_path "")
134-
endif()
135-
if(NOT MSVC)
136-
set(${lib_name} "${configuration_path}lib${tgt_name}.a" PARENT_SCOPE)
137-
else()
138-
set(${lib_name} "${configuration_path}${tgt_name}.lib" PARENT_SCOPE)
139-
endif()
130+
set(${lib_name} $<TARGET_FILE:${tgt_name}> PARENT_SCOPE)
140131
endfunction()
141132

142133
# Sanitizer_common unit tests testsuite.
@@ -164,11 +155,7 @@ macro(add_sanitizer_tests_for_arch arch)
164155
set(SANITIZER_TEST_OBJECTS)
165156
foreach(source ${SANITIZER_TEST_SOURCES})
166157
get_filename_component(basename ${source} NAME)
167-
if(CMAKE_CONFIGURATION_TYPES)
168-
set(output_obj "${CMAKE_CFG_INTDIR}/${basename}.${arch}.o")
169-
else()
170-
set(output_obj "${basename}.${arch}.o")
171-
endif()
158+
set(output_obj "${CMAKE_CFG_RESOLVED_INTDIR}${basename}.${arch}.o")
172159
clang_compile(${output_obj} ${source}
173160
CFLAGS ${SANITIZER_TEST_CFLAGS_COMMON} ${TARGET_FLAGS}
174161
DEPS ${SANITIZER_TEST_COMPILE_DEPS})

0 commit comments

Comments
 (0)