1include(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'. 11function(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 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() 29 add_clang_executable(${test_name}Tests ${CLANG_UNITTEST_DEFAULT_ARGS}) 30 add_dependencies(ClangUnitTests ${test_name}Tests) 31 set_target_properties(${test_name}Tests PROPERTIES FOLDER "Clang tests") 32endfunction() 33 34add_custom_target(ClangUnitTests) 35set_target_properties(ClangUnitTests PROPERTIES FOLDER "Clang tests") 36 37include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include) 38add_definitions(-DGTEST_HAS_RTTI=0) 39if( LLVM_COMPILER_IS_GCC_COMPATIBLE ) 40 llvm_replace_compiler_option(CMAKE_CXX_FLAGS "-frtti" "-fno-rtti") 41elseif( MSVC ) 42 llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/GR" "/GR-") 43endif() 44 45if (NOT LLVM_ENABLE_THREADS) 46 add_definitions(-DGTEST_HAS_PTHREAD=0) 47endif() 48 49if(SUPPORTS_NO_VARIADIC_MACROS_FLAG) 50 add_definitions("-Wno-variadic-macros") 51endif() 52 53add_clang_unittest(AST 54 AST/APValueTest.cpp 55 USED_LIBS gtest gtest_main clangAST 56 ) 57 58add_clang_unittest(Basic 59 Basic/FileManagerTest.cpp 60 USED_LIBS gtest gtest_main clangBasic 61 ) 62 63add_clang_unittest(Frontend 64 Frontend/FrontendActionTest.cpp 65 USED_LIBS gtest gtest_main clangFrontend 66 ) 67