leetal / ios-cmake

A CMake toolchain file for iOS, macOS, watchOS & tvOS C/C++/Obj-C++ development
BSD 3-Clause "New" or "Revised" License
1.82k stars 436 forks source link
c catalyst cmake cmake-scripts cmake-toolchain cpp ios ios-cmake ios-development macos macosx objective-c tvos tvos-cmake tvos-development tvos-simulator watchos watchos-cmake watchos-development

A CMake toolchain file for iOS (+ Catalyst), watchOS, tvOS and macOS development with full simulator support and toggleable options!

ios-cmake

catalyst-jobs   combined-jobs   ios-jobs

macos-jobs   tvos-jobs   watchos-jobs

Platform flag options (-DPLATFORM=flag)

Example usage

NOTE: Change the -DPLATFORM to an applicable value if targeting another platform.

cd example/example-lib
cmake -B build -G Xcode -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake -DPLATFORM=OS64
cmake --build build --config Release

This will build the library for the given PLATFORM. In this case, iOS with the arm64 architecture.

COMBINED Options

The options called *COMBINED (OS64COMBINED, TVOSCOMBINED and WATCHOSCOMBINED) will build complete FAT-libraries for the given platform. These FAT-libraries include slices for both device and simulator, making the distribution and usage of the library much more simple!

Example:

cmake . -G Xcode -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake -DPLATFORM=OS64COMBINED
cmake --build . --config Release
cmake --install . --config Release # Necessary to build combined library

NOTE: The COMBINED options ONLY work with the Xcode generator (-G Xcode) on CMake versions 3.14+!


Exposed Variables

XCODE_VERSION - Version number (not including Build version) of Xcode detected.

SDK_VERSION - Version of SDK being used.

CMAKE_OSX_ARCHITECTURES - Architectures being compiled for (generated from PLATFORM).

APPLE_TARGET_TRIPLE - Used by autoconf build systems.

Additional Options

-DENABLE_BITCODE=(BOOL) - Disabled by default, specify TRUE or 1 to enable bitcode

-DENABLE_ARC=(BOOL) - Enabled by default, specify FALSE or 0 to disable ARC

-DENABLE_VISIBILITY=(BOOL) - Disabled by default, specify TRUE or 1 to enable symbol visibility support

-DENABLE_STRICT_TRY_COMPILE=(BOOL) - Disabled by default, specify TRUE or 1 to enable strict compiler checks (will run linker on all compiler checks whenever needed)

-DARCHS=(STRING) - Valid values are: armv7, armv7s, arm64, i386, x86_64, armv7k, arm64_32. By default it will build for all valid architectures based on -DPLATFORM (see above)

To combine all platforms into the same FAT-library, either build any of the "COMBINED" platform types OR use the LIPO tool. More information on how to combine libraries with LIPO is readily available on the net.

Thanks To