HandleCompilerRT.cmake 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. function(find_compiler_rt_library name dest)
  2. if (NOT DEFINED LIBUNWIND_COMPILE_FLAGS)
  3. message(FATAL_ERROR "LIBUNWIND_COMPILE_FLAGS must be defined when using this function")
  4. endif()
  5. set(dest "" PARENT_SCOPE)
  6. set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBUNWIND_COMPILE_FLAGS}
  7. "--rtlib=compiler-rt" "--print-libgcc-file-name")
  8. if (CMAKE_CXX_COMPILER_ID MATCHES Clang AND CMAKE_CXX_COMPILER_TARGET)
  9. list(APPEND CLANG_COMMAND "--target=${CMAKE_CXX_COMPILER_TARGET}")
  10. endif()
  11. get_property(LIBUNWIND_CXX_FLAGS CACHE CMAKE_CXX_FLAGS PROPERTY VALUE)
  12. string(REPLACE " " ";" LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}")
  13. list(APPEND CLANG_COMMAND ${LIBUNWIND_CXX_FLAGS})
  14. execute_process(
  15. COMMAND ${CLANG_COMMAND}
  16. RESULT_VARIABLE HAD_ERROR
  17. OUTPUT_VARIABLE LIBRARY_FILE
  18. )
  19. string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE)
  20. file(TO_CMAKE_PATH "${LIBRARY_FILE}" LIBRARY_FILE)
  21. string(REPLACE "builtins" "${name}" LIBRARY_FILE "${LIBRARY_FILE}")
  22. if (NOT HAD_ERROR AND EXISTS "${LIBRARY_FILE}")
  23. message(STATUS "Found compiler-rt library: ${LIBRARY_FILE}")
  24. set(${dest} "${LIBRARY_FILE}" PARENT_SCOPE)
  25. else()
  26. message(STATUS "Failed to find compiler-rt library")
  27. endif()
  28. endfunction()
  29. function(find_compiler_rt_dir dest)
  30. if (NOT DEFINED LIBUNWIND_COMPILE_FLAGS)
  31. message(FATAL_ERROR "LIBUNWIND_COMPILE_FLAGS must be defined when using this function")
  32. endif()
  33. set(dest "" PARENT_SCOPE)
  34. if (APPLE)
  35. set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBUNWIND_COMPILE_FLAGS}
  36. "-print-file-name=lib")
  37. execute_process(
  38. COMMAND ${CLANG_COMMAND}
  39. RESULT_VARIABLE HAD_ERROR
  40. OUTPUT_VARIABLE LIBRARY_DIR
  41. )
  42. string(STRIP "${LIBRARY_DIR}" LIBRARY_DIR)
  43. file(TO_CMAKE_PATH "${LIBRARY_DIR}" LIBRARY_DIR)
  44. set(LIBRARY_DIR "${LIBRARY_DIR}/darwin")
  45. else()
  46. set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBUNWIND_COMPILE_FLAGS}
  47. "--rtlib=compiler-rt" "--print-libgcc-file-name")
  48. execute_process(
  49. COMMAND ${CLANG_COMMAND}
  50. RESULT_VARIABLE HAD_ERROR
  51. OUTPUT_VARIABLE LIBRARY_FILE
  52. )
  53. string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE)
  54. file(TO_CMAKE_PATH "${LIBRARY_FILE}" LIBRARY_FILE)
  55. get_filename_component(LIBRARY_DIR "${LIBRARY_FILE}" DIRECTORY)
  56. endif()
  57. if (NOT HAD_ERROR AND EXISTS "${LIBRARY_DIR}")
  58. message(STATUS "Found compiler-rt directory: ${LIBRARY_DIR}")
  59. set(${dest} "${LIBRARY_DIR}" PARENT_SCOPE)
  60. else()
  61. message(STATUS "Failed to find compiler-rt directory")
  62. endif()
  63. endfunction()