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 if (APPLE) 29 set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXX_COMPILE_FLAGS} 30 "-print-file-name=lib") 31 execute_process( 32 COMMAND ${CLANG_COMMAND} 33 RESULT_VARIABLE HAD_ERROR 34 OUTPUT_VARIABLE LIBRARY_DIR 35 ) 36 string(STRIP "${LIBRARY_DIR}" LIBRARY_DIR) 37 set(LIBRARY_DIR "${LIBRARY_DIR}/darwin") 38 else() 39 set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXX_COMPILE_FLAGS} 40 "--rtlib=compiler-rt" "--print-libgcc-file-name") 41 execute_process( 42 COMMAND ${CLANG_COMMAND} 43 RESULT_VARIABLE HAD_ERROR 44 OUTPUT_VARIABLE LIBRARY_FILE 45 ) 46 string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE) 47 get_filename_component(LIBRARY_DIR "${LIBRARY_FILE}" DIRECTORY) 48 endif() 49 if (NOT HAD_ERROR AND EXISTS "${LIBRARY_DIR}") 50 message(STATUS "Found compiler-rt directory: ${LIBRARY_DIR}") 51 set(${dest} "${LIBRARY_DIR}" PARENT_SCOPE) 52 else() 53 message(STATUS "Failed to find compiler-rt directory") 54 endif() 55 endfunction() 56