diff options
author | Chris Bieneman <beanz@apple.com> | 2016-05-03 19:48:11 +0000 |
---|---|---|
committer | Chris Bieneman <beanz@apple.com> | 2016-05-03 19:48:11 +0000 |
commit | 4e4d4302a346a8619da1ea3ddf2f9fdc13f572b0 (patch) | |
tree | 2215369bb14f6832b24cc6b642d8f01ceeffe8f9 /cmake/Modules/BuiltinTests.cmake | |
parent | e3884fe1b5d4cd3fad6aa18bca82a57a2b1be492 (diff) |
[CMake] NFC. Add support for testing the compiler without testing the linker
Summary:
One of the big limitations we have in the compiler-rt build system today is that we cannot bootstrap building the builtins because you need a fully functional toolchain to pass CMake's tests.
This change adds support for compile only tests.
It is NFC because nothing is using the compile-only tests yet.
I believe this is the last separable part of D16653.
Reviewers: samsonov
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D19692
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@268427 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake/Modules/BuiltinTests.cmake')
-rw-r--r-- | cmake/Modules/BuiltinTests.cmake | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/cmake/Modules/BuiltinTests.cmake b/cmake/Modules/BuiltinTests.cmake new file mode 100644 index 000000000..fde5f7590 --- /dev/null +++ b/cmake/Modules/BuiltinTests.cmake @@ -0,0 +1,60 @@ + +# This function takes an OS and a list of architectures and identifies the +# subset of the architectures list that the installed toolchain can target. +function(try_compile_only output) + set(SIMPLE_C ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.c) + file(WRITE ${SIMPLE_C} "int foo(int x, int y) { return x + y; }\n") + string(REGEX MATCHALL "<[A-Za-z0-9_]*>" substitutions + ${CMAKE_C_COMPILE_OBJECT}) + string(REPLACE ";" " " extra_flags "${ARGN}") + + set(test_compile_command "${CMAKE_C_COMPILE_OBJECT}") + foreach(substitution ${substitutions}) + if(substitution STREQUAL "<CMAKE_C_COMPILER>") + string(REPLACE "<CMAKE_C_COMPILER>" + "${CMAKE_C_COMPILER}" test_compile_command ${test_compile_command}) + elseif(substitution STREQUAL "<OBJECT>") + string(REPLACE "<OBJECT>" + "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/test.o" + test_compile_command ${test_compile_command}) + elseif(substitution STREQUAL "<SOURCE>") + string(REPLACE "<SOURCE>" "${SIMPLE_C}" test_compile_command + ${test_compile_command}) + elseif(substitution STREQUAL "<FLAGS>") + string(REPLACE "<FLAGS>" "${CMAKE_C_FLAGS} ${extra_flags}" + test_compile_command ${test_compile_command}) + else() + string(REPLACE "${substitution}" "" test_compile_command + ${test_compile_command}) + endif() + endforeach() + + string(REPLACE " " ";" test_compile_command "${test_compile_command}") + + execute_process( + COMMAND ${test_compile_command} + RESULT_VARIABLE result + OUTPUT_VARIABLE TEST_OUTPUT + ERROR_VARIABLE TEST_ERROR + ) + if(result EQUAL 0) + set(${output} True PARENT_SCOPE) + else() + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Testing compiler for supporting " ${ARGN} ":\n" + "Command: ${test_compile_command}\n" + "${TEST_OUTPUT}\n${TEST_ERROR}\n${result}\n") + set(${output} False PARENT_SCOPE) + endif() +endfunction() + +function(builtin_check_c_compiler_flag flag output) + message(STATUS "Performing Test ${output}") + try_compile_only(result ${flag}) + set(${output} ${result} PARENT_SCOPE) + if(${result}) + message(STATUS "Performing Test ${output} - Success") + else() + message(STATUS "Performing Test ${output} - Failed") + endif() +endfunction() |