Jeffrey Yasskin | f91ae52 | 2011-02-19 18:06:01 +0000 | [diff] [blame] | 1 | include(LLVMParseArguments) |
| 2 | |
| 3 | # add_clang_unittest(test_dirname file1.cpp file2.cpp ... |
| 4 | # [USED_LIBS lib1 lib2] |
| 5 | # [LINK_COMPONENTS component1 component2]) |
| 6 | # |
| 7 | # Will compile the list of files together and link against the clang |
| 8 | # libraries in the USED_LIBS list and the llvm-config components in |
| 9 | # the LINK_COMPONENTS list. Produces a binary named |
| 10 | # 'basename(test_dirname)Tests'. |
| 11 | function(add_clang_unittest) |
| 12 | PARSE_ARGUMENTS(CLANG_UNITTEST "USED_LIBS;LINK_COMPONENTS" "" ${ARGN}) |
| 13 | set(LLVM_LINK_COMPONENTS ${CLANG_UNITTEST_LINK_COMPONENTS}) |
| 14 | set(LLVM_USED_LIBS ${CLANG_UNITTEST_USED_LIBS}) |
| 15 | list(GET CLANG_UNITTEST_DEFAULT_ARGS 0 test_dirname) |
| 16 | list(REMOVE_AT CLANG_UNITTEST_DEFAULT_ARGS 0) |
| 17 | |
Jeffrey Yasskin | 718b01d | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 18 | string(REGEX MATCH "([^/]+)$" test_name ${test_dirname}) |
| 19 | if (CMAKE_BUILD_TYPE) |
| 20 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY |
| 21 | ${CLANG_BINARY_DIR}/unittests/${test_dirname}/${CMAKE_BUILD_TYPE}) |
| 22 | else() |
| 23 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY |
| 24 | ${CLANG_BINARY_DIR}/unittests/${test_dirname}) |
| 25 | endif() |
| 26 | if( NOT LLVM_BUILD_TESTS ) |
| 27 | set(EXCLUDE_FROM_ALL ON) |
| 28 | endif() |
Jeffrey Yasskin | f91ae52 | 2011-02-19 18:06:01 +0000 | [diff] [blame] | 29 | add_clang_executable(${test_name}Tests ${CLANG_UNITTEST_DEFAULT_ARGS}) |
Jeffrey Yasskin | 718b01d | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 30 | add_dependencies(ClangUnitTests ${test_name}Tests) |
Oscar Fuentes | a3f787c | 2011-02-20 22:06:44 +0000 | [diff] [blame] | 31 | set_target_properties(${test_name}Tests PROPERTIES FOLDER "Clang tests") |
Jeffrey Yasskin | 718b01d | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 32 | endfunction() |
| 33 | |
| 34 | add_custom_target(ClangUnitTests) |
Oscar Fuentes | a3f787c | 2011-02-20 22:06:44 +0000 | [diff] [blame] | 35 | set_target_properties(ClangUnitTests PROPERTIES FOLDER "Clang tests") |
Jeffrey Yasskin | 718b01d | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 36 | |
| 37 | include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include) |
| 38 | add_definitions(-DGTEST_HAS_RTTI=0) |
| 39 | if( CMAKE_COMPILER_IS_GNUCXX ) |
| 40 | llvm_replace_compiler_option(CMAKE_CXX_FLAGS "-frtti" "-fno-rtti") |
| 41 | elseif( MSVC ) |
| 42 | llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/GR" "/GR-") |
| 43 | endif() |
| 44 | |
| 45 | if (NOT LLVM_ENABLE_THREADS) |
| 46 | add_definitions(-DGTEST_HAS_PTHREAD=0) |
| 47 | endif() |
| 48 | |
| 49 | if(SUPPORTS_NO_VARIADIC_MACROS_FLAG) |
| 50 | add_definitions("-Wno-variadic-macros") |
| 51 | endif() |
| 52 | |
Zhanyong Wan | c515d18 | 2011-02-16 05:45:20 +0000 | [diff] [blame] | 53 | add_clang_unittest(Basic |
Zhanyong Wan | c515d18 | 2011-02-16 05:45:20 +0000 | [diff] [blame] | 54 | Basic/FileManagerTest.cpp |
Jeffrey Yasskin | f91ae52 | 2011-02-19 18:06:01 +0000 | [diff] [blame] | 55 | USED_LIBS gtest gtest_main clangBasic |
Zhanyong Wan | c515d18 | 2011-02-16 05:45:20 +0000 | [diff] [blame] | 56 | ) |
| 57 | |
Jeffrey Yasskin | 718b01d | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 58 | add_clang_unittest(Frontend |
Jeffrey Yasskin | 718b01d | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 59 | Frontend/FrontendActionTest.cpp |
Jeffrey Yasskin | f91ae52 | 2011-02-19 18:06:01 +0000 | [diff] [blame] | 60 | USED_LIBS gtest gtest_main clangFrontend |
Jeffrey Yasskin | 718b01d | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 61 | ) |
Manuel Klimek | cf3ce5d | 2011-04-21 18:37:41 +0000 | [diff] [blame] | 62 | |
| 63 | add_clang_unittest(Tooling |
| 64 | Tooling/ToolingTest.cpp |
| 65 | USED_LIBS gtest gtest_main clangTooling |
| 66 | ) |
Manuel Klimek | 9a05fa9 | 2011-04-27 16:39:14 +0000 | [diff] [blame] | 67 | |
| 68 | add_clang_unittest(JsonCompileCommandLineDatabase |
| 69 | Tooling/JsonCompileCommandLineDatabaseTest.cpp |
| 70 | USED_LIBS gtest gtest_main clangTooling |
| 71 | ) |