[clang] Handle __declspec() attributes in using
[llvm-project.git] / compiler-rt / lib / orc / tests / CMakeLists.txt
blob6014ed328d2cc84466eef2c573032b33b0142ab2
1 include(CompilerRTCompile)
3 include_directories(..)
5 # Unit tests target.
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.
15   -std=c++17
16   ${ORC_CFLAGS}
17   ${COMPILER_RT_UNITTEST_CFLAGS}
18   -I${COMPILER_RT_SOURCE_DIR}/lib/orc
19   )
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")
26 endfunction()
28 function(get_orc_lib_for_arch arch lib)
29   if(APPLE)
30     set(tgt_name "RTOrc.test.osx")
31   else()
32     set(tgt_name "RTOrc.test.${arch}")
33   endif()
34   set(${lib} "${tgt_name}" PARENT_SCOPE)
35 endfunction()
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})
44 if(APPLE)
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})
48 else()
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)
54 endif()
56 set(ORC_DEPS orc)
57 # ORC uses C++ standard library headers.
58 if (TARGET cxx-headers OR HAVE_LIBCXX)
59   list(APPEND ORC_DEPS cxx-headers)
60 endif()
62 macro(add_orc_unittest testname)
63   cmake_parse_arguments(TEST "" "" "SOURCES;HEADERS" ${ARGN})
64   if(UNIX)
65     foreach(arch ${ORC_TEST_ARCH})
66       set(TEST_OBJECTS)
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})
76     endforeach()
77   endif()
78 endmacro()
80 macro(add_orc_tool toolname)
81   cmake_parse_arguments(TOOL "" "" "SOURCES;HEADERS" ${ARGN})
82   if(UNIX)
83     foreach(arch ${ORC_TEST_ARCH})
84       set(TOOL_OBJECTS)
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}
91         DEPS ${ORC_DEPS}
92         CFLAGS ${ORC_UNITTEST_CFLAGS}
93         LINK_FLAGS ${ORC_UNITTEST_LINK_FLAGS})
94     endforeach()
95   endif()
96 endmacro()
98 if (APPLE)
99   add_orc_lib("RTOrc.test.osx"
100     $<TARGET_OBJECTS:RTOrc.osx>)
101 else()
102   foreach(arch ${ORC_SUPPORTED_ARCH})
103     add_orc_lib("RTOrc.test.${arch}"
104       $<TARGET_OBJECTS:RTOrc.${arch}>)
105   endforeach()
106 endif()
108 if(COMPILER_RT_INCLUDE_TESTS)
109   add_subdirectory(unit)
110 endif()
111 add_subdirectory(tools)