From 8484a1204cf6dda9825f55ba778c932525bd9943 Mon Sep 17 00:00:00 2001 From: James Zern Date: Thu, 19 Nov 2020 18:41:03 -0800 Subject: [PATCH] cmake: fix compilation w/Xcode generator Add a stub file to object only library targets. https://cmake.org/cmake/help/v3.18/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 $. Bug: webp:477 Change-Id: I5d404c921d84433c7a0b22e0736ab0dbe699d264 --- CMakeLists.txt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d2dadf79..19e7a71c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,6 +164,29 @@ add_definitions(-DHAVE_CONFIG_H) # ############################################################################## # Build the webpdecoder library. + +# Creates a source file with an unused stub function in $CMAKE_BINARY_DIR and +# adds it to the specified target. Currently used only with Xcode. +# +# See also: +# https://cmake.org/cmake/help/v3.18/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 $." +function(libwebp_add_stub_file TARGET) + set(stub_source_dir "${CMAKE_BINARY_DIR}") + set(stub_source_file + "${stub_source_dir}/libwebp_${TARGET}_stub.c") + set(stub_source_code + "// Generated file. DO NOT EDIT!\n" + "// C source file created for target ${TARGET}.\n" + "void libwebp_${TARGET}_stub_function(void)\;\n" + "void libwebp_${TARGET}_stub_function(void) {}\n") + file(WRITE "${stub_source_file}" ${stub_source_code}) + + target_sources(${TARGET} PRIVATE ${stub_source_file}) +endfunction() + if(MSVC) # avoid security warnings for e.g., fopen() used in the examples. add_definitions(-D_CRT_SECURE_NO_WARNINGS) @@ -190,6 +213,9 @@ add_library(webpdecoder $ $ $) +if(XCODE) + libwebp_add_stub_file(webpdecoder) +endif() target_link_libraries(webpdecoder ${WEBP_DEP_LIBRARIES}) target_include_directories( webpdecoder @@ -229,6 +255,9 @@ add_library(webp $ $ $) +if(XCODE) + libwebp_add_stub_file(webp) +endif() target_link_libraries(webp ${WEBP_DEP_LIBRARIES}) target_include_directories(webp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}