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