1 function(find_compiler_rt_library name dest) 2 if (NOT DEFINED LIBCXXABI_COMPILE_FLAGS) 3 message(FATAL_ERROR "LIBCXXABI_COMPILE_FLAGS must be defined when using this function") 4 endif() 5 set(dest "" PARENT_SCOPE) 6 set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXXABI_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 execute_process( 12 COMMAND ${CLANG_COMMAND} 13 RESULT_VARIABLE HAD_ERROR 14 OUTPUT_VARIABLE LIBRARY_FILE 15 ) 16 string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE) 17 string(REPLACE "builtins" "${name}" LIBRARY_FILE "${LIBRARY_FILE}") 18 if (NOT HAD_ERROR AND EXISTS "${LIBRARY_FILE}") 19 message(STATUS "Found compiler-rt library: ${LIBRARY_FILE}") 20 set(${dest} "${LIBRARY_FILE}" PARENT_SCOPE) 21 else() 22 message(STATUS "Failed to find compiler-rt library") 23 endif() 24 endfunction() 25 26 function(find_compiler_rt_dir dest) 27 if (NOT DEFINED LIBCXXABI_COMPILE_FLAGS) 28 message(FATAL_ERROR "LIBCXXABI_COMPILE_FLAGS must be defined when using this function") 29 endif() 30 set(dest "" PARENT_SCOPE) 31 if (APPLE) 32 set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXXABI_COMPILE_FLAGS} 33 "-print-file-name=lib") 34 execute_process( 35 COMMAND ${CLANG_COMMAND} 36 RESULT_VARIABLE HAD_ERROR 37 OUTPUT_VARIABLE LIBRARY_DIR 38 ) 39 string(STRIP "${LIBRARY_DIR}" LIBRARY_DIR) 40 set(LIBRARY_DIR "${LIBRARY_DIR}/darwin") 41 else() 42 set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXXABI_COMPILE_FLAGS} 43 "--rtlib=compiler-rt" "--print-libgcc-file-name") 44 execute_process( 45 COMMAND ${CLANG_COMMAND} 46 RESULT_VARIABLE HAD_ERROR 47 OUTPUT_VARIABLE LIBRARY_FILE 48 ) 49 string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE) 50 get_filename_component(LIBRARY_DIR "${LIBRARY_FILE}" DIRECTORY) 51 endif() 52 if (NOT HAD_ERROR AND EXISTS "${LIBRARY_DIR}") 53 message(STATUS "Found compiler-rt directory: ${LIBRARY_DIR}") 54 set(${dest} "${LIBRARY_DIR}" PARENT_SCOPE) 55 else() 56 message(STATUS "Failed to find compiler-rt directory") 57 endif() 58 endfunction() 59