[llvm] r201854 - [CMake] Introduce "llvm_add_library(SHARED STATIC)" to build both shared lib and static lib simulataneously.
NAKAMURA Takumi
geek4civic at gmail.com
Fri Feb 21 06:17:17 PST 2014
Author: chapuni
Date: Fri Feb 21 08:17:17 2014
New Revision: 201854
URL: http://llvm.org/viewvc/llvm-project?rev=201854&view=rev
Log:
[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.
Modified:
llvm/trunk/cmake/modules/AddLLVM.cmake
Modified: llvm/trunk/cmake/modules/AddLLVM.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/AddLLVM.cmake?rev=201854&r1=201853&r2=201854&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/AddLLVM.cmake (original)
+++ llvm/trunk/cmake/modules/AddLLVM.cmake Fri Feb 21 08:17:17 2014
@@ -184,14 +184,18 @@ function(llvm_add_library name)
cmake_parse_arguments(ARG
"MODULE;SHARED;STATIC"
"OUTPUT_NAME"
- "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS"
+ "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS"
${ARGN})
list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS})
if(ARG_ADDITIONAL_HEADERS)
# Pass through ADDITIONAL_HEADERS.
set(ARG_ADDITIONAL_HEADERS ADDITIONAL_HEADERS ${ARG_ADDITIONAL_HEADERS})
endif()
- llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ${ARG_ADDITIONAL_HEADERS})
+ if(ARG_OBJLIBS)
+ set(ALL_FILES ${ARG_OBJLIBS})
+ else()
+ llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ${ARG_ADDITIONAL_HEADERS})
+ endif()
if(ARG_MODULE)
if(ARG_SHARED OR ARG_STATIC)
@@ -210,6 +214,36 @@ function(llvm_add_library name)
endif()
endif()
+ # Generate objlib
+ if(ARG_SHARED AND ARG_STATIC)
+ # Generate an obj library for both targets.
+ set(obj_name "obj.${name}")
+ add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL
+ ${ALL_FILES}
+ )
+ llvm_update_compile_flags(${obj_name})
+ set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>")
+
+ set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries")
+ endif()
+
+ if(ARG_SHARED AND ARG_STATIC)
+ # static
+ set(name_static "${name}_static")
+ if(ARG_OUTPUT_NAME)
+ set(output_name OUTPUT_NAME "${ARG_OUTPUT_NAME}_static")
+ endif()
+ # DEPENDS has been appended to LLVM_COMMON_LIBS.
+ llvm_add_library(${name_static} STATIC
+ ${output_name}
+ OBJLIBS ${ALL_FILES} # objlib
+ LINK_LIBS ${ARG_LINK_LIBS}
+ LINK_COMPONENTS ${ARG_LINK_COMPONENTS}
+ )
+ # FIXME: Add name_static to anywhere in TARGET ${name}'s PROPERTY.
+ set(ARG_STATIC)
+ endif()
+
if(ARG_MODULE)
add_library(${name} MODULE ${ALL_FILES})
elseif(ARG_SHARED)
More information about the llvm-commits
mailing list