1 include(CompilerRTCompile)
3 include_directories(..)
6 add_custom_target(OrcRTUnitTests)
7 set_target_properties(OrcRTUnitTests PROPERTIES FOLDER "OrcRT unittests")
9 # Testing tools target.
10 add_custom_target(OrcRTTools)
11 set_target_properties(OrcRTTools PROPERTIES FOLDER "OrcRT tools")
13 set(ORC_UNITTEST_CFLAGS
14 # FIXME: This should be set for all unit tests.
17 ${COMPILER_RT_UNITTEST_CFLAGS}
18 -I${COMPILER_RT_SOURCE_DIR}/lib/orc
21 function(add_orc_lib library)
22 add_library(${library} STATIC ${ARGN})
23 set_target_properties(${library} PROPERTIES
24 ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
25 FOLDER "Compiler-RT Runtime tests")
28 function(get_orc_lib_for_arch arch lib)
30 set(tgt_name "RTOrc.test.osx")
32 set(tgt_name "RTOrc.test.${arch}")
34 set(${lib} "${tgt_name}" PARENT_SCOPE)
37 set(ORC_TEST_ARCH ${ORC_SUPPORTED_ARCH})
38 set(ORC_UNITTEST_LINK_FLAGS
39 ${COMPILER_RT_UNITTEST_LINK_FLAGS}
40 ${CMAKE_THREAD_LIBS_INIT}
41 ${COMPILER_RT_UNWINDER_LINK_LIBS}
42 ${COMPILER_RT_CXX_LINK_LIBS})
45 darwin_filter_host_archs(ORC_SUPPORTED_ARCH ORC_TEST_ARCH)
46 list(APPEND ORC_UNITTEST_CFLAGS ${DARWIN_osx_CFLAGS})
47 list(APPEND ORC_UNITTEST_LINK_FLAGS ${DARWIN_osx_LINK_FLAGS})
49 append_list_if(COMPILER_RT_HAS_LIBM -lm ORC_UNITTEST_LINK_FLAGS)
50 append_list_if(COMPILER_RT_HAS_LIBRT -lrt ORC_UNITTEST_LINK_FLAGS)
51 append_list_if(COMPILER_RT_HAS_LIBDL -ldl ORC_UNITTEST_LINK_FLAGS)
52 append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread ORC_UNITTEST_LINK_FLAGS)
53 append_list_if(COMPILER_RT_HAS_LIBEXECINFO -lexecinfo ORC_UNITTEST_LINK_FLAGS)
57 # ORC uses C++ standard library headers.
58 if (TARGET cxx-headers OR HAVE_LIBCXX)
59 list(APPEND ORC_DEPS cxx-headers)
62 macro(add_orc_unittest testname)
63 cmake_parse_arguments(TEST "" "" "SOURCES;HEADERS" ${ARGN})
65 foreach(arch ${ORC_TEST_ARCH})
67 get_orc_lib_for_arch(${arch} ORC_RUNTIME_LIBS)
68 generate_compiler_rt_tests(TEST_OBJECTS
69 OrcRTUnitTests "${testname}-${arch}-Test" "${arch}"
70 SOURCES ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE}
71 RUNTIME "${ORC_RUNTIME_LIBS}"
72 COMPILE_DEPS ${TEST_HEADERS} ${ORC_HEADERS}
73 DEPS llvm_gtest ${ORC_DEPS}
74 CFLAGS ${ORC_UNITTEST_CFLAGS} ${COMPILER_RT_GTEST_CFLAGS}
75 LINK_FLAGS ${ORC_UNITTEST_LINK_FLAGS})
80 macro(add_orc_tool toolname)
81 cmake_parse_arguments(TOOL "" "" "SOURCES;HEADERS" ${ARGN})
83 foreach(arch ${ORC_TEST_ARCH})
85 get_orc_lib_for_arch(${arch} ORC_RUNTIME_LIBS)
86 generate_compiler_rt_tests(TOOL_OBJECTS
87 OrcRTTools "${toolname}-${arch}" "${arch}"
88 SOURCES ${TOOL_SOURCES}
89 RUNTIME "${ORC_RUNTIME_LIBS}"
90 COMPILE_DEPS ${TOOL_HEADERS} ${ORC_HEADERS}
92 CFLAGS ${ORC_UNITTEST_CFLAGS}
93 LINK_FLAGS ${ORC_UNITTEST_LINK_FLAGS})
99 add_orc_lib("RTOrc.test.osx"
100 $<TARGET_OBJECTS:RTOrc.osx>)
102 foreach(arch ${ORC_SUPPORTED_ARCH})
103 add_orc_lib("RTOrc.test.${arch}"
104 $<TARGET_OBJECTS:RTOrc.${arch}>)
108 if(COMPILER_RT_INCLUDE_TESTS)
109 add_subdirectory(unit)
111 add_subdirectory(tools)