|
| 1 | +include(CheckCXXCompilerFlag) |
| 2 | +include(CompilerRTCompile) |
| 3 | +include(CompilerRTLink) |
| 4 | + |
| 5 | +set(CTX_PROFILE_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. |
| 19 | +append_list_if(SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG -Wno-gnu-zero-variadic-macro-arguments CTX_PROFILE_UNITTEST_CFLAGS) |
| 20 | +append_list_if(COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG -Wno-variadic-macros CTX_PROFILE_UNITTEST_CFLAGS) |
| 21 | + |
| 22 | +file(GLOB PROFILE_HEADERS ../*.h) |
| 23 | + |
| 24 | +set(CTX_PROFILE_SOURCES |
| 25 | + ../CtxInstrProfiling.cpp) |
| 26 | + |
| 27 | +set(CTX_PROFILE_UNITTESTS |
| 28 | + CtxInstrProfilingTest.cpp |
| 29 | + driver.cpp) |
| 30 | + |
| 31 | +include_directories(../../../include) |
| 32 | + |
| 33 | +set(CTX_PROFILE_UNIT_TEST_HEADERS |
| 34 | + ${CTX_PROFILE_HEADERS}) |
| 35 | + |
| 36 | +set(CTX_PROFILE_UNITTEST_LINK_FLAGS |
| 37 | + ${COMPILER_RT_UNITTEST_LINK_FLAGS}) |
| 38 | + |
| 39 | +list(APPEND CTX_PROFILE_UNITTEST_LINK_FLAGS -pthread) |
| 40 | + |
| 41 | +set(CTX_PROFILE_UNITTEST_LINK_LIBRARIES |
| 42 | + ${COMPILER_RT_UNWINDER_LINK_LIBS} |
| 43 | + ${SANITIZER_TEST_CXX_LIBRARIES}) |
| 44 | +list(APPEND CTX_PROFILE_UNITTEST_LINK_LIBRARIES "dl") |
| 45 | + |
| 46 | +if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST CTX_PROFILE_SUPPORTED_ARCH) |
| 47 | + # Profile unit tests are only run on the host machine. |
| 48 | + set(arch ${COMPILER_RT_DEFAULT_TARGET_ARCH}) |
| 49 | + |
| 50 | + add_executable(CtxProfileUnitTests |
| 51 | + ${CTX_PROFILE_UNITTESTS} |
| 52 | + ${COMPILER_RT_GTEST_SOURCE} |
| 53 | + ${COMPILER_RT_GMOCK_SOURCE} |
| 54 | + ${CTX_PROFILE_SOURCES} |
| 55 | + $<TARGET_OBJECTS:RTSanitizerCommon.${arch}> |
| 56 | + $<TARGET_OBJECTS:RTSanitizerCommonCoverage.${arch}> |
| 57 | + $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}> |
| 58 | + $<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.${arch}> |
| 59 | + $<TARGET_OBJECTS:RTSanitizerCommonSymbolizerInternal.${arch}>) |
| 60 | + set_target_compile_flags(CtxProfileUnitTests ${CTX_PROFILE_UNITTEST_CFLAGS}) |
| 61 | + set_target_link_flags(CtxProfileUnitTests ${CTX_PROFILE_UNITTEST_LINK_FLAGS}) |
| 62 | + target_link_libraries(CtxProfileUnitTests ${CTX_PROFILE_UNITTEST_LINK_LIBRARIES}) |
| 63 | + |
| 64 | + if (TARGET cxx-headers OR HAVE_LIBCXX) |
| 65 | + add_dependencies(CtxProfileUnitTests cxx-headers) |
| 66 | + endif() |
| 67 | + |
| 68 | + set_target_properties(CtxProfileUnitTests PROPERTIES |
| 69 | + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
| 70 | +endif() |
0 commit comments