blob: 9730008319c781500c2dddba63ca4928664147eb [file] [log] [blame]
Eric Fiselier58bd12a2017-03-11 03:24:18 +00001function(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()
21endfunction()
22
23function(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)
Bruno Cardoso Lopes76328442017-03-14 04:12:29 +000028 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()
Eric Fiselier58bd12a2017-03-11 03:24:18 +000049 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()
55endfunction()