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) |
Oscar Fuentes | c5cd252 | 2011-05-11 13:53:30 +0000 | [diff] [blame] | 39 | if( LLVM_COMPILER_IS_GCC_COMPATIBLE ) |
Jeffrey Yasskin | 718b01d | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 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 |
Argyrios Kyrtzidis | d7711ec | 2011-12-21 16:56:29 +0000 | [diff] [blame] | 55 | Basic/SourceManagerTest.cpp |
| 56 | USED_LIBS gtest gtest_main clangLex |
Zhanyong Wan | c515d18 | 2011-02-16 05:45:20 +0000 | [diff] [blame] | 57 | ) |
| 58 | |
Jeffrey Yasskin | 718b01d | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 59 | add_clang_unittest(Frontend |
Jeffrey Yasskin | 718b01d | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 60 | Frontend/FrontendActionTest.cpp |
Jeffrey Yasskin | f91ae52 | 2011-02-19 18:06:01 +0000 | [diff] [blame] | 61 | USED_LIBS gtest gtest_main clangFrontend |
Jeffrey Yasskin | 718b01d | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 62 | ) |