brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.5 KiB · 7039a32 Raw
120 lines · plain
1include(CompilerRTCompile)2 3include_directories(..)4 5# Unit tests target.6add_custom_target(OrcRTUnitTests)7set_target_properties(OrcRTUnitTests PROPERTIES FOLDER "Compiler-RT/Tests")8 9# Testing tools target.10add_custom_target(OrcRTTools)11set_target_properties(OrcRTTools PROPERTIES FOLDER "Compiler-RT/Tools")12 13set(ORC_UNITTEST_CFLAGS14# FIXME: This should be set for all unit tests.15  -std=c++1716  ${ORC_CFLAGS}17  ${COMPILER_RT_UNITTEST_CFLAGS}18  -I${COMPILER_RT_SOURCE_DIR}/lib/orc19  )20 21function(add_orc_lib library)22  add_library(${library} STATIC ${ARGN})23  set_target_properties(${library} PROPERTIES24    ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}25    FOLDER "Compiler-RT/Tests/Runtime")26endfunction()27 28function(get_orc_lib_for_arch arch lib)29  if(APPLE)30    if("osx" IN_LIST ORC_SUPPORTED_OS)31      set(tgt_name "RTOrc.test.osx")32    endif()33  else()34    set(tgt_name "RTOrc.test.${arch}")35  endif()36  set(${lib} "${tgt_name}" PARENT_SCOPE)37endfunction()38 39set(ORC_TEST_ARCH ${ORC_SUPPORTED_ARCH})40set(ORC_UNITTEST_LINK_FLAGS41  ${COMPILER_RT_UNITTEST_LINK_FLAGS}42  ${CMAKE_THREAD_LIBS_INIT}43  ${COMPILER_RT_UNWINDER_LINK_LIBS}44  ${COMPILER_RT_CXX_LINK_LIBS})45 46if(APPLE)47  darwin_filter_host_archs(ORC_SUPPORTED_ARCH ORC_TEST_ARCH)48  list(APPEND ORC_UNITTEST_CFLAGS ${DARWIN_osx_CFLAGS})49  list(APPEND ORC_UNITTEST_LINK_FLAGS ${DARWIN_osx_LINK_FLAGS})50else()51  append_list_if(COMPILER_RT_HAS_LIBM -lm ORC_UNITTEST_LINK_FLAGS)52  append_list_if(COMPILER_RT_HAS_LIBRT -lrt ORC_UNITTEST_LINK_FLAGS)53  append_list_if(COMPILER_RT_HAS_LIBDL -ldl ORC_UNITTEST_LINK_FLAGS)54  append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread ORC_UNITTEST_LINK_FLAGS)55  append_list_if(COMPILER_RT_HAS_LIBEXECINFO -lexecinfo ORC_UNITTEST_LINK_FLAGS)56endif()57 58set(ORC_DEPS orc)59# ORC uses C++ standard library headers.60if (TARGET cxx-headers OR HAVE_LIBCXX)61  list(APPEND ORC_DEPS cxx-headers)62endif()63 64macro(add_orc_unittest testname)65  cmake_parse_arguments(TEST "" "" "SOURCES;HEADERS" ${ARGN})66  if(UNIX)67    foreach(arch ${ORC_TEST_ARCH})68      set(TEST_OBJECTS)69      get_orc_lib_for_arch(${arch} ORC_RUNTIME_LIBS)70      if(ORC_RUNTIME_LIBS)71        generate_compiler_rt_tests(TEST_OBJECTS72          OrcRTUnitTests "${testname}-${arch}-Test" "${arch}"73          SOURCES ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE}74          RUNTIME "${ORC_RUNTIME_LIBS}"75          COMPILE_DEPS ${TEST_HEADERS} ${ORC_HEADERS}76          DEPS ${ORC_DEPS}77          CFLAGS ${ORC_UNITTEST_CFLAGS} ${COMPILER_RT_GTEST_CFLAGS}78          LINK_FLAGS ${ORC_UNITTEST_LINK_FLAGS})79      endif()80    endforeach()81  endif()82endmacro()83 84macro(add_orc_tool toolname)85  cmake_parse_arguments(TOOL "" "" "SOURCES;HEADERS" ${ARGN})86  if(UNIX)87    foreach(arch ${ORC_TEST_ARCH})88      set(TOOL_OBJECTS)89      get_orc_lib_for_arch(${arch} ORC_RUNTIME_LIBS)90      if(ORC_RUNTIME_LIBS)91        generate_compiler_rt_tests(TOOL_OBJECTS92          OrcRTTools "${toolname}-${arch}" "${arch}"93          SOURCES ${TOOL_SOURCES}94          RUNTIME "${ORC_RUNTIME_LIBS}"95          COMPILE_DEPS ${TOOL_HEADERS} ${ORC_HEADERS}96          DEPS ${ORC_DEPS}97          CFLAGS ${ORC_UNITTEST_CFLAGS}98          LINK_FLAGS ${ORC_UNITTEST_LINK_FLAGS})99      endif()100    endforeach()101  endif()102endmacro()103 104if (APPLE)105  if("osx" IN_LIST ORC_SUPPORTED_OS)106    add_orc_lib("RTOrc.test.osx"107      $<TARGET_OBJECTS:RTOrc.osx>)108  endif()109else()110  foreach(arch ${ORC_SUPPORTED_ARCH})111    add_orc_lib("RTOrc.test.${arch}"112      $<TARGET_OBJECTS:RTOrc.${arch}>)113  endforeach()114endif()115 116if(COMPILER_RT_INCLUDE_TESTS)117  add_subdirectory(unit)118endif()119add_subdirectory(tools)120