1 include(LLVMProcessSources)
3 function(get_system_libs return_var)
4 # Returns in `return_var' a list of system libraries used by LLVM.
7 set(system_libs ${system_libs} imagehlp psapi)
8 elseif( CMAKE_HOST_UNIX )
10 set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
12 if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD )
13 set(system_libs ${system_libs} pthread)
17 set(${return_var} ${system_libs} PARENT_SCOPE)
18 endfunction(get_system_libs)
20 macro(add_llvm_library name)
21 llvm_process_sources( ALL_FILES ${ARGN} )
22 add_library( ${name} ${ALL_FILES} )
23 set( llvm_libs ${llvm_libs} ${name} PARENT_SCOPE)
24 set( llvm_lib_targets ${llvm_lib_targets} ${name} PARENT_SCOPE )
25 if( LLVM_COMMON_DEPENDS )
26 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
27 endif( LLVM_COMMON_DEPENDS )
29 target_link_libraries(${name} ${LLVM_COMMON_LIBS})
31 install(TARGETS ${name}
33 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
34 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
35 # The LLVM Target library shall be built before its sublibraries
36 # (asmprinter, etc) because those may use tablegenned files which
37 # generation is triggered by the main LLVM target library. Necessary
38 # for parallel builds:
39 if( CURRENT_LLVM_TARGET )
40 add_dependencies(${name} ${CURRENT_LLVM_TARGET})
42 endmacro(add_llvm_library name)
45 macro(add_llvm_loadable_module name)
46 if( NOT LLVM_ON_UNIX )
47 message(STATUS "Loadable modules not supported on this platform.
50 llvm_process_sources( ALL_FILES ${ARGN} )
51 add_library( ${name} MODULE ${ALL_FILES} )
52 set_target_properties( ${name} PROPERTIES PREFIX "" )
55 # Darwin-specific linker flags for loadable modules.
56 set_target_properties(${name} PROPERTIES
57 LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
60 install(TARGETS ${name}
62 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
63 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
65 endmacro(add_llvm_loadable_module name)
68 macro(add_llvm_executable name)
69 llvm_process_sources( ALL_FILES ${ARGN} )
70 if( EXCLUDE_FROM_ALL )
71 add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
73 add_executable(${name} ${ALL_FILES})
75 set(EXCLUDE_FROM_ALL OFF)
77 foreach(lib ${LLVM_USED_LIBS})
78 target_link_libraries( ${name} ${lib} )
80 endif( LLVM_USED_LIBS )
81 if( LLVM_COMMON_DEPENDS )
82 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
83 endif( LLVM_COMMON_DEPENDS )
85 target_link_libraries(${name} ${LLVM_COMMON_LIBS})
88 get_system_libs(llvm_system_libs)
89 if( llvm_system_libs )
90 target_link_libraries(${name} ${llvm_system_libs})
93 endmacro(add_llvm_executable name)
96 macro(add_llvm_tool name)
97 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR})
98 if( NOT LLVM_BUILD_TOOLS )
99 set(EXCLUDE_FROM_ALL ON)
101 add_llvm_executable(${name} ${ARGN})
102 if( LLVM_BUILD_TOOLS )
103 install(TARGETS ${name} RUNTIME DESTINATION bin)
105 endmacro(add_llvm_tool name)
108 macro(add_llvm_example name)
109 # set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_EXAMPLES_BINARY_DIR})
110 if( NOT LLVM_BUILD_EXAMPLES )
111 set(EXCLUDE_FROM_ALL ON)
113 add_llvm_executable(${name} ${ARGN})
114 if( LLVM_BUILD_EXAMPLES )
115 install(TARGETS ${name} RUNTIME DESTINATION examples)
117 endmacro(add_llvm_example name)
120 macro(add_llvm_target target_name)
121 if( TABLEGEN_OUTPUT )
122 add_custom_target(${target_name}Table_gen
123 DEPENDS ${TABLEGEN_OUTPUT})
124 add_dependencies(${target_name}Table_gen ${LLVM_COMMON_DEPENDS})
125 endif( TABLEGEN_OUTPUT )
126 include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
127 add_llvm_library(LLVM${target_name} ${ARGN} ${TABLEGEN_OUTPUT})
128 if ( TABLEGEN_OUTPUT )
129 add_dependencies(LLVM${target_name} ${target_name}Table_gen)
130 endif (TABLEGEN_OUTPUT)
131 set(CURRENT_LLVM_TARGET LLVM${target_name} PARENT_SCOPE)
132 endmacro(add_llvm_target)
134 macro(llvm_get_target_libraries return_var)
135 set( link_components ${ARGN} )
136 foreach(c ${link_components})
137 # add codegen, asmprinter, asmparser, disassembler
138 list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
140 list(FIND llvm_libs "LLVM${c}CodeGen" idx)
142 list(APPEND expanded_components "LLVM${c}CodeGen")
144 list(FIND llvm_libs "LLVM${c}" idx)
146 list(APPEND expanded_components "LLVM${c}")
148 message(FATAL_ERROR "Target ${c} is not in the set of libraries.")
151 list(FIND llvm_libs "LLVM${c}AsmPrinter" asmidx)
152 if( NOT asmidx LESS 0 )
153 list(APPEND expanded_components "LLVM${c}AsmPrinter")
155 list(FIND llvm_libs "LLVM${c}AsmParser" asmidx)
156 if( NOT asmidx LESS 0 )
157 list(APPEND expanded_components "LLVM${c}AsmParser")
159 list(FIND llvm_libs "LLVM${c}Info" asmidx)
160 if( NOT asmidx LESS 0 )
161 list(APPEND expanded_components "LLVM${c}Info")
163 list(FIND llvm_libs "LLVM${c}Disassembler" asmidx)
164 if( NOT asmidx LESS 0 )
165 list(APPEND expanded_components "LLVM${c}Disassembler")
167 elseif( c STREQUAL "native" )
168 list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen")
169 elseif( c STREQUAL "nativecodegen" )
170 list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen")
171 elseif( c STREQUAL "backend" )
172 # same case as in `native'.
173 elseif( c STREQUAL "engine" OR c STREQUAL "jit")
174 # TODO: as we assume we are on X86, this is `jit'.
175 list(APPEND expanded_components "LLVMJIT")
176 elseif( c STREQUAL "interpreter" )
177 list(APPEND expanded_components "LLVMInterpreter")
178 elseif( c STREQUAL "all" )
179 list(APPEND expanded_components ${llvm_libs})
180 else( NOT idx LESS 0 )
181 list(APPEND expanded_components LLVM${c})
182 endif( NOT idx LESS 0 )
184 set(${return_var} ${expanded_components})
185 endmacro(llvm_get_target_libraries)
187 macro(add_llvm_link_components target_name)
188 llvm_get_target_libraries(target_libs ${ARGN})
189 target_link_libraries(${target_name} ${target_libs})