xref: /llvm-project/compiler-rt/lib/memprof/tests/CMakeLists.txt (revision a35ac42fac88e82748a7e035821a1c6226be9ac0)
1include(CheckCXXCompilerFlag)
2include(CompilerRTCompile)
3include(CompilerRTLink)
4
5set(MEMPROF_UNITTEST_CFLAGS
6  ${COMPILER_RT_UNITTEST_CFLAGS}
7  ${COMPILER_RT_GTEST_CFLAGS}
8  ${COMPILER_RT_GMOCK_CFLAGS}
9  ${SANITIZER_TEST_CXX_CFLAGS}
10  -I${COMPILER_RT_SOURCE_DIR}/lib/
11  -DSANITIZER_COMMON_NO_REDEFINE_BUILTINS
12  -O2
13  -g
14  -fno-rtti
15  -Wno-pedantic
16  -fno-omit-frame-pointer)
17
18# Suppress warnings for gmock variadic macros for clang and gcc respectively.
19append_list_if(SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG -Wno-gnu-zero-variadic-macro-arguments MEMPROF_UNITTEST_CFLAGS)
20append_list_if(COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG -Wno-variadic-macros MEMPROF_UNITTEST_CFLAGS)
21
22file(GLOB MEMPROF_HEADERS ../*.h)
23
24set(MEMPROF_SOURCES
25  ../memprof_mibmap.cpp
26  ../memprof_rawprofile.cpp)
27
28set(MEMPROF_UNITTESTS
29  rawprofile.cpp
30  driver.cpp)
31
32include_directories(../../../include)
33
34set(MEMPROF_UNIT_TEST_HEADERS
35  ${MEMPROF_HEADERS})
36
37set(MEMPROF_UNITTEST_LINK_FLAGS
38  ${COMPILER_RT_UNITTEST_LINK_FLAGS})
39
40if(NOT WIN32)
41  list(APPEND MEMPROF_UNITTEST_LINK_FLAGS -pthread)
42endif()
43
44set(MEMPROF_UNITTEST_DEPS)
45if (TARGET cxx-headers OR HAVE_LIBCXX)
46  list(APPEND MEMPROF_UNITTEST_DEPS cxx-headers)
47endif()
48
49set(MEMPROF_UNITTEST_LINK_LIBRARIES
50  ${COMPILER_RT_UNWINDER_LINK_LIBS}
51  ${SANITIZER_TEST_CXX_LIBRARIES})
52append_list_if(COMPILER_RT_HAS_LIBDL -ldl MEMPROF_UNITTEST_LINK_LIBRARIES)
53
54# Adds memprof tests for each architecture.
55macro(add_memprof_tests_for_arch arch)
56  set(MEMPROF_TEST_RUNTIME_OBJECTS
57    $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
58    $<TARGET_OBJECTS:RTSanitizerCommonCoverage.${arch}>
59    $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
60    $<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.${arch}>
61    $<TARGET_OBJECTS:RTSanitizerCommonSymbolizerInternal.${arch}>
62  )
63  set(MEMPROF_TEST_RUNTIME RTMemProfTest.${arch})
64  add_library(${MEMPROF_TEST_RUNTIME} STATIC ${MEMPROF_TEST_RUNTIME_OBJECTS})
65  set_target_properties(${MEMPROF_TEST_RUNTIME} PROPERTIES
66    ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
67    FOLDER "Compiler-RT/Tests/Runtime")
68  set(MEMPROF_TEST_OBJECTS)
69  generate_compiler_rt_tests(MEMPROF_TEST_OBJECTS
70    MemProfUnitTests "MemProf-${arch}-UnitTest" ${arch}
71    RUNTIME ${MEMPROF_TEST_RUNTIME}
72    DEPS ${MEMPROF_UNITTEST_DEPS}
73    SOURCES ${MEMPROF_UNITTESTS} ${MEMPROF_SOURCES} ${COMPILER_RT_GTEST_SOURCE}
74    COMPILE_DEPS ${MEMPROF_UNIT_TEST_HEADERS}
75    CFLAGS ${MEMPROF_UNITTEST_CFLAGS}
76    LINK_FLAGS ${MEMPROF_UNITTEST_LINK_FLAGS} ${MEMPROF_UNITTEST_LINK_LIBRARIES})
77endmacro()
78
79# MemProf unit tests testsuite.
80add_custom_target(MemProfUnitTests)
81set_target_properties(MemProfUnitTests PROPERTIES FOLDER "Compiler-RT/Tests")
82if(COMPILER_RT_CAN_EXECUTE_TESTS AND COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST MEMPROF_SUPPORTED_ARCH)
83  # MemProf unit tests are only run on the host machine.
84  foreach(arch ${COMPILER_RT_DEFAULT_TARGET_ARCH})
85    add_memprof_tests_for_arch(${arch})
86  endforeach()
87endif()
88