Remove one of the LLVM-specific CMake hacks in favor of standard CMake
[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}Tests ${ARGN})
15   target_link_libraries(${test_name}Tests
16     gtest
17     gtest_main
18     LLVMSupport # gtest needs it for raw_ostream.
19     )
20
21   add_dependencies(UnitTests ${test_name}Tests)
22   set_target_properties(${test_name}Tests 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(ADT
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(Analysis
91   Analysis/ScalarEvolutionTest.cpp
92   )
93
94 add_llvm_unittest(ExecutionEngine
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/JIT ${JITTestsSources})
134
135 if(MINGW OR CYGWIN)
136   set_property(TARGET JITTests PROPERTY LINK_FLAGS -Wl,--export-all-symbols)
137 endif()
138
139 add_llvm_unittest(Transforms/Utils
140   Transforms/Utils/Cloning.cpp
141   )
142
143 set(VMCoreSources
144   VMCore/ConstantsTest.cpp
145   VMCore/DominatorTreeTest.cpp
146   VMCore/InstructionsTest.cpp
147   VMCore/MetadataTest.cpp
148   VMCore/PassManagerTest.cpp
149   VMCore/ValueMapTest.cpp
150   VMCore/VerifierTest.cpp
151   )
152
153 # MSVC9 and 8 cannot compile ValueMapTest.cpp due to their bug.
154 # See issue#331418 in Visual Studio.
155 if(MSVC AND MSVC_VERSION LESS 1600)
156   list(REMOVE_ITEM VMCoreSources VMCore/ValueMapTest.cpp)
157 endif()
158
159 add_llvm_unittest(VMCore ${VMCoreSources})
160
161 add_llvm_unittest(Bitcode
162   Bitcode/BitReaderTest.cpp
163   )
164
165 set(LLVM_LINK_COMPONENTS
166   Support
167   Core
168   )
169
170 add_llvm_unittest(Support
171   Support/AlignOfTest.cpp
172   Support/AllocatorTest.cpp
173   Support/BlockFrequencyTest.cpp
174   Support/Casting.cpp
175   Support/CommandLineTest.cpp
176   Support/ConstantRangeTest.cpp
177   Support/DataExtractorTest.cpp
178   Support/EndianTest.cpp
179   Support/IntegersSubsetTest.cpp
180   Support/IRBuilderTest.cpp
181   Support/LeakDetectorTest.cpp
182   Support/ManagedStatic.cpp
183   Support/MathExtrasTest.cpp
184   Support/MDBuilderTest.cpp
185   Support/Path.cpp
186   Support/raw_ostream_test.cpp
187   Support/RegexTest.cpp
188   Support/SwapByteOrderTest.cpp
189   Support/TimeValue.cpp
190   Support/TypeBuilderTest.cpp
191   Support/ValueHandleTest.cpp
192   Support/YAMLParserTest.cpp
193   )