Skip to content

Commit

Permalink
Merge pull request leetal#97 from leetal/dev
Browse files Browse the repository at this point in the history
Experimental macOS & Catalyst support, experimental Apple Silicon support + Bugfixes
  • Loading branch information
leetal authored Mar 1, 2021
2 parents ebb1619 + 5b99674 commit ba716b3
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 129 deletions.
67 changes: 39 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
A CMake toolchain file for iOS, watchOS and tvOS development with full simulator support and toggable options!
A CMake toolchain file for iOS (+ Catalyst), watchOS, tvOS and macOS development with full simulator support and toggleable options!

### NEW!
* Now exposes Autoconf compatible triples, accessible via the `APPLE_TARGET_TRIPLE` variable.
* Experimental Catalyst support (iOS on macOS)
* macOS support and experimental Apple Silicon support
* Deprecated options now removed.

ios-cmake
=========
Expand All @@ -14,42 +16,55 @@ Tested with the following combinations:
* XCode 10.2, iOS SDK 12.2
* XCode 11.1, iOS SDK 13.1
* XCode 11.3, iOS SDK 13.3
* XCode 12.2, iOS SDK 14.2
* XCode 12.4, iOS/iPadOS SDK 14.4, tvOS 14.3, watchOS 7.2, macOS SDK 11.1

## Platform flag options (-DPLATFORM=_flag_)

* _OS_ - to build for iOS (armv7, armv7s, arm64) **DEPRECATED in favour of OS64**
* _OS64_ - to build for iOS (arm64 only)
* _OS64COMBINED_ - to build for iOS & iOS Simulator (FAT lib) (arm64, x86_64)
* _SIMULATOR_ - to build for iOS simulator 32 bit (i386) **DEPRECATED**
* _SIMULATOR64_ - to build for iOS simulator 64 bit (x86_64)
* _SIMULATORARM64_ - to build for iOS simulator 64 bit (arm64)
* _TVOS_ - to build for tvOS (arm64)
* _TVOSCOMBINED_ - to build for tvOS & tvOS Simulator (arm64, x86_64)
* _SIMULATOR_TVOS_ - to build for tvOS Simulator (x86_64)
* _WATCHOS_ - to build for watchOS (armv7k, arm64_32)
* _WATCHOSCOMBINED_ - to build for watchOS & Simulator (armv7k, arm64_32, i386)
* _SIMULATOR_WATCHOS_ - to build for watchOS Simulator (i386)
* _MAC_ - to build for macOS (x86_64)
* _MAC_ARM64_ - to build for macOS on Apple Silicon (arm64)
* _MAC_CATALYST_ - to build iOS for Mac (Catalyst, x86_64)
* _MAC_CATALYST_ARM64_ - to build iOS for Mac on Apple Silicon (Catalyst, arm64)

# Example usage
**NOTE: The below commands will build for 64-bit simulator only. Change the `-DPLATFORM` to the applicable value if targeting another platform.**
**_NOTE_: Change the `-DPLATFORM` to an applicable value if targeting another platform.**

```bash
cd example/example-lib
mkdir build
cd build
cmake .. -G Xcode -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake -DPLATFORM=OS64COMBINED
cmake --build . --config Release --target install
cmake .. -G Xcode -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake -DPLATFORM=OS64
cmake --build . --config Release
```

This will build and install the library for the given IOS_PLATFORM.

## Options

* Set `-DPLATFORM` to "SIMULATOR" to build for iOS simulator 32 bit (i386) **DEPRECATED**
* Set `-DPLATFORM` to "SIMULATOR64" (example above) to build for iOS simulator 64 bit (x86_64)
* Set `-DPLATFORM` to "SIMULATORARM64" to build for iOS simulator 64 bit (arm64)
* Set `-DPLATFORM` to "OS" to build for Device (armv7, armv7s, arm64)
* Set `-DPLATFORM` to "OS64" to build for Device (arm64)
* Set `-DPLATFORM` to "OS64COMBINED" to build for Device & Simulator (FAT lib) (arm64, x86_64)
* Set `-DPLATFORM` to "TVOS" to build for tvOS (arm64)
* Set `-DPLATFORM` to "TVOSCOMBINED" to build for tvOS & Simulator (arm64, x86_64)
* Set `-DPLATFORM` to "SIMULATOR_TVOS" to build for tvOS Simulator (x86_64)
* Set `-DPLATFORM` to "WATCHOS" to build for watchOS (armv7k, arm64_32)
* Set `-DPLATFORM` to "WATCHOSCOMBINED" to build for watchOS & Simulator (armv7k, arm64_32, i386)
* Set `-DPLATFORM` to "SIMULATOR_WATCHOS" to build for watchOS Simulator (i386)
This will build and install 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!

**NOTE: The COMBINED options _ONLY_ work with the Xcode generator (-G Xcode), together with a install-target (see example above).**
Example:
```bash
cmake . -G Xcode -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake -DPLATFORM=OS64COMBINED
cmake --build . --config Release
cmake --install . --config Release
```

**_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.
Expand Down Expand Up @@ -78,8 +93,4 @@ LIPO tool. More information on how to combine libraries with LIPO is readily ava

* [natbro](https://github.com/natbro) for adding tvOS support
* [MSNexploder](https://github.com/MSNexploder) for adding OS64 and arm64e support
* [garryyan](https://github.com/garryyan) for adding watchOS support

## Notes

Parts of the original toolchain comes from a similar project found on code.google.com
* [garryyan](https://github.com/garryyan) for adding watchOS support
Binary file removed example/example-app/example-lib/lib/libexample.a
Binary file not shown.
39 changes: 31 additions & 8 deletions example/example-lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,33 @@ else()
message(STATUS "kqueue found!")
endif()

find_library(HAVE_UIKIT UIKit)
if (NOT HAVE_UIKIT)
message(FATAL_ERROR "UIKit.framework NOT found!")
if(PLATFORM MATCHES "(MAC|MAC_ARM64)")
find_library(HAVE_APPKIT AppKit)
if (NOT HAVE_APPKIT)
message(FATAL_ERROR "AppKit.framework NOT found!")
else()
message(STATUS "AppKit.framework found!")
endif()
elseif(PLATFORM MATCHES "(MAC_CATALYST|MAC_CATALYST_ARM64)")
find_library(HAVE_APPKIT AppKit)
if (NOT HAVE_APPKIT)
message(FATAL_ERROR "AppKit.framework NOT found!")
else()
message(STATUS "AppKit.framework found!")
endif()
find_library(HAVE_UIKIT UIKit)
if (NOT HAVE_UIKIT)
message(FATAL_ERROR "UIKit.framework NOT found!")
else()
message(STATUS "UIKit.framework found!")
endif()
else()
message(STATUS "UIKit.framework found!")
find_library(HAVE_UIKIT UIKit)
if (NOT HAVE_UIKIT)
message(FATAL_ERROR "UIKit.framework NOT found!")
else()
message(STATUS "UIKit.framework found!")
endif()
endif()

# Hook up XCTest for the supported plaforms (all but WatchOS)
Expand Down Expand Up @@ -61,10 +83,11 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

# Executable
#add_executable (helloworld main.cpp)

# Link the library with the executable
#target_link_libraries(helloworld example)
if(PLATFORM MATCHES "MAC.*")
add_executable (helloworld main.cpp)
# Link the library with the executable
target_link_libraries(helloworld example)
endif()

# Debug symbols set in XCode project
set_xcode_property(example GCC_GENERATE_DEBUGGING_SYMBOLS YES "All")
Expand Down
10 changes: 9 additions & 1 deletion example/example-lib/HelloWorld.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#include "HelloWorld.hpp"
#include <TargetConditionals.h>

std::string HelloWorld::helloWorld()
{
return std::string("Hello World");
#if TARGET_OS_MACCATALYST
return std::string("Hello World from Mac Catalyst");
#elif TARGET_OS_MAC
return std::string("Hello World from macOS");
#elif TARGET_OS_IPHONE
return std::string("Hello World from iOS");
#endif
return std::string("Hello World from an unknown platform");
}
3 changes: 1 addition & 2 deletions example/example-lib/HelloWorldIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ @implementation HelloWorldIOS

- (NSString*)getHelloWorld
{
NSString *text = [NSString stringWithUTF8String: _h.helloWorld().c_str()];
return text;
return [NSString stringWithUTF8String: _h.helloWorld().c_str()];
}

@end
2 changes: 1 addition & 1 deletion example/example-lib/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
int main(int argc, char** argv)
{
HelloWorld hw;
std::cout << hw.helloWorld() << std::endl;;
std::cout << hw.helloWorld() << std::endl;
}
Loading

0 comments on commit ba716b3

Please sign in to comment.