llvm.org GIT mirror llvm / 0eefad3
[CMake] Introduce llvm_add_library(). - MODULE;SHARED;STATIC STATIC by default w/o BUILD_SHARED_LIBS. SHARED by default w/ BUILD_SHARED_LIBS. - OUTPUT_NAME name Corresponds to OUTPUT_NAME in target properties. - DEPENDS targets... Same semantics as add_dependencies(). - LINK_COMPONENTS components... Same as the variable LLVM_LINK_COMPONENTS. - LINK_LIBS lib_targets... Same semantics as target_link_libraries(). - ADDITIONAL_HEADERS (implemented in LLVMProcessSources) May specify header files for IDE generators. I suggest llvm_add_library() may be used for inter-project add_library stuff and also suggest add_***_library() may be used project-specific. Please be patient that llvm_add_library might be ambiguous against add_llvm_library. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201072 91177308-0d34-0410-b5e6-96231b3b80d8 NAKAMURA Takumi 5 years ago
1 changed file(s) with 77 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
161161 endif()
162162 endfunction()
163163
164 macro(add_llvm_library name)
165 llvm_process_sources( ALL_FILES ${ARGN} )
166 add_library( ${name} ${ALL_FILES} )
164 # llvm_add_library(name sources...
165 # MODULE;SHARED;STATIC
166 # STATIC by default w/o BUILD_SHARED_LIBS.
167 # SHARED by default w/ BUILD_SHARED_LIBS.
168 # OUTPUT_NAME name
169 # Corresponds to OUTPUT_NAME in target properties.
170 # DEPENDS targets...
171 # Same semantics as add_dependencies().
172 # LINK_COMPONENTS components...
173 # Same as the variable LLVM_LINK_COMPONENTS.
174 # LINK_LIBS lib_targets...
175 # Same semantics as target_link_libraries().
176 # ADDITIONAL_HEADERS (implemented in LLVMProcessSources)
177 # May specify header files for IDE generators.
178 # )
179 function(llvm_add_library name)
180 cmake_parse_arguments(ARG
181 "MODULE;SHARED;STATIC"
182 "OUTPUT_NAME"
183 "DEPENDS;LINK_COMPONENTS;LINK_LIBS"
184 ${ARGN})
185 list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS})
186 llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS})
187
188 if(ARG_MODULE)
189 if(ARG_SHARED OR ARG_STATIC)
190 message(WARNING "MODULE with SHARED|STATIC doesn't make sense.")
191 endif()
192 else()
193 if(BUILD_SHARED_LIBS AND NOT ARG_STATIC)
194 set(ARG_SHARED TRUE)
195 endif()
196 if(NOT ARG_SHARED)
197 set(ARG_STATIC TRUE)
198 endif()
199 endif()
200
201 if(ARG_MODULE)
202 add_library(${name} MODULE ${ALL_FILES})
203 elseif(ARG_SHARED)
204 add_library(${name} SHARED ${ALL_FILES})
205 else()
206 add_library(${name} STATIC ${ALL_FILES})
207 endif()
167208 set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR})
168 set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} )
169209 llvm_update_compile_flags(${name})
170210 add_dead_strip( ${name} )
171 if( LLVM_COMMON_DEPENDS )
172 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
173 endif( LLVM_COMMON_DEPENDS )
174
175 if( BUILD_SHARED_LIBS )
176 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
211 if(ARG_OUTPUT_NAME)
212 set_target_properties(${name}
213 PROPERTIES
214 OUTPUT_NAME ${ARG_OUTPUT_NAME}
215 )
216 endif()
217
218 if(ARG_MODULE)
219 set_property(TARGET ${name} PROPERTY SUFFIX ${LLVM_PLUGIN_EXT})
220 endif()
221
222 if(ARG_SHARED)
177223 if (MSVC)
178224 set_target_properties(${name}
179225 PROPERTIES
180226 IMPORT_SUFFIX ".imp")
181227 endif ()
182
228 endif()
229
230 if(ARG_MODULE OR ARG_SHARED)
183231 if (LLVM_EXPORTED_SYMBOL_FILE)
184232 add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
185233 endif()
186234 endif()
235
236 target_link_libraries(${name} ${ARG_LINK_LIBS})
237
238 llvm_config(${name} ${ARG_LINK_COMPONENTS} ${LLVM_LINK_COMPONENTS})
187239
188240 # Ensure that the system libraries always comes last on the
189241 # list. Without this, linking the unit tests on MinGW fails.
190242 link_system_libs( ${name} )
243
244 if(LLVM_COMMON_DEPENDS)
245 add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
246 endif()
247 endfunction()
248
249 macro(add_llvm_library name)
250 if( BUILD_SHARED_LIBS )
251 llvm_add_library(${name} SHARED ${ARGN})
252 else()
253 llvm_add_library(${name} ${ARGN})
254 endif()
255 set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} )
191256
192257 if( EXCLUDE_FROM_ALL )
193258 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
218283 # Add empty "phony" target
219284 add_custom_target(${name})
220285 else()
221 llvm_process_sources( ALL_FILES ${ARGN} )
222 add_library(${name} MODULE ${ALL_FILES})
223 set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR})
286 llvm_add_library(${name} MODULE ${ARGN})
224287 set_target_properties( ${name} PROPERTIES PREFIX "" )
225 llvm_update_compile_flags(${name})
226 add_dead_strip( ${name} )
227
228 if (LLVM_EXPORTED_SYMBOL_FILE)
229 add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
230 endif(LLVM_EXPORTED_SYMBOL_FILE)
231
232 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
233 link_system_libs( ${name} )
234288
235289 if (APPLE)
236290 # Darwin-specific linker flags for loadable modules.
237291 set_property(TARGET ${name} APPEND_STRING PROPERTY
238292 LINK_FLAGS " -Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
239293 endif()
240
241 if (MODULE)
242 set_property(TARGET ${name} PROPERTY SUFFIX ${LLVM_PLUGIN_EXT})
243 endif ()
244294
245295 if( EXCLUDE_FROM_ALL )
246296 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)