Chris Bieneman | 4e4d430 | 2016-05-03 19:48:11 +0000 | [diff] [blame^] | 1 | |
| 2 | # This function takes an OS and a list of architectures and identifies the |
| 3 | # subset of the architectures list that the installed toolchain can target. |
| 4 | function(try_compile_only output) |
| 5 | set(SIMPLE_C ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.c) |
| 6 | file(WRITE ${SIMPLE_C} "int foo(int x, int y) { return x + y; }\n") |
| 7 | string(REGEX MATCHALL "<[A-Za-z0-9_]*>" substitutions |
| 8 | ${CMAKE_C_COMPILE_OBJECT}) |
| 9 | string(REPLACE ";" " " extra_flags "${ARGN}") |
| 10 | |
| 11 | set(test_compile_command "${CMAKE_C_COMPILE_OBJECT}") |
| 12 | foreach(substitution ${substitutions}) |
| 13 | if(substitution STREQUAL "<CMAKE_C_COMPILER>") |
| 14 | string(REPLACE "<CMAKE_C_COMPILER>" |
| 15 | "${CMAKE_C_COMPILER}" test_compile_command ${test_compile_command}) |
| 16 | elseif(substitution STREQUAL "<OBJECT>") |
| 17 | string(REPLACE "<OBJECT>" |
| 18 | "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/test.o" |
| 19 | test_compile_command ${test_compile_command}) |
| 20 | elseif(substitution STREQUAL "<SOURCE>") |
| 21 | string(REPLACE "<SOURCE>" "${SIMPLE_C}" test_compile_command |
| 22 | ${test_compile_command}) |
| 23 | elseif(substitution STREQUAL "<FLAGS>") |
| 24 | string(REPLACE "<FLAGS>" "${CMAKE_C_FLAGS} ${extra_flags}" |
| 25 | test_compile_command ${test_compile_command}) |
| 26 | else() |
| 27 | string(REPLACE "${substitution}" "" test_compile_command |
| 28 | ${test_compile_command}) |
| 29 | endif() |
| 30 | endforeach() |
| 31 | |
| 32 | string(REPLACE " " ";" test_compile_command "${test_compile_command}") |
| 33 | |
| 34 | execute_process( |
| 35 | COMMAND ${test_compile_command} |
| 36 | RESULT_VARIABLE result |
| 37 | OUTPUT_VARIABLE TEST_OUTPUT |
| 38 | ERROR_VARIABLE TEST_ERROR |
| 39 | ) |
| 40 | if(result EQUAL 0) |
| 41 | set(${output} True PARENT_SCOPE) |
| 42 | else() |
| 43 | file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log |
| 44 | "Testing compiler for supporting " ${ARGN} ":\n" |
| 45 | "Command: ${test_compile_command}\n" |
| 46 | "${TEST_OUTPUT}\n${TEST_ERROR}\n${result}\n") |
| 47 | set(${output} False PARENT_SCOPE) |
| 48 | endif() |
| 49 | endfunction() |
| 50 | |
| 51 | function(builtin_check_c_compiler_flag flag output) |
| 52 | message(STATUS "Performing Test ${output}") |
| 53 | try_compile_only(result ${flag}) |
| 54 | set(${output} ${result} PARENT_SCOPE) |
| 55 | if(${result}) |
| 56 | message(STATUS "Performing Test ${output} - Success") |
| 57 | else() |
| 58 | message(STATUS "Performing Test ${output} - Failed") |
| 59 | endif() |
| 60 | endfunction() |