r373769 - [CMake] Clang: Don't use object libraries with Xcode

Jordan Rose via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 4 11:17:58 PDT 2019


Author: jrose
Date: Fri Oct  4 11:17:58 2019
New Revision: 373769

URL: http://llvm.org/viewvc/llvm-project?rev=373769&view=rev
Log:
[CMake] Clang: Don't use object libraries with Xcode

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

Modified:
    cfe/trunk/cmake/modules/AddClang.cmake
    cfe/trunk/tools/clang-shlib/CMakeLists.txt

Modified: cfe/trunk/cmake/modules/AddClang.cmake
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/AddClang.cmake?rev=373769&r1=373768&r2=373769&view=diff
==============================================================================
--- cfe/trunk/cmake/modules/AddClang.cmake (original)
+++ cfe/trunk/cmake/modules/AddClang.cmake Fri Oct  4 11:17:58 2019
@@ -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()

Modified: cfe/trunk/tools/clang-shlib/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/CMakeLists.txt?rev=373769&r1=373768&r2=373769&view=diff
==============================================================================
--- cfe/trunk/tools/clang-shlib/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-shlib/CMakeLists.txt Fri Oct  4 11:17:58 2019
@@ -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 ()




More information about the cfe-commits mailing list