Skip to content

Commit

Permalink
Support for CMake Object Library in XCode build.
Browse files Browse the repository at this point in the history
  • Loading branch information
gegles authored and rndi committed Oct 30, 2018
1 parent 69279a6 commit 8c60631
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,13 @@ endif()
# Make the OBJECT library for haicrypt and srt. Then they'll be bound into
# real libraries later, either one common, or separate.

# This is needed for Xcode to properly handle CMake OBJECT Libraries
# From docs (https://cmake.org/cmake/help/latest/command/add_library.html#object-libraries):
#
# ... Some native build systems (such as Xcode) may not like targets that have only object files,
# so consider adding at least one real source file to any target that references $<TARGET_OBJECTS:objlib>.
set(OBJECT_LIB_SUPPORT "${PROJECT_SOURCE_DIR}/cmake_object_lib_support.c")

add_library(haicrypt_virtual OBJECT ${SOURCES_haicrypt} ${SOURCES_common})

# NOTE: The "virtual library" is a library specification that cmake
Expand Down Expand Up @@ -462,7 +469,7 @@ endif()
set (VIRTUAL_srt $<TARGET_OBJECTS:srt_virtual> $<TARGET_OBJECTS:haicrypt_virtual>)

if (srt_libspec_shared)
add_library(${TARGET_srt}_shared SHARED ${VIRTUAL_srt})
add_library(${TARGET_srt}_shared SHARED ${OBJECT_LIB_SUPPORT} ${VIRTUAL_srt})
# shared libraries need PIC
set_property(TARGET ${TARGET_srt}_shared PROPERTY OUTPUT_NAME ${TARGET_srt})
set_target_properties (${TARGET_srt}_shared PROPERTIES VERSION ${SRT_VERSION} SOVERSION ${SRT_VERSION_MAJOR})
Expand All @@ -476,7 +483,7 @@ if (srt_libspec_shared)
endif()

if (srt_libspec_static)
add_library(${TARGET_srt}_static STATIC ${VIRTUAL_srt})
add_library(${TARGET_srt}_static STATIC ${OBJECT_LIB_SUPPORT} ${VIRTUAL_srt})

# For Windows, leave the name to be "srt_static.lib".
# Windows generates two different library files:
Expand Down
9 changes: 9 additions & 0 deletions cmake_object_lib_support.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// DO NOT DELETE
// This file is needed for Xcode to properly handle CMake OBJECT Libraries
// From docs (https://cmake.org/cmake/help/latest/command/add_library.html#object-libraries):
//
// ... Some native build systems (such as Xcode) may not like targets that have only object files,
// so consider adding at least one real source file to any target that references $<TARGET_OBJECTS:objlib>.

// Just a dummy symbol to avoid compiler warnings
int srt_object_lib_dummy = 0;

0 comments on commit 8c60631

Please sign in to comment.