Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Commit

Permalink
Fix issues building libraries as more than one type with Xcode
Browse files Browse the repository at this point in the history
Summary:
CMake+Xcode doesn't seem to handle targets that only have object
sources. This patch works around that limitation by adding a dummy
soruce file to any library target that is generated by llvm_add_library
when object libraries are generated.

Object libraries are generated whenever llvm_add_library is passed more
than one library type, which is now the default case for clang static
libraries (which generate STATIC and OBJECT libraries).

Reviewers: zturner, compnerd, joanlluch

Reviewed By: joanlluch

Subscribers: joanlluch, xbolva00, mgorny, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D64300

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365365 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
llvm-beanz committed Jul 8, 2019
1 parent faeff09 commit 9a276df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ if ((CMAKE_GENERATOR MATCHES "Visual Studio") AND (CMAKE_GENERATOR_TOOLSET STREQ
"host compiler, pass -Thost=x64 on the CMake command line.")
endif()

if (CMAKE_GENERATOR STREQUAL "Xcode" AND NOT CMAKE_OSX_ARCHITECTURES)
# Some CMake features like object libraries get confused if you don't
# explicitly specify an architecture setting with the Xcode generator.
set(CMAKE_OSX_ARCHITECTURES "x86_64")
endif()

project(LLVM
VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}
LANGUAGES C CXX ASM)
Expand Down
7 changes: 6 additions & 1 deletion cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,12 @@ function(llvm_add_library name)
${ALL_FILES}
)
llvm_update_compile_flags(${obj_name})
set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>")
if(CMAKE_GENERATOR STREQUAL "Xcode")
set(DUMMY_FILE ${CMAKE_CURRENT_BINARY_DIR}/Dummy.c)
file(WRITE ${DUMMY_FILE} "// This file intentionally empty\n")
set_property(SOURCE ${DUMMY_FILE} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-empty-translation-unit")
endif()
set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>" ${DUMMY_FILE})

# Do add_dependencies(obj) later due to CMake issue 14747.
list(APPEND objlibs ${obj_name})
Expand Down

0 comments on commit 9a276df

Please sign in to comment.