Skip to content

Commit ba716b3

Browse files
authored
Merge pull request #97 from leetal/dev
Experimental macOS & Catalyst support, experimental Apple Silicon support + Bugfixes
2 parents ebb1619 + 5b99674 commit ba716b3

File tree

7 files changed

+254
-129
lines changed

7 files changed

+254
-129
lines changed

README.md

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
A CMake toolchain file for iOS, watchOS and tvOS development with full simulator support and toggable options!
1+
A CMake toolchain file for iOS (+ Catalyst), watchOS, tvOS and macOS development with full simulator support and toggleable options!
22

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

68
ios-cmake
79
=========
@@ -14,42 +16,55 @@ Tested with the following combinations:
1416
* XCode 10.2, iOS SDK 12.2
1517
* XCode 11.1, iOS SDK 13.1
1618
* XCode 11.3, iOS SDK 13.3
17-
* XCode 12.2, iOS SDK 14.2
19+
* XCode 12.4, iOS/iPadOS SDK 14.4, tvOS 14.3, watchOS 7.2, macOS SDK 11.1
20+
21+
## Platform flag options (-DPLATFORM=_flag_)
22+
23+
* _OS_ - to build for iOS (armv7, armv7s, arm64) **DEPRECATED in favour of OS64**
24+
* _OS64_ - to build for iOS (arm64 only)
25+
* _OS64COMBINED_ - to build for iOS & iOS Simulator (FAT lib) (arm64, x86_64)
26+
* _SIMULATOR_ - to build for iOS simulator 32 bit (i386) **DEPRECATED**
27+
* _SIMULATOR64_ - to build for iOS simulator 64 bit (x86_64)
28+
* _SIMULATORARM64_ - to build for iOS simulator 64 bit (arm64)
29+
* _TVOS_ - to build for tvOS (arm64)
30+
* _TVOSCOMBINED_ - to build for tvOS & tvOS Simulator (arm64, x86_64)
31+
* _SIMULATOR_TVOS_ - to build for tvOS Simulator (x86_64)
32+
* _WATCHOS_ - to build for watchOS (armv7k, arm64_32)
33+
* _WATCHOSCOMBINED_ - to build for watchOS & Simulator (armv7k, arm64_32, i386)
34+
* _SIMULATOR_WATCHOS_ - to build for watchOS Simulator (i386)
35+
* _MAC_ - to build for macOS (x86_64)
36+
* _MAC_ARM64_ - to build for macOS on Apple Silicon (arm64)
37+
* _MAC_CATALYST_ - to build iOS for Mac (Catalyst, x86_64)
38+
* _MAC_CATALYST_ARM64_ - to build iOS for Mac on Apple Silicon (Catalyst, arm64)
1839

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

2243
```bash
2344
cd example/example-lib
2445
mkdir build
2546
cd build
26-
cmake .. -G Xcode -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake -DPLATFORM=OS64COMBINED
27-
cmake --build . --config Release --target install
47+
cmake .. -G Xcode -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake -DPLATFORM=OS64
48+
cmake --build . --config Release
2849
```
2950

30-
This will build and install the library for the given IOS_PLATFORM.
31-
32-
## Options
33-
34-
* Set `-DPLATFORM` to "SIMULATOR" to build for iOS simulator 32 bit (i386) **DEPRECATED**
35-
* Set `-DPLATFORM` to "SIMULATOR64" (example above) to build for iOS simulator 64 bit (x86_64)
36-
* Set `-DPLATFORM` to "SIMULATORARM64" to build for iOS simulator 64 bit (arm64)
37-
* Set `-DPLATFORM` to "OS" to build for Device (armv7, armv7s, arm64)
38-
* Set `-DPLATFORM` to "OS64" to build for Device (arm64)
39-
* Set `-DPLATFORM` to "OS64COMBINED" to build for Device & Simulator (FAT lib) (arm64, x86_64)
40-
* Set `-DPLATFORM` to "TVOS" to build for tvOS (arm64)
41-
* Set `-DPLATFORM` to "TVOSCOMBINED" to build for tvOS & Simulator (arm64, x86_64)
42-
* Set `-DPLATFORM` to "SIMULATOR_TVOS" to build for tvOS Simulator (x86_64)
43-
* Set `-DPLATFORM` to "WATCHOS" to build for watchOS (armv7k, arm64_32)
44-
* Set `-DPLATFORM` to "WATCHOSCOMBINED" to build for watchOS & Simulator (armv7k, arm64_32, i386)
45-
* Set `-DPLATFORM` to "SIMULATOR_WATCHOS" to build for watchOS Simulator (i386)
51+
This will build and install the library for the given PLATFORM. In this case, iOS with the arm64 architecture.
4652

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

52-
**NOTE: The COMBINED options _ONLY_ work with the Xcode generator (-G Xcode), together with a install-target (see example above).**
58+
Example:
59+
```bash
60+
cmake . -G Xcode -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake -DPLATFORM=OS64COMBINED
61+
cmake --build . --config Release
62+
cmake --install . --config Release
63+
```
64+
65+
**_NOTE_: The COMBINED options _ONLY_ work with the Xcode generator (-G Xcode) on CMake versions 3.14+!**
66+
67+
---
5368

5469
### Exposed Variables
5570
`XCODE_VERSION` - Version number (not including Build version) of Xcode detected.
@@ -78,8 +93,4 @@ LIPO tool. More information on how to combine libraries with LIPO is readily ava
7893

7994
* [natbro](https://github.com/natbro) for adding tvOS support
8095
* [MSNexploder](https://github.com/MSNexploder) for adding OS64 and arm64e support
81-
* [garryyan](https://github.com/garryyan) for adding watchOS support
82-
83-
## Notes
84-
85-
Parts of the original toolchain comes from a similar project found on code.google.com
96+
* [garryyan](https://github.com/garryyan) for adding watchOS support
-28 KB
Binary file not shown.

example/example-lib/CMakeLists.txt

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,33 @@ else()
1313
message(STATUS "kqueue found!")
1414
endif()
1515

16-
find_library(HAVE_UIKIT UIKit)
17-
if (NOT HAVE_UIKIT)
18-
message(FATAL_ERROR "UIKit.framework NOT found!")
16+
if(PLATFORM MATCHES "(MAC|MAC_ARM64)")
17+
find_library(HAVE_APPKIT AppKit)
18+
if (NOT HAVE_APPKIT)
19+
message(FATAL_ERROR "AppKit.framework NOT found!")
20+
else()
21+
message(STATUS "AppKit.framework found!")
22+
endif()
23+
elseif(PLATFORM MATCHES "(MAC_CATALYST|MAC_CATALYST_ARM64)")
24+
find_library(HAVE_APPKIT AppKit)
25+
if (NOT HAVE_APPKIT)
26+
message(FATAL_ERROR "AppKit.framework NOT found!")
27+
else()
28+
message(STATUS "AppKit.framework found!")
29+
endif()
30+
find_library(HAVE_UIKIT UIKit)
31+
if (NOT HAVE_UIKIT)
32+
message(FATAL_ERROR "UIKit.framework NOT found!")
33+
else()
34+
message(STATUS "UIKit.framework found!")
35+
endif()
1936
else()
20-
message(STATUS "UIKit.framework found!")
37+
find_library(HAVE_UIKIT UIKit)
38+
if (NOT HAVE_UIKIT)
39+
message(FATAL_ERROR "UIKit.framework NOT found!")
40+
else()
41+
message(STATUS "UIKit.framework found!")
42+
endif()
2143
endif()
2244

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

6385
# Executable
64-
#add_executable (helloworld main.cpp)
65-
66-
# Link the library with the executable
67-
#target_link_libraries(helloworld example)
86+
if(PLATFORM MATCHES "MAC.*")
87+
add_executable (helloworld main.cpp)
88+
# Link the library with the executable
89+
target_link_libraries(helloworld example)
90+
endif()
6891

6992
# Debug symbols set in XCode project
7093
set_xcode_property(example GCC_GENERATE_DEBUGGING_SYMBOLS YES "All")

example/example-lib/HelloWorld.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#include "HelloWorld.hpp"
2+
#include <TargetConditionals.h>
23

34
std::string HelloWorld::helloWorld()
45
{
5-
return std::string("Hello World");
6+
#if TARGET_OS_MACCATALYST
7+
return std::string("Hello World from Mac Catalyst");
8+
#elif TARGET_OS_MAC
9+
return std::string("Hello World from macOS");
10+
#elif TARGET_OS_IPHONE
11+
return std::string("Hello World from iOS");
12+
#endif
13+
return std::string("Hello World from an unknown platform");
614
}

example/example-lib/HelloWorldIOS.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ @implementation HelloWorldIOS
77

88
- (NSString*)getHelloWorld
99
{
10-
NSString *text = [NSString stringWithUTF8String: _h.helloWorld().c_str()];
11-
return text;
10+
return [NSString stringWithUTF8String: _h.helloWorld().c_str()];
1211
}
1312

1413
@end

example/example-lib/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
int main(int argc, char** argv)
66
{
77
HelloWorld hw;
8-
std::cout << hw.helloWorld() << std::endl;;
8+
std::cout << hw.helloWorld() << std::endl;
99
}

0 commit comments

Comments
 (0)