📜 ⬆️ ⬇️

Building FreeType2 for iOS

imageimage
There are many notes on the Internet on how to build freetype for iOS.
All these notes are united by a common characteristic - they do not work.
The fact is that all the instructions operate on gcc for building the library, but since XCode 5, gcc is not included in the delivery and you need to use clang for building on iOS.
There are no notes on how to compile correctly.
We correct this injustice.


Preparation for assembly


It is assumed that XCode is already downloaded and configured.
Freetype is based on sourceforge , and from there we take it.
We do not forget to unpack the received archive.

To build a universal library, we will need to repeat the compilation of the library with different parameters 5 times.
All instructions are executed from the root directory freetype.
')
i386


$ ./configure --enable-static = yes --enable-shared = no CC = / Applications / Xcode.app / Contents / Developer / Toolchains / XcodeDefault.xctoolchain / usr / bin / cc CFLAGS = "- arch i386 -Wno -extended-offsetof -miphoneos-version-min = 4.2 -I / Applications / Xcode.app / Contents / Developer / Platforms / iPhoneSimulator.platform / Developer / SDKs / iPhoneSimulator7.1.sdk / usr / include -isysroot / Applications / Xcode .app / Contents / Developer / Platforms / iPhoneSimulator.platform / Developer / SDKs / iPhoneSimulator7.1.sdk "CPP = / Applications / Xcode.app / Contents / Developer / Toolchains / XcodeDefault.xctoolchain / usr / bin / cpp AR = / Applications / Xcode.app / Contents / Developer / Toolchains / XcodeDefault.xctoolchain / usr / bin / ar LDFLAGS = "- arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/ iPhoneSimulator7.1.sdk -miphoneos-version-min = 4.2 "
$ make

With these commands, we set up the build for i386 architecture and build the library. The resulting library will be located in the objs / .libs / libfreetype.a directory
Rename the resulting library and copy it to the root. We will need it at the last step of the assembly.

$ cp objs / .libs / libfreetype.a libfreetype-i386.a

x86_64


Similarly, we build under x86_64, add the make clean command to get rid of the results of the previous build

$ ./configure --enable-static = yes --enable-shared = no CC = / Applications / Xcode.app / Contents / Developer / Toolchains / XcodeDefault.xctoolchain / usr / bin / cc CFLAGS = "- arch x86_64 -Wno -extended-offsetof -miphoneos-version-min = 4.2 -I / Applications / Xcode.app / Contents / Developer / Platforms / iPhoneSimulator.platform / Developer / SDKs / iPhoneSimulator7.1.sdk / usr / include -isysroot / Applications / Xcode .app / Contents / Developer / Platforms / iPhoneSimulator.platform / Developer / SDKs / iPhoneSimulator7.1.sdk "CPP = / Applications / Xcode.app / Contents / Developer / Toolchains / XcodeDefault.xctoolchain / usr / bin / cpp AR = / Applications / Xcode.app / Contents / Developer / Toolchains / XcodeDefault.xctoolchain / usr / bin / ar LDFLAGS = "- arch x86_64 -isysroot / Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/ iPhoneSimulator7.1.sdk -miphoneos-version-min = 4.2 "; make clean; make
$ cp objs / .libs / libfreetype.a libfreetype-x86_64.a


armv7

armv7 is used in iPhone 3GS, iPhone 4, iPhone 4S. We add parameters for cross-compilation.

$ ./configure --host = arm-apple-darwin --enable-static = yes --enable-shared = no CC = / Applications / Xcode.app / Contents / Developer / Toolchains / XcodeDefault.xctoolchain / usr / bin / cc CFLAGS = "- arch armv7 -pipe -std = c99 -Wno-extended-offsetof -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length = 0 -fvisibility = hidden -miphoneos- version-min = 4.2 -I / Applications / Xcode.app / Contents / Developer / Platforms / iPhoneOS.platform / Developer / SDKs / iPhoneOS7.1.sdk / usr / include -isysroot / Apps / Xcode.app/Contents/Developer/ Platforms / iPhoneOS.platform / Developer / SDKs / iPhoneOS7.1.sdk "AR = / Applications / Xcode.app / Contents / Developer / Toolchains / XcodeDefault.xctoolchain / usr / bin / ar LDFLAGS =" - arch armv7 -isysroot / Applications /Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk -miphoneos-version-min = 4.2 "
$ make clean; make
$ cp objs / .libs / libfreetype.a libfreetype-arm7.a


armv7s

armv7s is used in iphone 5, iphone 5s. The configuration is minimal.

$ ./configure --host = arm-apple-darwin --enable-static = yes --enable-shared = no CC = / Applications / Xcode.app / Contents / Developer / Toolchains / XcodeDefault.xctoolchain / usr / bin / cc CFLAGS = "- arch armv7s -pipe -std = c99 -Wno-extended-offsetof -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length = 0 -fvisibility = hidden -miphoneos- version-min = 5.0 -I / Applications / Xcode.app / Contents / Developer / Platforms / iPhoneOS.platform / Developer / SDKs / iPhoneOS7.1.sdk / usr / include -isysroot / Apps / Xcode.app/Contents/Developer/ Platforms / iPhoneOS.platform / Developer / SDKs / iPhoneOS7.1.sdk "AR = / Applications / Xcode.app / Contents / Developer / Toolchains / XcodeDefault.xctoolchain / usr / bin / ar LDFLAGS =" - arch armv7s -isysroot / Applications /Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk -miphoneos-version-min = 5.0 "
$ make clean; make
$ cp objs / .libs / libfreetype.a libfreetype-arm7s.a


arm64

arm64 - the most current architecture at the time of this writing.

$ ./configure --host = arm-apple-darwin --enable-static = yes --enable-shared = no CC = / Applications / Xcode.app / Contents / Developer / Toolchains / XcodeDefault.xctoolchain / usr / bin / cc CFLAGS = "- arch arm64 -pipe -std = c99 -Wno-extended-offsetof -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length = 0 -fvisibility = hidden -miphoneos- version-min = 6.0 -I / Applications / Xcode.app / Contents / Developer / Platforms / iPhoneOS.platform / Developer / SDKs / iPhoneOS7.1.sdk / usr / include -isysroot / Apps / Xcode.app/Contents/Developer/ Platforms / iPhoneOS.platform / Developer / SDKs / iPhoneOS7.1.sdk "AR = / Applications / Xcode.app / Contents / Developer / Toolchains / XcodeDefault.xctoolchain / usr / bin / ar LDFLAGS =" - arch arm64 -isysroot / Applications /Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk -miphoneos-version-min = 6.0 "
$ make clean; make
$ cp objs / .libs / libfreetype.a libfreetype-arm64.a


Important

Do not forget to change iPhoneOS7.1.sdk to the version of sdk that you have installed now. 7.1 is the current version at the time of this writing, but updates are released quite often and, it is likely that by the time you read this instruction, the version has already changed.

Building a universal library

We have 5 separate libraries at the root.
We need to collect them in one universal library. To do this, use the lipo tool.

$ lipo -create -output libfreetype.a libfreetype-i386.a libfreetype-x86_64.a libfreetype-arm7.a libfreetype-arm7s.a libfreetype-arm64.a

Now there is a long-awaited libfreetype.a that supports all the architectures we need.

Well that's all. Add the resulting library to your Xcode project and work with it!
Good luck!

Source: https://habr.com/ru/post/216759/


All Articles