<div dir="ltr">The <a href="https://cmake.org/cmake/help/latest/prop_tgt/IOS_INSTALL_COMBINED.html">IOS_INSTALL_COMBINED</a> target property allows you to create fat binaries, but only at install time. To use this feature, set your CMAKE_OSX_SYSROOT to <font face="monospace, monospace">iphoneos</font> and the simulator slice will be built and added to the fat binary for you automatically during the install step. If you require fat binaries at build time, that could be much more challenging.<div><br></div><div><br><div class="gmail_quote"><div dir="ltr">On Mon, Nov 19, 2018 at 10:19 PM Erik van Nooijen <<a href="mailto:Eric.vanNooijen@tomtom.com">Eric.vanNooijen@tomtom.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="m_-5570285802169666805WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">With CMake it is possible to build for fat binaries for iOS without XCode. Fat binaries meaning containing all the architectures
for iPhone and iPhoneSimulator.</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">However, when building frameworks, CMake builds it with the MacOSX layout, including '<i>Version</i>' directory and symlinks etc. This is wrong when building for iOS.</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">The reason is that CMake determines bundle layout based on CMAKE_OSX_SYSROOT, but this cannot be set correctly in this situation, as it allows only one directory to be
set, and we'd need two (iPhone and iPhoneSimulator). In short:</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">* not setting CMAKE_OSX_SYSROOT results in MacOSX framework/bundle layouts</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">* setting CMAKE_OSX_SYSROOT to a single sysroot gives error for the other architecture(s)</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> ld: dynamic main executables must link with libSystem.dylib for architecture i386</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">* setting CMAKE_OSX_SYSROOT to multiple sysroots gives error for incorrect paths</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> Ignoring CMAKE_OSX_SYSROOT value:</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.1.sdk;/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.1.sdk</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> because the directory does not exist.</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">Please find below an example CMakeLists.txt to test/verify this. The behaviour can be switched on and off with the MAKE_FAT variable.</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">What is the correct way to get fat binaries in the correct iOS layout in such a case?</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">cmake_minimum_required(VERSION 3.13)</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">project(iOSFatBinaries)</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">set(MAKE_FAT TRUE)</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">execute_process(COMMAND xcodebuild -version -sdk iphoneos Path COMMAND perl -ne "chomp;print;exit;" OUTPUT_VARIABLE SDK_IPHONE_ROOT)</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">execute_process(COMMAND xcodebuild -version -sdk iphonesimulator Path COMMAND perl -ne "chomp;print;exit;" OUTPUT_VARIABLE SDK_IPHONE_SIMULATOR_ROOT)</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""># CMAKE_OSX_ARCHITECTURES</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">if(MAKE_FAT)</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> set(CMAKE_OSX_ARCHITECTURES "armv7;armv7s;arm64;i386;x86_64" CACHE INTERNAL "Set supported OSX architectures")</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">else()</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> set(CMAKE_OSX_ARCHITECTURES "armv7;armv7s;arm64" CACHE INTERNAL "Set supported OSX architectures")</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">endif()</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""># CMAKE_C_FLAGS and CMAKE_CXX_FLAGS</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">if(MAKE_FAT)</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> set(SYSROOT_FLAGS " -arch armv7 -Xarch_armv7 \"-isysroot${SDK_IPHONE_ROOT}\"")</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> set(SYSROOT_FLAGS "${SYSROOT_FLAGS} -arch armv7s -Xarch_armv7s \"-isysroot${SDK_IPHONE_ROOT}\"")</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> set(SYSROOT_FLAGS "${SYSROOT_FLAGS} -arch arm64 -Xarch_arm64 \"-isysroot${SDK_IPHONE_ROOT}\"")</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> set(SYSROOT_FLAGS "${SYSROOT_FLAGS} -arch i386 -Xarch_i386 \"-isysroot${SDK_IPHONE_SIMULATOR_ROOT}\"")</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> set(SYSROOT_FLAGS "${SYSROOT_FLAGS} -arch x86_64 -Xarch_x86_64 \"-isysroot${SDK_IPHONE_SIMULATOR_ROOT}\"")</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SYSROOT_FLAGS}" CACHE INTERNAL "CMake C Compiler Flags")</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SYSROOT_FLAGS}" CACHE INTERNAL "CMake CXX Compiler Flags")</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">else()</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch armv7 -arch armv7s -arch arm64")</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch armv7 -arch armv7s -arch arm64")</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">endif()</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""># CMAKE_CXX_FLAGS</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">if(MAKE_FAT)</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> set(CMAKE_OSX_SYSROOT "" CACHE INTERNAL "sysroot" FORCE)</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">else()</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> set(CMAKE_OSX_SYSROOT ${SDK_IPHONE_ROOT} CACHE INTERNAL "sysroot" FORCE)</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">endif()</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">add_library(${PROJECT_NAME} SHARED</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> lib.h</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> lib.cpp</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">)</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""># Framework properties</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">set_target_properties(${PROJECT_NAME} PROPERTIES</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> FRAMEWORK TRUE</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> FORCE_IOS_BUNDLE_LAYOUT TRUE</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> MACOSX_FRAMEWORK_IDENTIFIER ${PROJECT_NAME}</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> MACOSX_FRAMEWORK_BUNDLE_VERSION 1.0</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> MACOSX_FRAMEWORK_SHORT_VERSION_STRING 1.0</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> MACOSX_FRAMEWORK_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/<a href="http://Info.plist.in" target="_blank">Info.plist.in</a></span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> PUBLIC_HEADER lib.h</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">)</span><u></u><u></u></p>
</div>
</div><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr">Craig Scott<br><div>Melbourne, Australia</div><div><a href="https://crascit.com" target="_blank">https://crascit.com</a><br></div><div><br></div><div>New book released: <a href="https://crascit.com/professional-cmake/" target="_blank">Professional CMake: A Practical Guide</a><br></div></div></div></div></div></div></div></div></div>