[cfe-commits] [PATCH] Add CMake support to the clang unittests (issue4152043)
jyasskin at gmail.com
jyasskin at gmail.com
Wed Feb 9 11:36:29 PST 2011
Reviewers: cfe-commits_cs.uiuc.edu,
Message:
Initial patch at
http://codereview.appspot.com/download/issue4152043_1.diff
Description:
unittests/CMakeLists.txt is mostly a copy of llvm's
unittests/CMakeLists.txt, with some changes to adapt it to clang. I
don't know CMake well enough to know if some pieces can be factored out.
Please review this at http://codereview.appspot.com/4152043/
Affected files:
M CMakeLists.txt
M test/CMakeLists.txt
M test/Unit/lit.cfg
M test/Unit/lit.site.cfg.in
A unittests/CMakeLists.txt
Index: test/CMakeLists.txt
===================================================================
--- test/CMakeLists.txt (revision 125180)
+++ test/CMakeLists.txt (working copy)
@@ -26,6 +26,7 @@
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}/..")
@@ -70,7 +71,9 @@
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}/${testdir}
DEPENDS clang c-index-test FileCheck not count
@@ -81,7 +84,9 @@
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")
@@ -90,7 +95,9 @@
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_SOURCE_DIR}/../utils/C++Tests
DEPENDS clang c-index-test FileCheck not count
@@ -110,6 +117,7 @@
add_dependencies(clang-test clang-test.deps)
add_dependencies(clang-test.deps
+ ClangUnitTests
clang clang-headers c-index-test
llvm-dis opt
FileCheck count not)
Index: test/Unit/lit.cfg
===================================================================
--- test/Unit/lit.cfg (revision 125180)
+++ test/Unit/lit.cfg (working copy)
@@ -45,8 +45,8 @@
# 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
Index: test/Unit/lit.site.cfg.in
===================================================================
--- test/Unit/lit.site.cfg.in (revision 125180)
+++ test/Unit/lit.site.cfg.in (working copy)
@@ -11,11 +11,13 @@
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))
Index: unittests/CMakeLists.txt
===================================================================
--- unittests/CMakeLists.txt (revision 0)
+++ unittests/CMakeLists.txt (revision 0)
@@ -0,0 +1,57 @@
+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
+ jit
+ interpreter
+ nativecodegen
+ BitWriter
+ BitReader
+ AsmParser
+ Core
+ Support
+ )
+
+set(LLVM_USED_LIBS
+ gtest
+ gtest_main
+ LLVMSupport # gtest needs it for raw_ostream.
+ clangAST
+ clangFrontend
+ clangSerialization
+ )
+
+add_clang_unittest(Frontend
+ Frontend/FrontendActionTest.cpp
+ )
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt (revision 125180)
+++ CMakeLists.txt (working copy)
@@ -210,3 +210,4 @@
# TODO: docs.
add_subdirectory(test)
+add_subdirectory(unittests)
More information about the cfe-commits
mailing list