3 macro(llvm_config executable)
4 # extra args is the list of link components.
6 msvc_llvm_config(${executable} ${ARGN})
8 nix_llvm_config(${executable} ${ARGN})
13 function(msvc_llvm_config executable)
14 set( link_components ${ARGN} )
16 set(include_lflag "/INCLUDE:")
18 set(include_lflag "/INCLUDE:_")
20 foreach(c ${link_components})
21 if( c STREQUAL "jit" )
22 set(lfgs "${lfgs} ${include_lflag}X86TargetMachineModule")
23 endif( c STREQUAL "jit" )
24 list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
26 set(lfgs "${lfgs} ${include_lflag}${c}TargetMachineModule")
27 list(FIND LLVM_ASMPRINTERS_FORCE_LINK ${c} idx)
29 set(lfgs "${lfgs} ${include_lflag}${c}AsmPrinterForceLink")
34 msvc_map_components_to_libraries(LIBRARIES ${link_components})
35 target_link_libraries(${executable} ${LIBRARIES})
38 set_target_properties(${executable}
42 endfunction(msvc_llvm_config)
45 function(msvc_map_components_to_libraries out_libs)
46 set( link_components ${ARGN} )
47 foreach(c ${link_components})
48 # add codegen/asmprinter
49 list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
51 list(FIND llvm_libs "LLVM${c}CodeGen" idx)
53 list(APPEND expanded_components "LLVM${c}CodeGen")
55 list(FIND llvm_libs "LLVM${c}" idx)
57 list(APPEND expanded_components "LLVM${c}")
59 message(FATAL_ERROR "Target ${c} is not in the set of libraries.")
62 list(FIND llvm_libs "LLVM${c}AsmPrinter" asmidx)
63 if( NOT asmidx LESS 0 )
64 list(APPEND expanded_components "LLVM${c}AsmPrinter")
66 elseif( c STREQUAL "native" )
67 # TODO: we assume ARCH is X86. In this case, we must use nativecodegen
68 # component instead. Do nothing, as in llvm-config script.
69 elseif( c STREQUAL "nativecodegen" )
70 # TODO: we assume ARCH is X86.
71 list(APPEND expanded_components "LLVMX86CodeGen")
72 elseif( c STREQUAL "backend" )
73 # same case as in `native'.
74 elseif( c STREQUAL "engine" )
75 # TODO: as we assume we are on X86, this is `jit'.
76 list(APPEND expanded_components "LLVMJIT")
77 elseif( c STREQUAL "all" )
78 list(APPEND expanded_components ${llvm_libs})
79 else( NOT idx LESS 0 )
80 list(APPEND expanded_components LLVM${c})
81 endif( NOT idx LESS 0 )
83 # We must match capitalization.
84 string(TOUPPER "${llvm_libs}" capitalized_libs)
85 list(REMOVE_DUPLICATES expanded_components)
87 list(LENGTH expanded_components lst_size)
88 while( ${curr_idx} LESS ${lst_size} )
89 list(GET expanded_components ${curr_idx} c)
90 string(TOUPPER "${c}" capitalized)
91 list(FIND capitalized_libs ${capitalized} idx)
93 message(FATAL_ERROR "Library ${c} not found in list of llvm libraries.")
95 list(GET llvm_libs ${idx} canonical_lib)
96 list(APPEND result ${canonical_lib})
97 list(APPEND result ${MSVC_LIB_DEPS_${canonical_lib}})
98 list(APPEND expanded_components ${MSVC_LIB_DEPS_${canonical_lib}})
99 list(REMOVE_DUPLICATES expanded_components)
100 list(LENGTH expanded_components lst_size)
101 math(EXPR curr_idx "${curr_idx} + 1")
102 endwhile( ${curr_idx} LESS ${lst_size} )
103 list(REMOVE_DUPLICATES result)
104 set(${out_libs} ${result} PARENT_SCOPE)
105 endfunction(msvc_map_components_to_libraries)
108 macro(nix_llvm_config executable)
113 if( NOT HAVE_LLVM_CONFIG )
114 target_link_libraries(${executable}
115 "`${LLVM_TOOLS_BINARY_DIR}/llvm-config --libs ${lc}`")
116 else( NOT HAVE_LLVM_CONFIG )
117 # tbi: Error handling.
118 if( NOT PERL_EXECUTABLE )
119 message(FATAL_ERROR "Perl required but not found!")
120 endif( NOT PERL_EXECUTABLE )
122 COMMAND sh -c "${PERL_EXECUTABLE} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/llvm-config --libs ${lc}"
125 OUTPUT_STRIP_TRAILING_WHITESPACE)
127 message(FATAL_ERROR "llvm-config failed for executable ${executable}")
128 endif(NOT rv EQUAL 0)
129 string(REPLACE " " ";" libs ${libs})
131 if(c MATCHES ".*\\.o")
132 get_filename_component(fn ${c} NAME)
133 target_link_libraries(${executable}
134 ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${fn})
135 else(c MATCHES ".*\\.o")
136 string(REPLACE "-l" "" fn ${c})
137 target_link_libraries(${executable} ${fn})
138 endif(c MATCHES ".*\\.o")
140 endif( NOT HAVE_LLVM_CONFIG )
141 endmacro(nix_llvm_config)
144 # This data is used on MSVC for stablishing executable/library
145 # dependencies. Comes from the llvm-config script, which is built and
146 # installed on the bin directory for MinGW or Linux. At the end of the
147 # script, you'll see lines like this:
149 # LLVMARMAsmPrinter.o: LLVMARMCodeGen.o libLLVMAsmPrinter.a libLLVMCodeGen.a libLLVMCore.a libLLVMSupport.a libLLVMTarget.a
151 # This is translated to:
153 # set(MSVC_LIB_DEPS_LLVMARMAsmPrinter LLVMARMCodeGen LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSupport LLVMTarget)
155 # It is necessary to remove the `lib' prefix, the `.a' and `.o'
156 # suffixes. Watch out for this line:
158 # LLVMExecutionEngine.o LLVMJIT.o: libLLVMCodeGen.a libLLVMCore.a libLLVMSupport.a libLLVMSystem.a libLLVMTarget.a
160 # See how there are two elements before the colon. This must be
161 # translated as if it were:
163 # LLVMExecutionEngine.o: libLLVMCodeGen.a libLLVMCore.a libLLVMSupport.a libLLVMSystem.a libLLVMTarget.a
164 # LLVMJIT.o: libLLVMCodeGen.a libLLVMCore.a libLLVMSupport.a libLLVMSystem.a libLLVMTarget.a
166 # TODO: do this transformations on cmake.
168 # It is very important that the LLVM built for extracting this data
169 # must contain all targets, not just X86.
172 set(MSVC_LIB_DEPS_LLVMARMAsmPrinter LLVMARMCodeGen LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSupport LLVMTarget)
173 set(MSVC_LIB_DEPS_LLVMARMCodeGen LLVMCodeGen LLVMCore LLVMSelectionDAG LLVMSupport LLVMSystem LLVMTarget)
174 set(MSVC_LIB_DEPS_LLVMAlphaAsmPrinter LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSupport LLVMTarget)
175 set(MSVC_LIB_DEPS_LLVMAlphaCodeGen LLVMAlphaAsmPrinter LLVMCodeGen LLVMCore LLVMSelectionDAG LLVMSupport LLVMTarget)
176 set(MSVC_LIB_DEPS_LLVMCBackend LLVMAnalysis LLVMCodeGen LLVMCore LLVMScalarOpts LLVMSupport LLVMTarget LLVMTransformUtils LLVMipa)
177 set(MSVC_LIB_DEPS_LLVMCellSPUAsmPrinter LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSupport LLVMTarget)
178 set(MSVC_LIB_DEPS_LLVMCellSPUCodeGen LLVMCellSPUAsmPrinter LLVMCodeGen LLVMCore LLVMSelectionDAG LLVMSupport LLVMTarget)
179 set(MSVC_LIB_DEPS_LLVMCppBackend LLVMCore LLVMSupport LLVMTarget)
180 set(MSVC_LIB_DEPS_LLVMExecutionEngine LLVMCodeGen LLVMCore LLVMSupport LLVMSystem LLVMTarget)
181 set(MSVC_LIB_DEPS_LLVMJIT LLVMCodeGen LLVMCore LLVMSupport LLVMSystem LLVMTarget)
182 set(MSVC_LIB_DEPS_LLVMIA64 LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSelectionDAG LLVMSupport LLVMTarget)
183 set(MSVC_LIB_DEPS_LLVMInterpreter LLVMExecutionEngine LLVMCodeGen LLVMCore LLVMSupport LLVMSystem LLVMTarget)
184 set(MSVC_LIB_DEPS_LLVMMSIL LLVMAnalysis LLVMCodeGen LLVMCore LLVMScalarOpts LLVMSupport LLVMTarget LLVMTransformUtils LLVMipa)
185 set(MSVC_LIB_DEPS_LLVMMips LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSelectionDAG LLVMSupport LLVMTarget)
186 set(MSVC_LIB_DEPS_LLVMPIC16 LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSelectionDAG LLVMSupport LLVMTarget)
187 set(MSVC_LIB_DEPS_LLVMPowerPCAsmPrinter LLVMPowerPCCodeGen LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSupport LLVMTarget)
188 set(MSVC_LIB_DEPS_LLVMPowerPCCodeGen LLVMCodeGen LLVMCore LLVMSelectionDAG LLVMSupport LLVMSystem LLVMTarget)
189 set(MSVC_LIB_DEPS_LLVMSparcAsmPrinter LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSupport LLVMTarget)
190 set(MSVC_LIB_DEPS_LLVMSparcCodeGen LLVMSparcAsmPrinter LLVMCodeGen LLVMCore LLVMSelectionDAG LLVMSupport LLVMTarget)
191 set(MSVC_LIB_DEPS_LLVMX86AsmPrinter LLVMX86CodeGen LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSupport LLVMTarget)
192 set(MSVC_LIB_DEPS_LLVMX86CodeGen LLVMCodeGen LLVMCore LLVMSelectionDAG LLVMSupport LLVMTarget)
193 set(MSVC_LIB_DEPS_LLVMXCore LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSelectionDAG LLVMSupport LLVMTarget)
194 set(MSVC_LIB_DEPS_LLVMAnalysis LLVMCore LLVMSupport LLVMSystem LLVMTarget)
195 set(MSVC_LIB_DEPS_LLVMArchive LLVMBitReader LLVMCore LLVMSupport LLVMSystem)
196 set(MSVC_LIB_DEPS_LLVMAsmParser LLVMCore LLVMSupport)
197 set(MSVC_LIB_DEPS_LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSupport LLVMSystem LLVMTarget)
198 set(MSVC_LIB_DEPS_LLVMBitReader LLVMCore LLVMSupport)
199 set(MSVC_LIB_DEPS_LLVMBitWriter LLVMCore LLVMSupport LLVMSystem)
200 set(MSVC_LIB_DEPS_LLVMCodeGen LLVMAnalysis LLVMCore LLVMScalarOpts LLVMSupport LLVMSystem LLVMTarget LLVMTransformUtils)
201 set(MSVC_LIB_DEPS_LLVMCore LLVMSupport LLVMSystem)
202 set(MSVC_LIB_DEPS_LLVMDebugger LLVMAnalysis LLVMBitReader LLVMCore LLVMSupport LLVMSystem)
203 set(MSVC_LIB_DEPS_LLVMHello LLVMCore LLVMSupport)
204 set(MSVC_LIB_DEPS_LLVMInstrumentation LLVMCore LLVMScalarOpts LLVMSupport LLVMTransformUtils)
205 set(MSVC_LIB_DEPS_LLVMLinker LLVMArchive LLVMBitReader LLVMCore LLVMSupport LLVMSystem)
206 set(MSVC_LIB_DEPS_LLVMScalarOpts LLVMAnalysis LLVMCore LLVMSupport LLVMTarget LLVMTransformUtils)
207 set(MSVC_LIB_DEPS_LLVMSelectionDAG LLVMAnalysis LLVMCodeGen LLVMCore LLVMSupport LLVMSystem LLVMTarget)
208 set(MSVC_LIB_DEPS_LLVMSupport LLVMSystem)
209 set(MSVC_LIB_DEPS_LLVMSystem )
210 set(MSVC_LIB_DEPS_LLVMTarget LLVMCore LLVMSupport)
211 set(MSVC_LIB_DEPS_LLVMTransformUtils LLVMAnalysis LLVMCore LLVMSupport LLVMTarget LLVMipa)
212 set(MSVC_LIB_DEPS_LLVMipa LLVMAnalysis LLVMCore LLVMSupport)
213 set(MSVC_LIB_DEPS_LLVMipo LLVMAnalysis LLVMCore LLVMSupport LLVMTarget LLVMTransformUtils LLVMipa)