Completely refactor the structuring of unittest CMake files to match the

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
This commit is contained in:
Chandler Carruth 2012-06-21 09:51:26 +00:00
parent 7060221ae2
commit 7c888eee47
12 changed files with 193 additions and 155 deletions

View File

@ -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)

View 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)

View File

@ -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
)

View File

@ -0,0 +1,7 @@
set(LLVM_LINK_COMPONENTS
Analysis
)
add_llvm_unittest(AnalysisTests
ScalarEvolutionTest.cpp
)

View File

@ -0,0 +1,8 @@
set(LLVM_LINK_COMPONENTS
BitReader
BitWriter
)
add_llvm_unittest(BitcodeTests
BitReaderTest.cpp
)

View 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)

View File

@ -0,0 +1,11 @@
set(LLVM_LINK_COMPONENTS
jit
interpreter
nativecodegen
)
add_llvm_unittest(ExecutionEngineTests
ExecutionEngineTest.cpp
)
add_subdirectory(JIT)

View File

@ -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()

View File

@ -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
)

View File

@ -0,0 +1 @@
add_subdirectory(Utils)

View File

@ -0,0 +1,8 @@
set(LLVM_LINK_COMPONENTS
TransformUtils
)
add_llvm_unittest(UtilsTests
Cloning.cpp
Local.cpp
)

View File

@ -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}
)