Eric Fiselier | 58bd12a | 2017-03-11 03:24:18 +0000 | [diff] [blame] | 1 | function(find_compiler_rt_library name dest) |
| 2 | if (NOT DEFINED LIBCXX_COMPILE_FLAGS) |
| 3 | message(FATAL_ERROR "LIBCXX_COMPILE_FLAGS must be defined when using this function") |
| 4 | endif() |
| 5 | set(dest "" PARENT_SCOPE) |
| 6 | set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXX_COMPILE_FLAGS} |
| 7 | "--rtlib=compiler-rt" "--print-libgcc-file-name") |
| 8 | execute_process( |
| 9 | COMMAND ${CLANG_COMMAND} |
| 10 | RESULT_VARIABLE HAD_ERROR |
| 11 | OUTPUT_VARIABLE LIBRARY_FILE |
| 12 | ) |
| 13 | string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE) |
| 14 | string(REPLACE "builtins" "${name}" LIBRARY_FILE "${LIBRARY_FILE}") |
| 15 | if (NOT HAD_ERROR AND EXISTS "${LIBRARY_FILE}") |
| 16 | message(STATUS "Found compiler-rt library: ${LIBRARY_FILE}") |
| 17 | set(${dest} "${LIBRARY_FILE}" PARENT_SCOPE) |
| 18 | else() |
| 19 | message(STATUS "Failed to find compiler-rt library") |
| 20 | endif() |
| 21 | endfunction() |
| 22 | |
| 23 | function(find_compiler_rt_dir dest) |
| 24 | if (NOT DEFINED LIBCXX_COMPILE_FLAGS) |
| 25 | message(FATAL_ERROR "LIBCXX_COMPILE_FLAGS must be defined when using this function") |
| 26 | endif() |
| 27 | set(dest "" PARENT_SCOPE) |
| 28 | set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXX_COMPILE_FLAGS} |
| 29 | "--rtlib=compiler-rt" "--print-libgcc-file-name") |
| 30 | execute_process( |
| 31 | COMMAND ${CLANG_COMMAND} |
| 32 | RESULT_VARIABLE HAD_ERROR |
| 33 | OUTPUT_VARIABLE LIBRARY_FILE |
| 34 | ) |
| 35 | string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE) |
| 36 | get_filename_component(LIBRARY_DIR "${LIBRARY_FILE}" DIRECTORY) |
| 37 | if (NOT HAD_ERROR AND EXISTS "${LIBRARY_DIR}") |
| 38 | message(STATUS "Found compiler-rt directory: ${LIBRARY_DIR}") |
| 39 | set(${dest} "${LIBRARY_DIR}" PARENT_SCOPE) |
| 40 | else() |
| 41 | message(STATUS "Failed to find compiler-rt directory") |
| 42 | endif() |
| 43 | endfunction() |