[cfe-commits] r125561 - in /cfe/trunk: CMakeLists.txt test/CMakeLists.txt test/Unit/lit.cfg test/Unit/lit.site.cfg.in unittests/CMakeLists.txt

Jeffrey Yasskin jyasskin at google.com
Mon Feb 14 23:54:28 PST 2011


Author: jyasskin
Date: Tue Feb 15 01:54:28 2011
New Revision: 125561

URL: http://llvm.org/viewvc/llvm-project?rev=125561&view=rev
Log:
Add CMake support to the clang unittests.

Added:
    cfe/trunk/unittests/CMakeLists.txt
Modified:
    cfe/trunk/CMakeLists.txt
    cfe/trunk/test/CMakeLists.txt
    cfe/trunk/test/Unit/lit.cfg
    cfe/trunk/test/Unit/lit.site.cfg.in

Modified: cfe/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=125561&r1=125560&r2=125561&view=diff
==============================================================================
--- cfe/trunk/CMakeLists.txt (original)
+++ cfe/trunk/CMakeLists.txt Tue Feb 15 01:54:28 2011
@@ -53,6 +53,8 @@
 
   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 @@
 
 # TODO: docs.
 add_subdirectory(test)
+
+# FIXME: unittests require gtest.
+if( NOT CLANG_BUILT_STANDALONE )
+  add_subdirectory(unittests)
+endif()

Modified: cfe/trunk/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CMakeLists.txt?rev=125561&r1=125560&r2=125561&view=diff
==============================================================================
--- cfe/trunk/test/CMakeLists.txt (original)
+++ cfe/trunk/test/CMakeLists.txt Tue Feb 15 01:54:28 2011
@@ -27,6 +27,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}/..")
@@ -66,6 +67,8 @@
   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 @@
     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 @@
                 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 @@
                 ${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 @@
                  llvm-dis opt
                  FileCheck count not)
 
-  add_dependencies(check-all check.deps clang-test.deps)
-
 endif()

Modified: cfe/trunk/test/Unit/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Unit/lit.cfg?rev=125561&r1=125560&r2=125561&view=diff
==============================================================================
--- cfe/trunk/test/Unit/lit.cfg (original)
+++ cfe/trunk/test/Unit/lit.cfg Tue Feb 15 01:54:28 2011
@@ -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

Modified: cfe/trunk/test/Unit/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Unit/lit.site.cfg.in?rev=125561&r1=125560&r2=125561&view=diff
==============================================================================
--- cfe/trunk/test/Unit/lit.site.cfg.in (original)
+++ cfe/trunk/test/Unit/lit.site.cfg.in Tue Feb 15 01:54:28 2011
@@ -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))

Added: cfe/trunk/unittests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/CMakeLists.txt?rev=125561&view=auto
==============================================================================
--- cfe/trunk/unittests/CMakeLists.txt (added)
+++ cfe/trunk/unittests/CMakeLists.txt Tue Feb 15 01:54:28 2011
@@ -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
+ )





More information about the cfe-commits mailing list