[PATCH] D62033: Change llvm_add_library to always use name for static libraries
Wink Saville via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 16 14:19:08 PDT 2019
winksaville created this revision.
winksaville added reviewers: tstellar, beanz.
Herald added subscribers: llvm-commits, mgorny.
Herald added a project: LLVM.
Problem:
The default for libraries built using llvm_add_library is STATIC unless
BUILD_SHARED_LIBS is ON but having BUILD_SHARED_LIBS is an unsupported
configuration for non LLVM developers. See Note for BUILD_SHARED_LIBS:BOOL
in https://llvm.org/docs/CMake.html where it says:
"BUILD_SHARED_LIBS is only recommended for use by LLVM developers. If you
want to build LLVM as a shared library, you should use the
LLVM_BUILD_LLVM_DYLIB option."
As well as building STATIC libraries llvm_add_library can be used to
create SHARED, OBJECT or MODULE libraries. When creating these the first
parameter, ${name} is used as the name of the cmake object and also its
OUTPUT_NAME.
There is one exception to the naming rule, if both STATIC and SHARED are
passed to llvm_add_library both a static and shared libraries are created
and they must have different names. The current code uses ${name} for the
shared library and ${name}_static for the static library.
This causes a problem because by default LLVM sub-projects prefer linking
to LLVM using its static libraries, libLLVM*.a. For example, when clang
does this. But, if one of libclang* libraries is built by passing STATIC
and SHARED to llvm_add_library clang compiles and links just fine, but
when it is run we get an error:
$ ./bin/clang --version
: CommandLine Error: Option 'use-dbg-addr' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options
This happens because there are two copies of libLLVM, the static version
linked to the statically linked libclang*.a libraries and the shared
version linked to the shared libclangXxx.so.
Solution:
Use ${name} for the STATIC library and ${name}_shared for the SHARED
library. With this change even if both STATIC and SHARED versions of a
particular library is created ${name} is the static version and there
is no error.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D62033
Files:
llvm/cmake/modules/AddLLVM.cmake
Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -442,20 +442,20 @@
endif()
if(ARG_SHARED AND ARG_STATIC)
- # static
- set(name_static "${name}_static")
+ # SHARED as ${name}_shared STATIC will be ${name}
+ set(name_shared "${name}_shared")
if(ARG_OUTPUT_NAME)
set(output_name OUTPUT_NAME "${ARG_OUTPUT_NAME}")
endif()
# DEPENDS has been appended to LLVM_COMMON_LIBS.
- llvm_add_library(${name_static} STATIC
+ llvm_add_library(${name_shared} SHARED
${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)
+ # FIXME: Add name_shared to anywhere in TARGET ${name}'s PROPERTY.
+ set(ARG_SHARED)
endif()
if(ARG_MODULE)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62033.199903.patch
Type: text/x-patch
Size: 999 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190516/5cee5275/attachment.bin>
More information about the llvm-commits
mailing list