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")
5 set(dest "" PARENT_SCOPE)
6 set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXX_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}")
11 get_property(LIBCXX_CXX_FLAGS CACHE CMAKE_CXX_FLAGS PROPERTY VALUE)
12 string(REPLACE " " ";" LIBCXX_CXX_FLAGS "${LIBCXX_CXX_FLAGS}")
13 list(APPEND CLANG_COMMAND ${LIBCXX_CXX_FLAGS})
15 COMMAND ${CLANG_COMMAND}
16 RESULT_VARIABLE HAD_ERROR
17 OUTPUT_VARIABLE LIBRARY_FILE
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)
26 message(STATUS "Failed to find compiler-rt library")
30 function(find_compiler_rt_dir dest)
31 if (NOT DEFINED LIBCXX_COMPILE_FLAGS)
32 message(FATAL_ERROR "LIBCXX_COMPILE_FLAGS must be defined when using this function")
34 set(dest "" PARENT_SCOPE)
36 set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXX_COMPILE_FLAGS}
37 "-print-file-name=lib")
39 COMMAND ${CLANG_COMMAND}
40 RESULT_VARIABLE HAD_ERROR
41 OUTPUT_VARIABLE LIBRARY_DIR
43 string(STRIP "${LIBRARY_DIR}" LIBRARY_DIR)
44 file(TO_CMAKE_PATH "${LIBRARY_DIR}" LIBRARY_DIR)
45 set(LIBRARY_DIR "${LIBRARY_DIR}/darwin")
47 set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXX_COMPILE_FLAGS}
48 "--rtlib=compiler-rt" "--print-libgcc-file-name")
50 COMMAND ${CLANG_COMMAND}
51 RESULT_VARIABLE HAD_ERROR
52 OUTPUT_VARIABLE LIBRARY_FILE
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)
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)
62 message(STATUS "Failed to find compiler-rt directory")