Add missing unittest files to the cmake build.
[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   set_target_properties(${test_name}Tests PROPERTIES FOLDER "Tests")
16 endfunction()
17
18 # Visual Studio 2012 only supports up to 8 template parameters in
19 # std::tr1::tuple by default, but gtest requires 10
20 if(MSVC AND MSVC_VERSION EQUAL 1700)
21   add_definitions(-D_VARIADIC_MAX=10)
22 endif ()
23
24 add_custom_target(UnitTests)
25 set_target_properties(UnitTests PROPERTIES FOLDER "Tests")
26
27 include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
28 add_definitions(-DGTEST_HAS_RTTI=0)
29 if( LLVM_COMPILER_IS_GCC_COMPATIBLE )
30   llvm_replace_compiler_option(CMAKE_CXX_FLAGS "-frtti" "-fno-rtti")
31 elseif( MSVC )
32   llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/GR" "/GR-")
33 endif()
34
35 if (NOT LLVM_ENABLE_THREADS)
36   add_definitions(-DGTEST_HAS_PTHREAD=0)
37 endif()
38
39 if(SUPPORTS_NO_VARIADIC_MACROS_FLAG)
40   add_definitions("-Wno-variadic-macros")
41 endif()
42
43 set(LLVM_LINK_COMPONENTS
44   jit
45   interpreter
46   nativecodegen
47   BitWriter
48   BitReader
49   AsmParser
50   Core
51   Support
52   )
53
54 set(LLVM_USED_LIBS
55   gtest
56   gtest_main
57   LLVMSupport # gtest needs it for raw_ostream.
58   )
59
60 add_llvm_unittest(ADT
61   ADT/APFloatTest.cpp
62   ADT/APIntTest.cpp
63   ADT/BitVectorTest.cpp
64   ADT/DAGDeltaAlgorithmTest.cpp
65   ADT/DeltaAlgorithmTest.cpp
66   ADT/DenseMapTest.cpp
67   ADT/DenseSetTest.cpp
68   ADT/FoldingSet.cpp
69   ADT/HashingTest.cpp
70   ADT/ilistTest.cpp
71   ADT/ImmutableSetTest.cpp
72   ADT/IntEqClassesTest.cpp
73   ADT/IntervalMapTest.cpp
74   ADT/IntrusiveRefCntPtrTest.cpp
75   ADT/PackedVectorTest.cpp
76   ADT/SCCIteratorTest.cpp
77   ADT/SmallPtrSetTest.cpp
78   ADT/SmallStringTest.cpp
79   ADT/SmallVectorTest.cpp
80   ADT/SparseBitVectorTest.cpp
81   ADT/SparseSetTest.cpp
82   ADT/StringMapTest.cpp
83   ADT/StringRefTest.cpp
84   ADT/TripleTest.cpp
85   ADT/TwineTest.cpp
86   ADT/VariadicFunctionTest.cpp
87  )
88
89 add_llvm_unittest(Analysis
90   Analysis/ScalarEvolutionTest.cpp
91   )
92
93 add_llvm_unittest(ExecutionEngine
94   ExecutionEngine/ExecutionEngineTest.cpp
95   )
96
97 if( LLVM_USE_INTEL_JITEVENTS )
98   include_directories( ${LLVM_INTEL_JITEVENTS_INCDIR} )
99   link_directories( ${LLVM_INTEL_JITEVENTS_LIBDIR} )
100   set(ProfileTestSources
101     ExecutionEngine/JIT/IntelJITEventListenerTest.cpp
102     )
103   set(LLVM_LINK_COMPONENTS
104     ${LLVM_LINK_COMPONENTS}
105     IntelJITEvents
106     ) 
107 endif( LLVM_USE_INTEL_JITEVENTS )
108
109 if( LLVM_USE_OPROFILE )
110   set(ProfileTestSources
111     ${ProfileTestSources}
112     ExecutionEngine/JIT/OProfileJITEventListenerTest.cpp
113     )
114   set(LLVM_LINK_COMPONENTS
115     ${LLVM_LINK_COMPONENTS}
116     OProfileJIT
117     )
118 endif( LLVM_USE_OPROFILE )
119
120 set(JITTestsSources
121   ExecutionEngine/JIT/JITEventListenerTest.cpp
122   ExecutionEngine/JIT/JITMemoryManagerTest.cpp
123   ExecutionEngine/JIT/JITTest.cpp
124   ExecutionEngine/JIT/MultiJITTest.cpp
125   ${ProfileTestSources}
126   )
127
128 if(MSVC)
129   list(APPEND JITTestsSources ExecutionEngine/JIT/JITTests.def)
130 endif()
131
132 add_llvm_unittest(ExecutionEngine/JIT ${JITTestsSources})
133
134 if(MINGW OR CYGWIN)
135   set_property(TARGET JITTests PROPERTY LINK_FLAGS -Wl,--export-all-symbols)
136 endif()
137
138 add_llvm_unittest(Transforms/Utils
139   Transforms/Utils/Cloning.cpp
140   )
141
142 set(VMCoreSources
143   VMCore/ConstantsTest.cpp
144   VMCore/DominatorTreeTest.cpp
145   VMCore/InstructionsTest.cpp
146   VMCore/MetadataTest.cpp
147   VMCore/PassManagerTest.cpp
148   VMCore/ValueMapTest.cpp
149   VMCore/VerifierTest.cpp
150   )
151
152 # MSVC9 and 8 cannot compile ValueMapTest.cpp due to their bug.
153 # See issue#331418 in Visual Studio.
154 if(MSVC AND MSVC_VERSION LESS 1600)
155   list(REMOVE_ITEM VMCoreSources VMCore/ValueMapTest.cpp)
156 endif()
157
158 add_llvm_unittest(VMCore ${VMCoreSources})
159
160 add_llvm_unittest(Bitcode
161   Bitcode/BitReaderTest.cpp
162   )
163
164 set(LLVM_LINK_COMPONENTS
165   Support
166   Core
167   )
168
169 add_llvm_unittest(Support
170   Support/AlignOfTest.cpp
171   Support/AllocatorTest.cpp
172   Support/BlockFrequencyTest.cpp
173   Support/Casting.cpp
174   Support/CommandLineTest.cpp
175   Support/ConstantRangeTest.cpp
176   Support/DataExtractorTest.cpp
177   Support/EndianTest.cpp
178   Support/IntegersSubsetTest.cpp
179   Support/IRBuilderTest.cpp
180   Support/LeakDetectorTest.cpp
181   Support/ManagedStatic.cpp
182   Support/MathExtrasTest.cpp
183   Support/MDBuilderTest.cpp
184   Support/Path.cpp
185   Support/raw_ostream_test.cpp
186   Support/RegexTest.cpp
187   Support/SwapByteOrderTest.cpp
188   Support/TimeValue.cpp
189   Support/TypeBuilderTest.cpp
190   Support/ValueHandleTest.cpp
191   Support/YAMLParserTest.cpp
192   )