Disable RTTI when building unit tests. This avoids errors at link time.
[oota-llvm.git] / unittests / CMakeLists.txt
1 function(add_llvm_unittest test_dirname)
2   string(REGEX MATCH "([^/]+)$" test_name ${test_dirname})
3   if (CMAKE_BUILD_TYPE)
4     set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
5       ${LLVM_BINARY_DIR}/unittests/${test_dirname}/${CMAKE_BUILD_TYPE})
6   else()
7     set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
8       ${LLVM_BINARY_DIR}/unittests/${test_dirname})
9   endif()
10   if( NOT LLVM_BUILD_TESTS )
11     set(EXCLUDE_FROM_ALL ON)
12   endif()
13   add_llvm_executable(${test_name}Tests ${ARGN})
14   add_dependencies(UnitTests ${test_name}Tests)
15 endfunction()
16
17 add_custom_target(UnitTests)
18
19 include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
20 add_definitions(-DGTEST_HAS_RTTI=0)
21 if( CMAKE_COMPILER_IS_GNUCXX )
22   llvm_replace_compiler_option(CMAKE_CXX_FLAGS "-frtti" "-fno-rtti")
23 elseif( MSVC )
24   llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/GR" "/GR-")
25 endif()
26
27 if (NOT LLVM_ENABLE_THREADS)
28   add_definitions(-DGTEST_HAS_PTHREAD=0)
29 endif()
30
31 if(SUPPORTS_NO_VARIADIC_MACROS_FLAG)
32   add_definitions("-Wno-variadic-macros")
33 endif()
34
35 set(LLVM_LINK_COMPONENTS
36   jit
37   interpreter
38   nativecodegen
39   BitWriter
40   BitReader
41   AsmParser
42   Core
43   Support
44   )
45
46 set(LLVM_USED_LIBS
47   gtest
48   gtest_main
49   LLVMSupport # gtest needs it for raw_ostream.
50   )
51
52 add_llvm_unittest(ADT
53   ADT/APFloatTest.cpp
54   ADT/APIntTest.cpp
55   ADT/BitVectorTest.cpp
56   ADT/DAGDeltaAlgorithmTest.cpp
57   ADT/DeltaAlgorithmTest.cpp
58   ADT/DenseMapTest.cpp
59   ADT/DenseSetTest.cpp
60   ADT/FoldingSet.cpp
61   ADT/ilistTest.cpp
62   ADT/ImmutableSetTest.cpp
63   ADT/IntEqClassesTest.cpp
64   ADT/IntervalMapTest.cpp
65   ADT/SmallBitVectorTest.cpp
66   ADT/SmallStringTest.cpp
67   ADT/SmallVectorTest.cpp
68   ADT/SparseBitVectorTest.cpp
69   ADT/StringMapTest.cpp
70   ADT/StringRefTest.cpp
71   ADT/TripleTest.cpp
72   ADT/TwineTest.cpp
73  )
74
75 add_llvm_unittest(Analysis
76   Analysis/ScalarEvolutionTest.cpp
77   )
78
79 add_llvm_unittest(ExecutionEngine
80   ExecutionEngine/ExecutionEngineTest.cpp
81   )
82
83 set(JITTestsSources
84   ExecutionEngine/JIT/JITEventListenerTest.cpp
85   ExecutionEngine/JIT/JITMemoryManagerTest.cpp
86   ExecutionEngine/JIT/JITTest.cpp
87   ExecutionEngine/JIT/MultiJITTest.cpp
88   )
89
90 if(MSVC)
91   list(APPEND JITTestsSources ExecutionEngine/JIT/JITTests.def)
92 endif()
93
94 add_llvm_unittest(ExecutionEngine/JIT ${JITTestsSources})
95
96 if(MINGW)
97   set_property(TARGET JITTests PROPERTY LINK_FLAGS -Wl,--export-all-symbols)
98 endif()
99
100 add_llvm_unittest(Transforms/Utils
101   Transforms/Utils/Cloning.cpp
102   )
103
104 set(VMCoreSources
105   VMCore/ConstantsTest.cpp
106   VMCore/DerivedTypesTest.cpp
107   VMCore/InstructionsTest.cpp
108   VMCore/MetadataTest.cpp
109   VMCore/PassManagerTest.cpp
110   VMCore/ValueMapTest.cpp
111   VMCore/VerifierTest.cpp
112   )
113
114 # MSVC9 and 8 cannot compile ValueMapTest.cpp due to their bug.
115 # See issue#331418 in Visual Studio.
116 if(MSVC AND MSVC_VERSION LESS 1600)
117   list(REMOVE_ITEM VMCoreSources VMCore/ValueMapTest.cpp)
118 endif()
119
120 add_llvm_unittest(VMCore ${VMCoreSources})
121
122 set(LLVM_LINK_COMPONENTS
123   Support
124   Core
125   )
126
127 add_llvm_unittest(Support
128   Support/AllocatorTest.cpp
129   Support/Casting.cpp
130   Support/CommandLineTest.cpp
131   Support/ConstantRangeTest.cpp
132   Support/EndianTest.cpp
133   Support/LeakDetectorTest.cpp
134   Support/MathExtrasTest.cpp
135   Support/Path.cpp
136   Support/raw_ostream_test.cpp
137   Support/RegexTest.cpp
138   Support/SwapByteOrderTest.cpp
139   Support/TimeValue.cpp
140   Support/TypeBuilderTest.cpp
141   Support/ValueHandleTest.cpp
142   )