Chandler Carruth | 8897331 | 2012-06-21 02:04:39 +0000 | [diff] [blame] | 1 | # add_clang_unittest(test_dirname file1.cpp file2.cpp) |
Jeffrey Yasskin | 39a5820 | 2011-02-19 18:06:01 +0000 | [diff] [blame] | 2 | # |
| 3 | # Will compile the list of files together and link against the clang |
Chandler Carruth | 8897331 | 2012-06-21 02:04:39 +0000 | [diff] [blame] | 4 | # Produces a binary named 'basename(test_dirname)'. |
| 5 | function(add_clang_unittest test_dirname) |
Jeffrey Yasskin | cd3858b | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 6 | string(REGEX MATCH "([^/]+)$" test_name ${test_dirname}) |
| 7 | if (CMAKE_BUILD_TYPE) |
| 8 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY |
| 9 | ${CLANG_BINARY_DIR}/unittests/${test_dirname}/${CMAKE_BUILD_TYPE}) |
| 10 | else() |
| 11 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY |
| 12 | ${CLANG_BINARY_DIR}/unittests/${test_dirname}) |
| 13 | endif() |
| 14 | if( NOT LLVM_BUILD_TESTS ) |
| 15 | set(EXCLUDE_FROM_ALL ON) |
| 16 | endif() |
Chandler Carruth | 8897331 | 2012-06-21 02:04:39 +0000 | [diff] [blame] | 17 | |
| 18 | add_clang_executable(${test_name} ${ARGN}) |
| 19 | target_link_libraries(${test_name} |
| 20 | gtest |
| 21 | gtest_main |
| 22 | LLVMSupport # gtest needs it for raw_ostream. |
| 23 | ) |
| 24 | |
| 25 | add_dependencies(ClangUnitTests ${test_name}) |
| 26 | set_target_properties(${test_name} PROPERTIES FOLDER "Clang tests") |
Jeffrey Yasskin | cd3858b | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 27 | endfunction() |
| 28 | |
| 29 | add_custom_target(ClangUnitTests) |
Oscar Fuentes | 15fe190 | 2011-02-20 22:06:44 +0000 | [diff] [blame] | 30 | set_target_properties(ClangUnitTests PROPERTIES FOLDER "Clang tests") |
Jeffrey Yasskin | cd3858b | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 31 | |
| 32 | include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include) |
Chandler Carruth | 4b3d2c8 | 2012-06-21 00:40:48 +0000 | [diff] [blame] | 33 | |
Jeffrey Yasskin | cd3858b | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 34 | add_definitions(-DGTEST_HAS_RTTI=0) |
Oscar Fuentes | cfc9efa | 2011-05-11 13:53:30 +0000 | [diff] [blame] | 35 | if( LLVM_COMPILER_IS_GCC_COMPATIBLE ) |
Jeffrey Yasskin | cd3858b | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 36 | llvm_replace_compiler_option(CMAKE_CXX_FLAGS "-frtti" "-fno-rtti") |
| 37 | elseif( MSVC ) |
| 38 | llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/GR" "/GR-") |
| 39 | endif() |
| 40 | |
| 41 | if (NOT LLVM_ENABLE_THREADS) |
| 42 | add_definitions(-DGTEST_HAS_PTHREAD=0) |
| 43 | endif() |
| 44 | |
| 45 | if(SUPPORTS_NO_VARIADIC_MACROS_FLAG) |
| 46 | add_definitions("-Wno-variadic-macros") |
| 47 | endif() |
| 48 | |
Chandler Carruth | 8897331 | 2012-06-21 02:04:39 +0000 | [diff] [blame] | 49 | add_clang_unittest(BasicTests |
Zhanyong Wan | 5201b66 | 2011-02-16 05:45:20 +0000 | [diff] [blame] | 50 | Basic/FileManagerTest.cpp |
Argyrios Kyrtzidis | 2403797 | 2011-12-21 16:56:29 +0000 | [diff] [blame] | 51 | Basic/SourceManagerTest.cpp |
Chandler Carruth | 8897331 | 2012-06-21 02:04:39 +0000 | [diff] [blame] | 52 | ) |
| 53 | target_link_libraries(BasicTests |
| 54 | clangLex |
| 55 | ) |
Zhanyong Wan | 5201b66 | 2011-02-16 05:45:20 +0000 | [diff] [blame] | 56 | |
Chandler Carruth | 8897331 | 2012-06-21 02:04:39 +0000 | [diff] [blame] | 57 | add_clang_unittest(LexTests |
Argyrios Kyrtzidis | d169911 | 2012-01-19 15:59:01 +0000 | [diff] [blame] | 58 | Lex/LexerTest.cpp |
Chandler Carruth | 8897331 | 2012-06-21 02:04:39 +0000 | [diff] [blame] | 59 | ) |
| 60 | target_link_libraries(LexTests |
| 61 | clangLex |
| 62 | ) |
Argyrios Kyrtzidis | d169911 | 2012-01-19 15:59:01 +0000 | [diff] [blame] | 63 | |
Chandler Carruth | 8897331 | 2012-06-21 02:04:39 +0000 | [diff] [blame] | 64 | add_clang_unittest(FrontendTests |
Jeffrey Yasskin | cd3858b | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 65 | Frontend/FrontendActionTest.cpp |
Chandler Carruth | 8897331 | 2012-06-21 02:04:39 +0000 | [diff] [blame] | 66 | ) |
| 67 | target_link_libraries(FrontendTests |
| 68 | clangFrontend |
| 69 | ) |
Manuel Klimek | 47c245a | 2012-04-04 12:07:46 +0000 | [diff] [blame] | 70 | |
Chandler Carruth | 8897331 | 2012-06-21 02:04:39 +0000 | [diff] [blame] | 71 | add_clang_unittest(ToolingTests |
Manuel Klimek | 47c245a | 2012-04-04 12:07:46 +0000 | [diff] [blame] | 72 | Tooling/CompilationDatabaseTest.cpp |
| 73 | Tooling/ToolingTest.cpp |
Manuel Klimek | 770691b | 2012-04-19 08:48:53 +0000 | [diff] [blame] | 74 | Tooling/RecursiveASTVisitorTest.cpp |
Manuel Klimek | 3f00134 | 2012-05-23 16:29:20 +0000 | [diff] [blame] | 75 | Tooling/RefactoringTest.cpp |
Manuel Klimek | 78d084d | 2012-05-22 17:01:35 +0000 | [diff] [blame] | 76 | Tooling/RewriterTest.cpp |
Chandler Carruth | 8897331 | 2012-06-21 02:04:39 +0000 | [diff] [blame] | 77 | ) |
| 78 | target_link_libraries(ToolingTests |
| 79 | clangAST |
| 80 | clangTooling |
| 81 | clangRewrite |
| 82 | ) |