• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1function(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()
28endfunction()
29
30function(find_compiler_rt_dir dest)
31  if (NOT DEFINED LIBUNWIND_COMPILE_FLAGS)
32    message(FATAL_ERROR "LIBUNWIND_COMPILE_FLAGS must be defined when using this function")
33  endif()
34  set(dest "" PARENT_SCOPE)
35  if (APPLE)
36    set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBUNWIND_COMPILE_FLAGS}
37        "-print-file-name=lib")
38    execute_process(
39        COMMAND ${CLANG_COMMAND}
40        RESULT_VARIABLE HAD_ERROR
41        OUTPUT_VARIABLE LIBRARY_DIR
42    )
43    string(STRIP "${LIBRARY_DIR}" LIBRARY_DIR)
44    file(TO_CMAKE_PATH "${LIBRARY_DIR}" LIBRARY_DIR)
45    set(LIBRARY_DIR "${LIBRARY_DIR}/darwin")
46  else()
47    set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBUNWIND_COMPILE_FLAGS}
48        "--rtlib=compiler-rt" "--print-libgcc-file-name")
49    execute_process(
50        COMMAND ${CLANG_COMMAND}
51        RESULT_VARIABLE HAD_ERROR
52        OUTPUT_VARIABLE LIBRARY_FILE
53    )
54    string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE)
55    file(TO_CMAKE_PATH "${LIBRARY_FILE}" LIBRARY_FILE)
56    get_filename_component(LIBRARY_DIR "${LIBRARY_FILE}" DIRECTORY)
57  endif()
58  if (NOT HAD_ERROR AND EXISTS "${LIBRARY_DIR}")
59    message(STATUS "Found compiler-rt directory: ${LIBRARY_DIR}")
60    set(${dest} "${LIBRARY_DIR}" PARENT_SCOPE)
61  else()
62    message(STATUS "Failed to find compiler-rt directory")
63  endif()
64endfunction()
65