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