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})
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})
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})
19 list(LENGTH llvmbuild_components llvmbuild_components_size)
20 file(WRITE ${ARG_OUTPUT}
22 struct AvailableComponent {
23 /// The name of the component.
26 /// The name of the library for this component (or NULL).
29 /// Whether the component is installed.
32 /// The list of libraries required when linking this component.
33 const char *RequiredLibraries[${llvmbuild_components_size}];
34 } AvailableComponents[${llvmbuild_components_size}] = {
37 foreach(llvmbuild_component ${llvmbuild_components})
38 if(llvmbuild_component STREQUAL "all")
39 unset(llvmbuild_libname)
40 set(llvmbuild_libdeps ${all_component_libdeps})
42 get_property(llvmbuild_libname TARGET ${llvmbuild_component} PROPERTY LLVM_COMPONENT_NAME)
43 get_property(llvmbuild_libdeps TARGET ${llvmbuild_component} PROPERTY LLVM_LINK_COMPONENTS)
45 string(TOLOWER ${llvmbuild_component} llvmbuild_componentname)
47 if(NOT llvmbuild_libname)
48 set(llvmbuild_llvmlibname nullptr)
49 string(TOLOWER ${llvmbuild_component} llvmbuild_libname)
51 set(llvmbuild_llvmlibname "\"LLVM${llvmbuild_libname}\"")
52 string(TOLOWER ${llvmbuild_libname} llvmbuild_libname)
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)
61 string(TOLOWER ${llvmbuild_libdepname} llvmbuild_clibdep)
63 list(APPEND llvmbuild_clibdeps ${llvmbuild_clibdep})
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")
72 list(SORT llvmbuild_centries)
73 foreach(llvmbuild_centry ${llvmbuild_centries})
74 file(APPEND ${ARG_OUTPUT} "${llvmbuild_centry}")
76 file(APPEND ${ARG_OUTPUT} "};")
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)
86 set(llvm_has_jit_native OFF)
89 if(llvm_has_jit_native)
90 set_property(TARGET Engine APPEND PROPERTY LLVM_LINK_COMPONENTS "MCJIT" "Native")
92 set_property(TARGET Engine APPEND PROPERTY LLVM_LINK_COMPONENTS "Interpreter")
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})
100 get_property(libtype TARGET ${llvm_component} PROPERTY LLVM_LIBTYPE)
101 target_link_libraries(${llvm_component} ${libtype} ${llvm_libs})