Fix gtest build issue on Visual Studio 2012 RC
[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/SmallBitVectorTest.cpp
77   ADT/SmallStringTest.cpp
78   ADT/SmallVectorTest.cpp
79   ADT/SparseBitVectorTest.cpp
80   ADT/SparseSetTest.cpp
81   ADT/StringMapTest.cpp
82   ADT/StringRefTest.cpp
83   ADT/TripleTest.cpp
84   ADT/TwineTest.cpp
85   ADT/VariadicFunctionTest.cpp
86  )
87
88 add_llvm_unittest(Analysis
89   Analysis/ScalarEvolutionTest.cpp
90   )
91
92 add_llvm_unittest(ExecutionEngine
93   ExecutionEngine/ExecutionEngineTest.cpp
94   )
95
96 if( LLVM_USE_INTEL_JITEVENTS )
97   include_directories( ${LLVM_INTEL_JITEVENTS_INCDIR} )
98   link_directories( ${LLVM_INTEL_JITEVENTS_LIBDIR} )
99   set(ProfileTestSources
100     ExecutionEngine/JIT/IntelJITEventListenerTest.cpp
101     )
102   set(LLVM_LINK_COMPONENTS
103     ${LLVM_LINK_COMPONENTS}
104     IntelJITEvents
105     ) 
106 endif( LLVM_USE_INTEL_JITEVENTS )
107
108 if( LLVM_USE_OPROFILE )
109   set(ProfileTestSources
110     ${ProfileTestSources}
111     ExecutionEngine/JIT/OProfileJITEventListenerTest.cpp
112     )
113   set(LLVM_LINK_COMPONENTS
114     ${LLVM_LINK_COMPONENTS}
115     OProfileJIT
116     )
117 endif( LLVM_USE_OPROFILE )
118
119 set(JITTestsSources
120   ExecutionEngine/JIT/JITEventListenerTest.cpp
121   ExecutionEngine/JIT/JITMemoryManagerTest.cpp
122   ExecutionEngine/JIT/JITTest.cpp
123   ExecutionEngine/JIT/MultiJITTest.cpp
124   ${ProfileTestSources}
125   )
126
127 if(MSVC)
128   list(APPEND JITTestsSources ExecutionEngine/JIT/JITTests.def)
129 endif()
130
131 add_llvm_unittest(ExecutionEngine/JIT ${JITTestsSources})
132
133 if(MINGW OR CYGWIN)
134   set_property(TARGET JITTests PROPERTY LINK_FLAGS -Wl,--export-all-symbols)
135 endif()
136
137 add_llvm_unittest(Transforms/Utils
138   Transforms/Utils/Cloning.cpp
139   )
140
141 set(VMCoreSources
142   VMCore/ConstantsTest.cpp
143   VMCore/InstructionsTest.cpp
144   VMCore/MetadataTest.cpp
145   VMCore/PassManagerTest.cpp
146   VMCore/ValueMapTest.cpp
147   VMCore/VerifierTest.cpp
148   VMCore/DominatorTreeTest.cpp
149   )
150
151 # MSVC9 and 8 cannot compile ValueMapTest.cpp due to their bug.
152 # See issue#331418 in Visual Studio.
153 if(MSVC AND MSVC_VERSION LESS 1600)
154   list(REMOVE_ITEM VMCoreSources VMCore/ValueMapTest.cpp)
155 endif()
156
157 add_llvm_unittest(VMCore ${VMCoreSources})
158
159 add_llvm_unittest(Bitcode
160   Bitcode/BitReaderTest.cpp
161   )
162
163 set(LLVM_LINK_COMPONENTS
164   Support
165   Core
166   )
167
168 add_llvm_unittest(Support
169   Support/AllocatorTest.cpp
170   Support/Casting.cpp
171   Support/CommandLineTest.cpp
172   Support/ConstantRangeTest.cpp
173   Support/EndianTest.cpp
174   Support/LeakDetectorTest.cpp
175   Support/MathExtrasTest.cpp
176   Support/Path.cpp
177   Support/raw_ostream_test.cpp
178   Support/RegexTest.cpp
179   Support/SwapByteOrderTest.cpp
180   Support/TimeValue.cpp
181   Support/TypeBuilderTest.cpp
182   Support/ValueHandleTest.cpp
183   Support/YAMLParserTest.cpp
184   )