Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
[CMake] Clang: Don't use object libraries with Xcode (#363)
Browse files Browse the repository at this point in the history
Undoes some of the effects of r360946 when using the Xcode CMake
generator---it doesn't handle object libraries correctly at all.
Attempts to still honor BUILD_SHARED_LIBS for Xcode, but I didn't
actually test it. Should have no effect on non-Xcode generators.

https://reviews.llvm.org/D68430

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373769 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
jrose-apple authored Oct 7, 2019
1 parent b73ce4d commit 7c4fe05
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions cmake/modules/AddClang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ macro(add_clang_library name)
# llvm_add_library ignores BUILD_SHARED_LIBS if STATIC is explicitly set,
# so we need to handle it here.
if(BUILD_SHARED_LIBS)
set(LIBTYPE SHARED OBJECT)
set(LIBTYPE SHARED)
else()
set(LIBTYPE STATIC OBJECT)
set(LIBTYPE STATIC)
endif()
if(NOT XCODE)
# The Xcode generator doesn't handle object libraries correctly.
list(APPEND LIBTYPE OBJECT)
endif()
set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
endif()
Expand Down
8 changes: 7 additions & 1 deletion tools/clang-shlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ endif()
get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS)

foreach (lib ${clang_libs})
list(APPEND _OBJECTS $<TARGET_OBJECTS:obj.${lib}>)
if(XCODE)
# Xcode doesn't support object libraries, so we have to trick it into
# linking the static libraries instead.
list(APPEND _DEPS "-force_load" ${lib})
else()
list(APPEND _OBJECTS $<TARGET_OBJECTS:obj.${lib}>)
endif()
list(APPEND _DEPS $<TARGET_PROPERTY:${lib},INTERFACE_LINK_LIBRARIES>)
list(APPEND _DEPS $<TARGET_PROPERTY:${lib},LINK_LIBRARIES>)
endforeach ()
Expand Down

0 comments on commit 7c4fe05

Please sign in to comment.