Completely refactor the structuring of unittest CMake files to match the
authorChandler Carruth <chandlerc@gmail.com>
Thu, 21 Jun 2012 09:51:26 +0000 (09:51 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Thu, 21 Jun 2012 09:51:26 +0000 (09:51 +0000)
Makefiles, the CMake files in every other part of the LLVM tree, and
sanity.

This should also restore the output tree structure of all the unit
tests, sorry for breaking that, and thanks for letting me know.

The fundamental change is to put a CMakeLists.txt file in the unittest
directory, with a single test binary produced from it. This has several
advantages:

- No more weird directory stripping in the unittest macro, allowing it
  to be used more readily in other projects.
- No more directory prefixes on all the source files.
- Allows correct and precise use of LLVM's per-directory dependency
  system.
- Allows use of the checking logic for source files that have not been
  added to the CMake build. This uncovered a file being skipped with
  CMake in LLVM and one in Clang's unit tests.
- Makes Specifying conditional compilation or other custom logic for JIT
  tests easier.

It did require adding the concept of an explicit 'optional' source file
to the CMake build so that the missing-file check can skip cases where
the file is *supposed* to be missing. =]

This is another chunk of refactoring the CMake build in order to make it
usable for other clients like CompilerRT / ASan / TSan.

Note that this is interdependent with a Clang CMake change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158909 91177308-0d34-0410-b5e6-96231b3b80d8

12 files changed:
cmake/modules/AddLLVM.cmake
cmake/modules/LLVMProcessSources.cmake
unittests/ADT/CMakeLists.txt [new file with mode: 0644]
unittests/Analysis/CMakeLists.txt [new file with mode: 0644]
unittests/Bitcode/CMakeLists.txt [new file with mode: 0644]
unittests/CMakeLists.txt
unittests/ExecutionEngine/CMakeLists.txt [new file with mode: 0644]
unittests/ExecutionEngine/JIT/CMakeLists.txt [new file with mode: 0644]
unittests/Support/CMakeLists.txt [new file with mode: 0644]
unittests/Transforms/CMakeLists.txt [new file with mode: 0644]
unittests/Transforms/Utils/CMakeLists.txt [new file with mode: 0644]
unittests/VMCore/CMakeLists.txt [new file with mode: 0644]

index f32a6d3c871585bf83f417f2649e5425c6521e1f..96246fafe4a1bbc521ef16bb515a329a2ddba936 100755 (executable)
@@ -149,14 +149,12 @@ macro(add_llvm_external_project name)
 endmacro(add_llvm_external_project)
 
 # Generic support for adding a unittest.
-function(add_unittest test_suite test_dirname)
-  string(REGEX MATCH "([^/]+)$" test_name ${test_dirname})
+function(add_unittest test_suite test_name)
   if (CMAKE_BUILD_TYPE)
     set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
-      ${CMAKE_CURRENT_BINARY_DIR}/${test_dirname}/${CMAKE_BUILD_TYPE})
+      ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
   else()
-    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
-      ${CMAKE_CURRENT_BINARY_DIR}/${test_dirname})
+    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
   endif()
   if( NOT LLVM_BUILD_TESTS )
     set(EXCLUDE_FROM_ALL ON)
index 641f1b33e1dc1f427075a3ced9db26d91994ec78..bb11e9cad6c02d29e1ff902982080df2e3ac8071 100644 (file)
@@ -81,10 +81,13 @@ function(llvm_check_source_file_list)
   file(GLOB globbed *.cpp)
   foreach(g ${globbed})
     get_filename_component(fn ${g} NAME)
-    list(FIND listed ${fn} idx)
+    list(FIND LLVM_OPTIONAL_SOURCES ${fn} idx)
     if( idx LESS 0 )
-      message(SEND_ERROR "Found unknown source file ${g}
+      list(FIND listed ${fn} idx)
+      if( idx LESS 0 )
+        message(SEND_ERROR "Found unknown source file ${g}
 Please update ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt\n")
+      endif()
     endif()
   endforeach()
 endfunction(llvm_check_source_file_list)
diff --git a/unittests/ADT/CMakeLists.txt b/unittests/ADT/CMakeLists.txt
new file mode 100644 (file)
index 0000000..690ff78
--- /dev/null
@@ -0,0 +1,32 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
+add_llvm_unittest(ADTTests
+  APFloatTest.cpp
+  APIntTest.cpp
+  BitVectorTest.cpp
+  DAGDeltaAlgorithmTest.cpp
+  DeltaAlgorithmTest.cpp
+  DenseMapTest.cpp
+  DenseSetTest.cpp
+  FoldingSet.cpp
+  HashingTest.cpp
+  ilistTest.cpp
+  ImmutableSetTest.cpp
+  IntEqClassesTest.cpp
+  IntervalMapTest.cpp
+  IntrusiveRefCntPtrTest.cpp
+  PackedVectorTest.cpp
+  SCCIteratorTest.cpp
+  SmallPtrSetTest.cpp
+  SmallStringTest.cpp
+  SmallVectorTest.cpp
+  SparseBitVectorTest.cpp
+  SparseSetTest.cpp
+  StringMapTest.cpp
+  StringRefTest.cpp
+  TripleTest.cpp
+  TwineTest.cpp
+  VariadicFunctionTest.cpp
+ )
diff --git a/unittests/Analysis/CMakeLists.txt b/unittests/Analysis/CMakeLists.txt
new file mode 100644 (file)
index 0000000..7991a41
--- /dev/null
@@ -0,0 +1,7 @@
+set(LLVM_LINK_COMPONENTS
+  Analysis
+  )
+
+add_llvm_unittest(AnalysisTests
+  ScalarEvolutionTest.cpp
+  )
diff --git a/unittests/Bitcode/CMakeLists.txt b/unittests/Bitcode/CMakeLists.txt
new file mode 100644 (file)
index 0000000..d8f5fe1
--- /dev/null
@@ -0,0 +1,8 @@
+set(LLVM_LINK_COMPONENTS
+  BitReader
+  BitWriter
+  )
+
+add_llvm_unittest(BitcodeTests
+  BitReaderTest.cpp
+  )
index 00fd79687cddec13e5c075644e0ece440bda5b8e..84bd44439ee3dc1b1c5f3936d2ad97df882bf007 100644 (file)
@@ -5,151 +5,10 @@ function(add_llvm_unittest test_dirname)
   add_unittest(UnitTests ${test_dirname} ${ARGN})
 endfunction()
 
-set(LLVM_LINK_COMPONENTS
-  jit
-  interpreter
-  nativecodegen
-  BitWriter
-  BitReader
-  AsmParser
-  Core
-  Support
-  )
-
-add_llvm_unittest(ADTTests
-  ADT/APFloatTest.cpp
-  ADT/APIntTest.cpp
-  ADT/BitVectorTest.cpp
-  ADT/DAGDeltaAlgorithmTest.cpp
-  ADT/DeltaAlgorithmTest.cpp
-  ADT/DenseMapTest.cpp
-  ADT/DenseSetTest.cpp
-  ADT/FoldingSet.cpp
-  ADT/HashingTest.cpp
-  ADT/ilistTest.cpp
-  ADT/ImmutableSetTest.cpp
-  ADT/IntEqClassesTest.cpp
-  ADT/IntervalMapTest.cpp
-  ADT/IntrusiveRefCntPtrTest.cpp
-  ADT/PackedVectorTest.cpp
-  ADT/SCCIteratorTest.cpp
-  ADT/SmallPtrSetTest.cpp
-  ADT/SmallStringTest.cpp
-  ADT/SmallVectorTest.cpp
-  ADT/SparseBitVectorTest.cpp
-  ADT/SparseSetTest.cpp
-  ADT/StringMapTest.cpp
-  ADT/StringRefTest.cpp
-  ADT/TripleTest.cpp
-  ADT/TwineTest.cpp
-  ADT/VariadicFunctionTest.cpp
- )
-
-add_llvm_unittest(AnalysisTests
-  Analysis/ScalarEvolutionTest.cpp
-  )
-
-add_llvm_unittest(ExecutionEngineTests
-  ExecutionEngine/ExecutionEngineTest.cpp
-  )
-
-if( LLVM_USE_INTEL_JITEVENTS )
-  include_directories( ${LLVM_INTEL_JITEVENTS_INCDIR} )
-  link_directories( ${LLVM_INTEL_JITEVENTS_LIBDIR} )
-  set(ProfileTestSources
-    ExecutionEngine/JIT/IntelJITEventListenerTest.cpp
-    )
-  set(LLVM_LINK_COMPONENTS
-    ${LLVM_LINK_COMPONENTS}
-    IntelJITEvents
-    ) 
-endif( LLVM_USE_INTEL_JITEVENTS )
-
-if( LLVM_USE_OPROFILE )
-  set(ProfileTestSources
-    ${ProfileTestSources}
-    ExecutionEngine/JIT/OProfileJITEventListenerTest.cpp
-    )
-  set(LLVM_LINK_COMPONENTS
-    ${LLVM_LINK_COMPONENTS}
-    OProfileJIT
-    )
-endif( LLVM_USE_OPROFILE )
-
-set(JITTestsSources
-  ExecutionEngine/JIT/JITEventListenerTest.cpp
-  ExecutionEngine/JIT/JITMemoryManagerTest.cpp
-  ExecutionEngine/JIT/JITTest.cpp
-  ExecutionEngine/JIT/MultiJITTest.cpp
-  ${ProfileTestSources}
-  )
-
-if(MSVC)
-  list(APPEND JITTestsSources ExecutionEngine/JIT/JITTests.def)
-endif()
-
-add_llvm_unittest(ExecutionEngine/JITTests
-  ${JITTestsSources}
-  )
-
-if(MINGW OR CYGWIN)
-  set_property(TARGET JITTests PROPERTY LINK_FLAGS -Wl,--export-all-symbols)
-endif()
-
-add_llvm_unittest(Transforms/UtilsTests
-  Transforms/Utils/Cloning.cpp
-  )
-
-set(VMCoreSources
-  VMCore/ConstantsTest.cpp
-  VMCore/DominatorTreeTest.cpp
-  VMCore/InstructionsTest.cpp
-  VMCore/MetadataTest.cpp
-  VMCore/PassManagerTest.cpp
-  VMCore/ValueMapTest.cpp
-  VMCore/VerifierTest.cpp
-  )
-
-# MSVC9 and 8 cannot compile ValueMapTest.cpp due to their bug.
-# See issue#331418 in Visual Studio.
-if(MSVC AND MSVC_VERSION LESS 1600)
-  list(REMOVE_ITEM VMCoreSources VMCore/ValueMapTest.cpp)
-endif()
-
-add_llvm_unittest(VMCoreTests
-  ${VMCoreSources}
-  )
-
-add_llvm_unittest(BitcodeTests
-  Bitcode/BitReaderTest.cpp
-  )
-
-set(LLVM_LINK_COMPONENTS
-  Support
-  Core
-  )
-
-add_llvm_unittest(SupportTests
-  Support/AlignOfTest.cpp
-  Support/AllocatorTest.cpp
-  Support/BlockFrequencyTest.cpp
-  Support/Casting.cpp
-  Support/CommandLineTest.cpp
-  Support/ConstantRangeTest.cpp
-  Support/DataExtractorTest.cpp
-  Support/EndianTest.cpp
-  Support/IntegersSubsetTest.cpp
-  Support/IRBuilderTest.cpp
-  Support/LeakDetectorTest.cpp
-  Support/ManagedStatic.cpp
-  Support/MathExtrasTest.cpp
-  Support/MDBuilderTest.cpp
-  Support/Path.cpp
-  Support/raw_ostream_test.cpp
-  Support/RegexTest.cpp
-  Support/SwapByteOrderTest.cpp
-  Support/TimeValue.cpp
-  Support/TypeBuilderTest.cpp
-  Support/ValueHandleTest.cpp
-  Support/YAMLParserTest.cpp
-  )
+add_subdirectory(ADT)
+add_subdirectory(Analysis)
+add_subdirectory(ExecutionEngine)
+add_subdirectory(Bitcode)
+add_subdirectory(Support)
+add_subdirectory(Transforms)
+add_subdirectory(VMCore)
diff --git a/unittests/ExecutionEngine/CMakeLists.txt b/unittests/ExecutionEngine/CMakeLists.txt
new file mode 100644 (file)
index 0000000..5ca9904
--- /dev/null
@@ -0,0 +1,11 @@
+set(LLVM_LINK_COMPONENTS
+  jit
+  interpreter
+  nativecodegen
+  )
+
+add_llvm_unittest(ExecutionEngineTests
+  ExecutionEngineTest.cpp
+  )
+
+add_subdirectory(JIT)
diff --git a/unittests/ExecutionEngine/JIT/CMakeLists.txt b/unittests/ExecutionEngine/JIT/CMakeLists.txt
new file mode 100644 (file)
index 0000000..a9821a1
--- /dev/null
@@ -0,0 +1,55 @@
+set(LLVM_LINK_COMPONENTS
+  jit
+  interpreter
+  nativecodegen
+  )
+
+# HACK: Declare a couple of source files as optionally compiled to satisfy the
+# missing-file-checker in LLVM's weird CMake build.
+set(LLVM_OPTIONAL_SOURCES
+  IntelJITEventListenerTest.cpp
+  OProfileJITEventListenerTest.cpp
+  )
+
+if( LLVM_USE_INTEL_JITEVENTS )
+  include_directories( ${LLVM_INTEL_JITEVENTS_INCDIR} )
+  link_directories( ${LLVM_INTEL_JITEVENTS_LIBDIR} )
+  set(ProfileTestSources
+    IntelJITEventListenerTest.cpp
+    )
+  set(LLVM_LINK_COMPONENTS
+    ${LLVM_LINK_COMPONENTS}
+    IntelJITEvents
+    ) 
+endif( LLVM_USE_INTEL_JITEVENTS )
+
+if( LLVM_USE_OPROFILE )
+  set(ProfileTestSources
+    ${ProfileTestSources}
+    OProfileJITEventListenerTest.cpp
+    )
+  set(LLVM_LINK_COMPONENTS
+    ${LLVM_LINK_COMPONENTS}
+    OProfileJIT
+    )
+endif( LLVM_USE_OPROFILE )
+
+set(JITTestsSources
+  JITEventListenerTest.cpp
+  JITMemoryManagerTest.cpp
+  JITTest.cpp
+  MultiJITTest.cpp
+  ${ProfileTestSources}
+  )
+
+if(MSVC)
+  list(APPEND JITTestsSources JITTests.def)
+endif()
+
+add_llvm_unittest(ExecutionEngine/JITTests
+  ${JITTestsSources}
+  )
+
+if(MINGW OR CYGWIN)
+  set_property(TARGET JITTests PROPERTY LINK_FLAGS -Wl,--export-all-symbols)
+endif()
diff --git a/unittests/Support/CMakeLists.txt b/unittests/Support/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6053994
--- /dev/null
@@ -0,0 +1,29 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  Core
+  )
+
+add_llvm_unittest(SupportTests
+  AlignOfTest.cpp
+  AllocatorTest.cpp
+  BlockFrequencyTest.cpp
+  Casting.cpp
+  CommandLineTest.cpp
+  ConstantRangeTest.cpp
+  DataExtractorTest.cpp
+  EndianTest.cpp
+  IntegersSubsetTest.cpp
+  IRBuilderTest.cpp
+  LeakDetectorTest.cpp
+  ManagedStatic.cpp
+  MathExtrasTest.cpp
+  MDBuilderTest.cpp
+  Path.cpp
+  raw_ostream_test.cpp
+  RegexTest.cpp
+  SwapByteOrderTest.cpp
+  TimeValue.cpp
+  TypeBuilderTest.cpp
+  ValueHandleTest.cpp
+  YAMLParserTest.cpp
+  )
diff --git a/unittests/Transforms/CMakeLists.txt b/unittests/Transforms/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e3ce185
--- /dev/null
@@ -0,0 +1 @@
+add_subdirectory(Utils)
diff --git a/unittests/Transforms/Utils/CMakeLists.txt b/unittests/Transforms/Utils/CMakeLists.txt
new file mode 100644 (file)
index 0000000..365bfbb
--- /dev/null
@@ -0,0 +1,8 @@
+set(LLVM_LINK_COMPONENTS
+  TransformUtils
+  )
+
+add_llvm_unittest(UtilsTests
+  Cloning.cpp
+  Local.cpp
+  )
diff --git a/unittests/VMCore/CMakeLists.txt b/unittests/VMCore/CMakeLists.txt
new file mode 100644 (file)
index 0000000..04eabf0
--- /dev/null
@@ -0,0 +1,27 @@
+set(LLVM_LINK_COMPONENTS
+  asmparser
+  analysis
+  core
+  ipa
+  target
+  )
+
+set(VMCoreSources
+  ConstantsTest.cpp
+  DominatorTreeTest.cpp
+  InstructionsTest.cpp
+  MetadataTest.cpp
+  PassManagerTest.cpp
+  ValueMapTest.cpp
+  VerifierTest.cpp
+  )
+
+# MSVC9 and 8 cannot compile ValueMapTest.cpp due to their bug.
+# See issue#331418 in Visual Studio.
+if(MSVC AND MSVC_VERSION LESS 1600)
+  list(REMOVE_ITEM VMCoreSources ValueMapTest.cpp)
+endif()
+
+add_llvm_unittest(VMCoreTests
+  ${VMCoreSources}
+  )