blob: 2e0e69e5e085da45f3b3761028f097ebb3df47ca [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)
Petr Hosek9036c492017-04-16 02:25:55 +00006 set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXX_COMPILE_FLAGS}
Eric Fiselier58bd12a2017-03-11 03:24:18 +00007 "--rtlib=compiler-rt" "--print-libgcc-file-name")
Petr Hosekc868a982017-04-05 22:53:05 +00008 if (CMAKE_CXX_COMPILER_ID MATCHES Clang AND CMAKE_CXX_COMPILER_TARGET)
9 list(APPEND CLANG_COMMAND "--target=${CMAKE_CXX_COMPILER_TARGET}")
10 endif()
Eric Fiselier58bd12a2017-03-11 03:24:18 +000011 execute_process(
12 COMMAND ${CLANG_COMMAND}
13 RESULT_VARIABLE HAD_ERROR
14 OUTPUT_VARIABLE LIBRARY_FILE
15 )
16 string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE)
Martin Storsjo57a4aef2018-06-20 21:03:34 +000017 file(TO_CMAKE_PATH "${LIBRARY_FILE}" LIBRARY_FILE)
Eric Fiselier58bd12a2017-03-11 03:24:18 +000018 string(REPLACE "builtins" "${name}" LIBRARY_FILE "${LIBRARY_FILE}")
19 if (NOT HAD_ERROR AND EXISTS "${LIBRARY_FILE}")
20 message(STATUS "Found compiler-rt library: ${LIBRARY_FILE}")
21 set(${dest} "${LIBRARY_FILE}" PARENT_SCOPE)
22 else()
23 message(STATUS "Failed to find compiler-rt library")
24 endif()
25endfunction()
26
27function(find_compiler_rt_dir dest)
28 if (NOT DEFINED LIBCXX_COMPILE_FLAGS)
29 message(FATAL_ERROR "LIBCXX_COMPILE_FLAGS must be defined when using this function")
30 endif()
31 set(dest "" PARENT_SCOPE)
Bruno Cardoso Lopes76328442017-03-14 04:12:29 +000032 if (APPLE)
33 set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXX_COMPILE_FLAGS}
34 "-print-file-name=lib")
35 execute_process(
36 COMMAND ${CLANG_COMMAND}
37 RESULT_VARIABLE HAD_ERROR
38 OUTPUT_VARIABLE LIBRARY_DIR
39 )
40 string(STRIP "${LIBRARY_DIR}" LIBRARY_DIR)
Martin Storsjo57a4aef2018-06-20 21:03:34 +000041 file(TO_CMAKE_PATH "${LIBRARY_DIR}" LIBRARY_DIR)
Bruno Cardoso Lopes76328442017-03-14 04:12:29 +000042 set(LIBRARY_DIR "${LIBRARY_DIR}/darwin")
43 else()
44 set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXX_COMPILE_FLAGS}
45 "--rtlib=compiler-rt" "--print-libgcc-file-name")
46 execute_process(
47 COMMAND ${CLANG_COMMAND}
48 RESULT_VARIABLE HAD_ERROR
49 OUTPUT_VARIABLE LIBRARY_FILE
50 )
51 string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE)
Martin Storsjo57a4aef2018-06-20 21:03:34 +000052 file(TO_CMAKE_PATH "${LIBRARY_FILE}" LIBRARY_FILE)
Bruno Cardoso Lopes76328442017-03-14 04:12:29 +000053 get_filename_component(LIBRARY_DIR "${LIBRARY_FILE}" DIRECTORY)
54 endif()
Eric Fiselier58bd12a2017-03-11 03:24:18 +000055 if (NOT HAD_ERROR AND EXISTS "${LIBRARY_DIR}")
56 message(STATUS "Found compiler-rt directory: ${LIBRARY_DIR}")
57 set(${dest} "${LIBRARY_DIR}" PARENT_SCOPE)
58 else()
59 message(STATUS "Failed to find compiler-rt directory")
60 endif()
61endfunction()