summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Modules/CompilerRTCompile.cmake16
-rw-r--r--cmake/Modules/CompilerRTUnittests.cmake30
2 files changed, 46 insertions, 0 deletions
diff --git a/cmake/Modules/CompilerRTCompile.cmake b/cmake/Modules/CompilerRTCompile.cmake
new file mode 100644
index 000000000..2794cabe5
--- /dev/null
+++ b/cmake/Modules/CompilerRTCompile.cmake
@@ -0,0 +1,16 @@
+include(LLVMParseArguments)
+
+# Compile a source into an object file with just-built Clang using
+# a provided compile flags and dependenices.
+# clang_compile(<object> <source>
+# CFLAGS <list of compile flags>
+# DEPS <list of dependencies>)
+macro(clang_compile object_file source)
+ parse_arguments(SOURCE "CFLAGS;DEPS" "" ${ARGN})
+ get_filename_component(source_rpath ${source} REALPATH)
+ add_custom_command(
+ OUTPUT ${object_file}
+ COMMAND clang ${SOURCE_CFLAGS} -c -o "${object_file}" ${source_rpath}
+ MAIN_DEPENDENCY ${source}
+ DEPENDS clang ${SOURCE_DEPS})
+endmacro()
diff --git a/cmake/Modules/CompilerRTUnittests.cmake b/cmake/Modules/CompilerRTUnittests.cmake
new file mode 100644
index 000000000..96ad67310
--- /dev/null
+++ b/cmake/Modules/CompilerRTUnittests.cmake
@@ -0,0 +1,30 @@
+include(AddLLVM)
+include(LLVMParseArguments)
+
+set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest)
+set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/gtest-all.cc)
+set(COMPILER_RT_GTEST_INCLUDE_CFLAGS
+ -DGTEST_NO_LLVM_RAW_OSTREAM=1
+ -I${COMPILER_RT_GTEST_PATH}/include
+)
+
+# Use Clang to link objects into a single executable with just-built
+# Clang, using specific link flags. Make executable a part of provided
+# test_suite.
+# add_compiler_rt_test(<test_suite> <test_name>
+# OBJECTS <object files>
+# DEPS <deps (e.g. runtime libs)>
+# LINK_FLAGS <link flags>)
+macro(add_compiler_rt_test test_suite test_name)
+ parse_arguments(TEST "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN})
+ get_unittest_directory(OUTPUT_DIR)
+ set(output_bin "${OUTPUT_DIR}/${test_name}")
+ add_custom_command(
+ OUTPUT ${output_bin}
+ COMMAND clang ${TEST_OBJECTS} -o "${output_bin}"
+ ${TEST_LINK_FLAGS}
+ DEPENDS clang ${TEST_DEPS} ${TEST_OBJECTS})
+ add_custom_target(${test_name} DEPENDS ${output_bin})
+ # Make the test suite depend on the binary.
+ add_dependencies(${test_suite} ${test_name})
+endmacro()