llvm.org GIT mirror llvm / 1901ee6
[CMake] Introduce "llvm_add_library(SHARED STATIC)" to build both shared lib and static lib simulataneously. llvm_add_library(foo SHARED STATIC DEPENDS <dependent targets...> LINK_LIBS <required libraries...> ) It generates both foo (foo.so) and foo_static(foo.a) and both of them depend on DEPENDS and LINK_LIBS. Then, also obj.foo is generated. obj.foo depends on DEPENDS, but doesn't depend on LINK_LIBS. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201854 91177308-0d34-0410-b5e6-96231b3b80d8 NAKAMURA Takumi 5 years ago
1 changed file(s) with 36 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
183183 cmake_parse_arguments(ARG
184184 "MODULE;SHARED;STATIC"
185185 "OUTPUT_NAME"
186 "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS"
186 "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS"
187187 ${ARGN})
188188 list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS})
189189 if(ARG_ADDITIONAL_HEADERS)
190190 # Pass through ADDITIONAL_HEADERS.
191191 set(ARG_ADDITIONAL_HEADERS ADDITIONAL_HEADERS ${ARG_ADDITIONAL_HEADERS})
192192 endif()
193 llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ${ARG_ADDITIONAL_HEADERS})
193 if(ARG_OBJLIBS)
194 set(ALL_FILES ${ARG_OBJLIBS})
195 else()
196 llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ${ARG_ADDITIONAL_HEADERS})
197 endif()
194198
195199 if(ARG_MODULE)
196200 if(ARG_SHARED OR ARG_STATIC)
207211 if(NOT ARG_SHARED)
208212 set(ARG_STATIC TRUE)
209213 endif()
214 endif()
215
216 # Generate objlib
217 if(ARG_SHARED AND ARG_STATIC)
218 # Generate an obj library for both targets.
219 set(obj_name "obj.${name}")
220 add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL
221 ${ALL_FILES}
222 )
223 llvm_update_compile_flags(${obj_name})
224 set(ALL_FILES "$")
225
226 set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries")
227 endif()
228
229 if(ARG_SHARED AND ARG_STATIC)
230 # static
231 set(name_static "${name}_static")
232 if(ARG_OUTPUT_NAME)
233 set(output_name OUTPUT_NAME "${ARG_OUTPUT_NAME}_static")
234 endif()
235 # DEPENDS has been appended to LLVM_COMMON_LIBS.
236 llvm_add_library(${name_static} STATIC
237 ${output_name}
238 OBJLIBS ${ALL_FILES} # objlib
239 LINK_LIBS ${ARG_LINK_LIBS}
240 LINK_COMPONENTS ${ARG_LINK_COMPONENTS}
241 )
242 # FIXME: Add name_static to anywhere in TARGET ${name}'s PROPERTY.
243 set(ARG_STATIC)
210244 endif()
211245
212246 if(ARG_MODULE)