[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / cmake / modules / LLVM-Build.cmake
blob525186cbbb19b31f40425cfae5d3a2907f6f7c47
1 # Generate C code in the file provided as OUTPUT that describes the properties
2 # of all components. This C code is suitable for inclusion in `llvm-config`
3 function(LLVMBuildGenerateCFragment)
4   cmake_parse_arguments(ARG "" "OUTPUT" "" ${ARGN})
6   # Write C header
7   #################
8   get_property(llvmbuild_components GLOBAL PROPERTY LLVM_COMPONENT_LIBS)
9   foreach(llvmbuild_component ${llvmbuild_components})
10     string(REGEX REPLACE "^LLVM" "" component_name ${llvmbuild_component})
11     list(APPEND all_component_libdeps ${component_name})
12   endforeach()
13   list(APPEND llvmbuild_components all)
14   foreach(llvm_component all-targets Engine Native NativeCodeGen ${LLVM_TARGETS_TO_BUILD})
15     list(APPEND llvmbuild_components ${llvm_component})
16     list(APPEND all_component_libdeps ${llvm_component})
17   endforeach()
19   list(LENGTH llvmbuild_components llvmbuild_components_size)
20   file(WRITE ${ARG_OUTPUT}
21   "
22   struct AvailableComponent {
23     /// The name of the component.
24     const char *Name;
26     /// The name of the library for this component (or NULL).
27     const char *Library;
29     /// Whether the component is installed.
30     bool IsInstalled;
32     /// The list of libraries required when linking this component.
33     const char *RequiredLibraries[${llvmbuild_components_size}];
34   } AvailableComponents[${llvmbuild_components_size}] = {
35   ")
37   foreach(llvmbuild_component ${llvmbuild_components})
38     if(llvmbuild_component STREQUAL "all")
39       unset(llvmbuild_libname)
40       set(llvmbuild_libdeps ${all_component_libdeps})
41     else()
42       get_property(llvmbuild_libname TARGET ${llvmbuild_component} PROPERTY LLVM_COMPONENT_NAME)
43       get_property(llvmbuild_libdeps TARGET ${llvmbuild_component} PROPERTY LLVM_LINK_COMPONENTS)
44     endif()
45     string(TOLOWER ${llvmbuild_component} llvmbuild_componentname)
47     if(NOT llvmbuild_libname)
48       set(llvmbuild_llvmlibname nullptr)
49       string(TOLOWER ${llvmbuild_component} llvmbuild_libname)
50     else()
51       set(llvmbuild_llvmlibname "\"LLVM${llvmbuild_libname}\"")
52       string(TOLOWER ${llvmbuild_libname} llvmbuild_libname)
53     endif()
55     set(llvmbuild_clibdeps "")
56     foreach(llvmbuild_libdep ${llvmbuild_libdeps})
57       get_property(llvmbuild_libdepname GLOBAL PROPERTY LLVM_COMPONENT_NAME_${llvmbuild_libdep})
58       if(NOT llvmbuild_libdepname)
59         string(TOLOWER ${llvmbuild_libdep} llvmbuild_clibdep)
60       else()
61         string(TOLOWER ${llvmbuild_libdepname} llvmbuild_clibdep)
62       endif()
63       list(APPEND llvmbuild_clibdeps ${llvmbuild_clibdep})
64     endforeach()
66     list(TRANSFORM llvmbuild_clibdeps PREPEND "\"")
67     list(TRANSFORM llvmbuild_clibdeps APPEND "\"")
68     list(JOIN llvmbuild_clibdeps ", " llvmbuild_clibdeps_joint)
69     list(APPEND llvmbuild_centries "{ \"${llvmbuild_libname}\", ${llvmbuild_llvmlibname}, true, {${llvmbuild_clibdeps_joint}} },\n")
70   endforeach()
72   list(SORT llvmbuild_centries)
73   foreach(llvmbuild_centry ${llvmbuild_centries})
74     file(APPEND ${ARG_OUTPUT} "${llvmbuild_centry}")
75   endforeach()
76   file(APPEND ${ARG_OUTPUT} "};")
77 endfunction()
79 # Resolve cross-component dependencies, for each available component.
80 function(LLVMBuildResolveComponentsLink)
82   # the native target may not be enabled when cross compiling
83   if(TARGET ${LLVM_NATIVE_ARCH})
84     get_property(llvm_has_jit_native TARGET ${LLVM_NATIVE_ARCH} PROPERTY LLVM_HAS_JIT)
85   else()
86     set(llvm_has_jit_native OFF)
87   endif()
89   if(llvm_has_jit_native)
90     set_property(TARGET Engine APPEND PROPERTY LLVM_LINK_COMPONENTS "MCJIT" "Native")
91   else()
92     set_property(TARGET Engine APPEND PROPERTY LLVM_LINK_COMPONENTS "Interpreter")
93   endif()
95   get_property(llvm_components GLOBAL PROPERTY LLVM_COMPONENT_LIBS)
96   foreach(llvm_component ${llvm_components})
97     get_property(link_components TARGET ${llvm_component} PROPERTY LLVM_LINK_COMPONENTS)
98     llvm_map_components_to_libnames(llvm_libs ${link_components})
99     if(llvm_libs)
100       get_property(libtype TARGET ${llvm_component} PROPERTY LLVM_LIBTYPE)
101       target_link_libraries(${llvm_component} ${libtype} ${llvm_libs})
102     endif()
103   endforeach()
104 endfunction()