зеркало из https://github.com/microsoft/clang.git
Add CMake support to the clang unittests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125561 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
26c05b11dc
Коммит
718b01d077
|
@ -53,6 +53,8 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
|
|||
|
||||
add_definitions( -D__STDC_LIMIT_MACROS )
|
||||
add_definitions( -D__STDC_CONSTANT_MACROS )
|
||||
|
||||
set( CLANG_BUILT_STANDALONE 1 )
|
||||
endif()
|
||||
|
||||
set(CLANG_RESOURCE_DIR "" CACHE STRING
|
||||
|
@ -214,3 +216,8 @@ add_subdirectory(runtime)
|
|||
|
||||
# TODO: docs.
|
||||
add_subdirectory(test)
|
||||
|
||||
# FIXME: unittests require gtest.
|
||||
if( NOT CLANG_BUILT_STANDALONE )
|
||||
add_subdirectory(unittests)
|
||||
endif()
|
||||
|
|
|
@ -27,6 +27,7 @@ set(CLANG_TEST_DIRECTORIES
|
|||
|
||||
set(LLVM_SOURCE_DIR "${LLVM_MAIN_SRC_DIR}")
|
||||
set(LLVM_BINARY_DIR "${LLVM_BINARY_DIR}")
|
||||
set(LLVM_BUILD_MODE "%(build_mode)s")
|
||||
set(LLVM_TOOLS_DIR "${LLVM_TOOLS_BINARY_DIR}/%(build_config)s")
|
||||
set(LLVM_LIBS_DIR "${LLVM_BINARY_DIR}/lib/%(build_config)s")
|
||||
set(CLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||
|
@ -66,6 +67,8 @@ if(PYTHONINTERP_FOUND)
|
|||
set(LIT_ARGS "${CLANG_TEST_EXTRA_ARGS} ${LLVM_LIT_ARGS}")
|
||||
separate_arguments(LIT_ARGS)
|
||||
|
||||
add_custom_target(clang-test.deps)
|
||||
|
||||
foreach(testdir ${CLANG_TEST_DIRECTORIES})
|
||||
add_custom_target(clang-test-${testdir}
|
||||
COMMAND ${PYTHON_EXECUTABLE}
|
||||
|
@ -82,7 +85,9 @@ if(PYTHONINTERP_FOUND)
|
|||
COMMAND ${PYTHON_EXECUTABLE}
|
||||
${LIT}
|
||||
--param clang_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
|
||||
--param clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg
|
||||
--param build_config=${CMAKE_CFG_INTDIR}
|
||||
--param build_mode=${RUNTIME_BUILD_MODE}
|
||||
${LIT_ARGS}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Running Clang regression tests")
|
||||
|
@ -97,8 +102,9 @@ if(PYTHONINTERP_FOUND)
|
|||
DEPENDS clang c-index-test FileCheck not count
|
||||
COMMENT "Running Clang regression tests")
|
||||
|
||||
add_custom_target(check-all
|
||||
COMMAND ${PYTHON_EXECUTABLE}
|
||||
if( NOT CLANG_BUILT_STANDALONE )
|
||||
add_custom_target(check-all
|
||||
COMMAND ${PYTHON_EXECUTABLE}
|
||||
${LIT}
|
||||
--param build_config=${CMAKE_CFG_INTDIR}
|
||||
--param build_mode=${RUNTIME_BUILD_MODE}
|
||||
|
@ -106,8 +112,9 @@ if(PYTHONINTERP_FOUND)
|
|||
${LLVM_BINARY_DIR}/test
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Running Clang and LLVM regression tests")
|
||||
|
||||
add_custom_target(clang-test.deps)
|
||||
add_dependencies(check-all check.deps clang-test.deps)
|
||||
add_dependencies(clang-test.deps ClangUnitTests)
|
||||
endif()
|
||||
|
||||
add_dependencies(clang-test clang-test.deps)
|
||||
add_dependencies(clang-test.deps
|
||||
|
@ -115,6 +122,4 @@ if(PYTHONINTERP_FOUND)
|
|||
llvm-dis opt
|
||||
FileCheck count not)
|
||||
|
||||
add_dependencies(check-all check.deps clang-test.deps)
|
||||
|
||||
endif()
|
||||
|
|
|
@ -45,8 +45,8 @@ if config.test_exec_root is None:
|
|||
# configuration hasn't been created by the build system, or we are in an
|
||||
# out-of-tree build situation).
|
||||
|
||||
# Check for 'clang_site_config' user parameter, and use that if available.
|
||||
site_cfg = lit.params.get('clang_site_config', None)
|
||||
# Check for 'clang_unit_site_config' user parameter, and use that if available.
|
||||
site_cfg = lit.params.get('clang_unit_site_config', None)
|
||||
if site_cfg and os.path.exists(site_cfg):
|
||||
lit.load_config(config, site_cfg)
|
||||
raise SystemExit
|
||||
|
|
|
@ -11,11 +11,13 @@ config.shlibdir = "@SHLIBDIR@"
|
|||
config.shlibpath_var = "@SHLIBPATH_VAR@"
|
||||
config.target_triple = "@TARGET_TRIPLE@"
|
||||
|
||||
# Support substitution of the tools and libs dirs with user parameters. This is
|
||||
# used when we can't determine the tool dir at configuration time.
|
||||
# Support substitution of the tools_dir, libs_dirs, and build_mode with user
|
||||
# parameters. This is used when we can't determine the tool dir at
|
||||
# configuration time.
|
||||
try:
|
||||
config.llvm_tools_dir = config.llvm_tools_dir % lit.params
|
||||
config.llvm_libs_dir = config.llvm_libs_dir % lit.params
|
||||
config.llvm_build_mode = config.llvm_build_mode % lit.params
|
||||
except KeyError,e:
|
||||
key, = e.args
|
||||
lit.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key))
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
function(add_clang_unittest test_dirname)
|
||||
string(REGEX MATCH "([^/]+)$" test_name ${test_dirname})
|
||||
if (CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
|
||||
${CLANG_BINARY_DIR}/unittests/${test_dirname}/${CMAKE_BUILD_TYPE})
|
||||
else()
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
|
||||
${CLANG_BINARY_DIR}/unittests/${test_dirname})
|
||||
endif()
|
||||
if( NOT LLVM_BUILD_TESTS )
|
||||
set(EXCLUDE_FROM_ALL ON)
|
||||
endif()
|
||||
add_clang_executable(${test_name}Tests ${ARGN})
|
||||
add_dependencies(ClangUnitTests ${test_name}Tests)
|
||||
endfunction()
|
||||
|
||||
add_custom_target(ClangUnitTests)
|
||||
|
||||
include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
|
||||
add_definitions(-DGTEST_HAS_RTTI=0)
|
||||
if( CMAKE_COMPILER_IS_GNUCXX )
|
||||
llvm_replace_compiler_option(CMAKE_CXX_FLAGS "-frtti" "-fno-rtti")
|
||||
elseif( MSVC )
|
||||
llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/GR" "/GR-")
|
||||
endif()
|
||||
|
||||
if (NOT LLVM_ENABLE_THREADS)
|
||||
add_definitions(-DGTEST_HAS_PTHREAD=0)
|
||||
endif()
|
||||
|
||||
if(SUPPORTS_NO_VARIADIC_MACROS_FLAG)
|
||||
add_definitions("-Wno-variadic-macros")
|
||||
endif()
|
||||
|
||||
set(LLVM_LINK_COMPONENTS
|
||||
Core
|
||||
)
|
||||
|
||||
set(LLVM_USED_LIBS
|
||||
gtest
|
||||
gtest_main
|
||||
clangFrontend
|
||||
)
|
||||
|
||||
add_clang_unittest(Frontend
|
||||
Frontend/FrontendActionTest.cpp
|
||||
)
|
Загрузка…
Ссылка в новой задаче