unittests/CMakeLists.txt: Tweak unittests' layout to be identical to GNU 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 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 (NOT LLVM_ENABLE_THREADS)
22   add_definitions(-DGTEST_HAS_PTHREAD=0)
23 endif()
24
25 set(LLVM_LINK_COMPONENTS
26   jit
27   interpreter
28   nativecodegen
29   BitWriter
30   BitReader
31   AsmParser
32   Core
33   Support
34   )
35
36 set(LLVM_USED_LIBS
37   gtest
38   gtest_main
39   LLVMSupport # gtest needs it for raw_ostream.
40   )
41
42 add_llvm_unittest(ADT
43   ADT/APFloatTest.cpp
44   ADT/APIntTest.cpp
45   ADT/BitVectorTest.cpp
46   ADT/DAGDeltaAlgorithmTest.cpp
47   ADT/DeltaAlgorithmTest.cpp
48   ADT/DenseMapTest.cpp
49   ADT/DenseSetTest.cpp
50   ADT/FoldingSet.cpp
51   ADT/ilistTest.cpp
52   ADT/ImmutableSetTest.cpp
53   ADT/IntervalMapTest.cpp
54   ADT/SmallBitVectorTest.cpp
55   ADT/SmallStringTest.cpp
56   ADT/SmallVectorTest.cpp
57   ADT/SparseBitVectorTest.cpp
58   ADT/StringMapTest.cpp
59   ADT/StringRefTest.cpp
60   ADT/TripleTest.cpp
61   ADT/TwineTest.cpp
62  )
63
64 add_llvm_unittest(Analysis
65   Analysis/ScalarEvolutionTest.cpp
66   )
67
68 add_llvm_unittest(ExecutionEngine
69   ExecutionEngine/ExecutionEngineTest.cpp
70   )
71
72 set(JITTestsSources
73   ExecutionEngine/JIT/JITEventListenerTest.cpp
74   ExecutionEngine/JIT/JITMemoryManagerTest.cpp
75   ExecutionEngine/JIT/JITTest.cpp
76   ExecutionEngine/JIT/MultiJITTest.cpp
77   )
78
79 if(MSVC)
80   list(APPEND JITTestsSources ExecutionEngine/JIT/JITTests.def)
81 endif()
82
83 add_llvm_unittest(ExecutionEngine/JIT ${JITTestsSources})
84
85 if(MINGW)
86   set_property(TARGET JITTests PROPERTY LINK_FLAGS -Wl,--export-all-symbols)
87 endif()
88
89 add_llvm_unittest(Transforms/Utils
90   Transforms/Utils/Cloning.cpp
91   )
92
93 set(VMCoreSources
94   VMCore/ConstantsTest.cpp
95   VMCore/DerivedTypesTest.cpp
96   VMCore/InstructionsTest.cpp
97   VMCore/MetadataTest.cpp
98   VMCore/PassManagerTest.cpp
99   VMCore/ValueMapTest.cpp
100   VMCore/VerifierTest.cpp
101   )
102
103 # MSVC9 and 8 cannot compile ValueMapTest.cpp due to their bug.
104 # See issue#331418 in Visual Studio.
105 if(MSVC AND MSVC_VERSION LESS 1600)
106   list(REMOVE_ITEM VMCoreSources VMCore/ValueMapTest.cpp)
107 endif()
108
109 add_llvm_unittest(VMCore ${VMCoreSources})
110
111 set(LLVM_LINK_COMPONENTS
112   Support
113   Core
114   )
115
116 add_llvm_unittest(Support
117   Support/AllocatorTest.cpp
118   Support/Casting.cpp
119   Support/CommandLineTest.cpp
120   Support/ConstantRangeTest.cpp
121   Support/EndianTest.cpp
122   Support/LeakDetectorTest.cpp
123   Support/MathExtrasTest.cpp
124   Support/Path.cpp
125   Support/raw_ostream_test.cpp
126   Support/RegexTest.cpp
127   Support/SwapByteOrderTest.cpp
128   Support/TimeValue.cpp
129   Support/TypeBuilderTest.cpp
130   Support/ValueHandleTest.cpp
131   )