[compiler-rt] r201672 - [CMake] Use host compiler to build unittests in standalone mode

Alexey Samsonov samsonov at google.com
Wed Feb 19 05:01:03 PST 2014


Author: samsonov
Date: Wed Feb 19 07:01:03 2014
New Revision: 201672

URL: http://llvm.org/viewvc/llvm-project?rev=201672&view=rev
Log:
[CMake] Use host compiler to build unittests in standalone mode

Modified:
    compiler-rt/trunk/CMakeLists.txt
    compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
    compiler-rt/trunk/cmake/Modules/CompilerRTCompile.cmake
    compiler-rt/trunk/cmake/Modules/CompilerRTLink.cmake

Modified: compiler-rt/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/CMakeLists.txt?rev=201672&r1=201671&r2=201672&view=diff
==============================================================================
--- compiler-rt/trunk/CMakeLists.txt (original)
+++ compiler-rt/trunk/CMakeLists.txt Wed Feb 19 07:01:03 2014
@@ -40,6 +40,9 @@ if (NOT COMPILER_RT_STANDALONE_BUILD)
   set(COMPILER_RT_INSTALL_PATH lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION})
   option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests."
          ${LLVM_INCLUDE_TESTS})
+  # Use just-built Clang to compile/link tests.
+  # FIXME: Use an absolute path instead.
+  set(COMPILER_RT_TEST_COMPILER clang)
 else()
   # Take output dir and install path from the user.
   set(COMPILER_RT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH
@@ -47,6 +50,8 @@ else()
   set(COMPILER_RT_INSTALL_PATH ${CMAKE_INSTALL_PREFIX} CACHE PATH
     "Path where built compiler-rt libraries should be installed.")
   option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests." OFF)
+  # Use a host compiler to compile/link tests.
+  set(COMPILER_RT_TEST_COMPILER ${CMAKE_CXX_COMPILER})
 
   set(LLVM_CONFIG_PATH "" CACHE PATH "Path to llvm-config binary")
   if (NOT LLVM_CONFIG_PATH)

Modified: compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake?rev=201672&r1=201671&r2=201672&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake (original)
+++ compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake Wed Feb 19 07:01:03 2014
@@ -113,8 +113,8 @@ set(COMPILER_RT_GTEST_INCLUDE_CFLAGS
   -I${COMPILER_RT_GTEST_PATH}
 )
 
-# Use Clang to link objects into a single executable with just-built
-# Clang, using specific link flags. Make executable a part of provided
+# Link objects into a single executable with COMPILER_RT_TEST_COMPILER,
+# using specified link flags. Make executable a part of provided
 # test_suite.
 # add_compiler_rt_test(<test_suite> <test_name>
 #                      OBJECTS <object files>
@@ -123,10 +123,14 @@ set(COMPILER_RT_GTEST_INCLUDE_CFLAGS
 macro(add_compiler_rt_test test_suite test_name)
   parse_arguments(TEST "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN})
   set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${test_name}")
+  # Use host compiler in a standalone build, and just-built Clang otherwise.
+  if(NOT COMPILER_RT_STANDALONE_BUILD)
+    list(APPEND TEST_DEPS clang)
+  endif()
   add_custom_target(${test_name}
-    COMMAND clang ${TEST_OBJECTS} -o "${output_bin}"
+    COMMAND ${COMPILER_RT_TEST_COMPILER} ${TEST_OBJECTS} -o "${output_bin}"
             ${TEST_LINK_FLAGS}
-    DEPENDS clang ${TEST_DEPS})
+    DEPENDS ${TEST_DEPS})
   # Make the test suite depend on the binary.
   add_dependencies(${test_suite} ${test_name})
 endmacro()

Modified: compiler-rt/trunk/cmake/Modules/CompilerRTCompile.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/CompilerRTCompile.cmake?rev=201672&r1=201671&r2=201672&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/Modules/CompilerRTCompile.cmake (original)
+++ compiler-rt/trunk/cmake/Modules/CompilerRTCompile.cmake Wed Feb 19 07:01:03 2014
@@ -1,6 +1,6 @@
 include(LLVMParseArguments)
 
-# Compile a source into an object file with just-built Clang using
+# Compile a source into an object file with COMPILER_RT_TEST_COMPILER using
 # a provided compile flags and dependenices.
 # clang_compile(<object> <source>
 #               CFLAGS <list of compile flags>
@@ -8,9 +8,13 @@ include(LLVMParseArguments)
 macro(clang_compile object_file source)
   parse_arguments(SOURCE "CFLAGS;DEPS" "" ${ARGN})
   get_filename_component(source_rpath ${source} REALPATH)
+  if(NOT COMPILER_RT_STANDALONE_BUILD)
+    list(APPEND SOURCE_DEPS clang)
+  endif()
   add_custom_command(
     OUTPUT ${object_file}
-    COMMAND clang ${SOURCE_CFLAGS} -c -o "${object_file}" ${source_rpath}
+    COMMAND ${COMPILER_RT_TEST_COMPILER} ${SOURCE_CFLAGS} -c -o "${object_file}"
+            ${source_rpath}
     MAIN_DEPENDENCY ${source}
-    DEPENDS clang ${SOURCE_DEPS})
+    DEPENDS ${SOURCE_DEPS})
 endmacro()

Modified: compiler-rt/trunk/cmake/Modules/CompilerRTLink.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/CompilerRTLink.cmake?rev=201672&r1=201671&r2=201672&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/Modules/CompilerRTLink.cmake (original)
+++ compiler-rt/trunk/cmake/Modules/CompilerRTLink.cmake Wed Feb 19 07:01:03 2014
@@ -1,14 +1,18 @@
 include(LLVMParseArguments)
 
-# Link a shared library with just-built Clang.
+# Link a shared library with COMPILER_RT_TEST_COMPILER.
 # clang_link_shared(<output.so>
 #                   OBJECTS <list of input objects>
 #                   LINKFLAGS <list of link flags>
 #                   DEPS <list of dependencies>)
 macro(clang_link_shared so_file)
   parse_arguments(SOURCE "OBJECTS;LINKFLAGS;DEPS" "" ${ARGN})
+  if(NOT COMPILER_RT_STANDALONE_BUILD)
+    list(APPEND SOURCE_DEPS clang)
+  endif()
   add_custom_command(
     OUTPUT ${so_file}
-    COMMAND clang -o "${so_file}" -shared ${SOURCE_LINKFLAGS} ${SOURCE_OBJECTS}
-    DEPENDS clang ${SOURCE_DEPS})
+    COMMAND ${COMPILER_RT_TEST_COMPILER} -o "${so_file}" -shared
+            ${SOURCE_LINKFLAGS} ${SOURCE_OBJECTS}
+    DEPENDS ${SOURCE_DEPS})
 endmacro()





More information about the llvm-commits mailing list