Compiling Freetype 2.6.5 Xcode for IOS
Asked Answered
F

1

7

Alright guys, I posted a similar question and took it down because it wasn't specific enough so here I go. From the zip file of Freetype 2.6.5 I have not been able to create an Xcode project that will compile the library for iOS use, only for i386_64.

I tried the commands here but I don't get past the first commands the and I am getting this

FreeType build system -- automatic system detection

The following settings are used:

platform unix compiler cc
configuration directory ./builds/unix configuration rules
./builds/unix/unix.mk

If this does not correspond to your system or settings please remove the file `config.mk' from this directory then read the INSTALL file for help.

Otherwise, simply type /Applications/Xcode.app/Contents/Developer/usr/bin/make' again to build the library, or /Applications/Xcode.app/Contents/Developer/usr/bin/make refdoc' to build the API reference (this needs python >= 2.6).

cd builds/unix; \ ./configure 'CFLAGS=-arch i386' /bin/sh: ./configure: No such file or directory make: *** [setup] Error 127

I also followed the instructions inside the cmakelists.txt that it comes inside the project but still nothing, I still get an xcode project for osx and not for IOS which is giving me a plethora of linking errors. Here is the instructions for your reference.

For an iOS static library, use #

cmake -D IOS_PLATFORM=OS -G Xcode

#

or

#

cmake -D IOS_PLATFORM=SIMULATOR -G Xcode

I am not sure what else to do. Any help?

Frow answered 15/7, 2016 at 23:41 Comment(9)
Maybe the shell script found here will help. The only reason I suggest this is because on your linked question, there is a comment on this answer stating that using this shell script was the only working solution as of September, 2015Kherson
@iRove108: Unfortunately that script won't work as-is, since the toolchain has moved locations since then. I'll post an updated version though shortly...Centurion
@l'L'l: I'm glad there is someone helping. I only suggested it as I found it in the question that the OP linked, although I have never actually compiled FreeType for IOS :). I thought it might be useful in case the OP did not see the answer at the bottom of the list on the linked question.Kherson
@iRove108: I couldn't agree more; the script has worked well in the past and definitely saves a lot of time.Centurion
Here's the modified build script that will compile the FreeType libraries for iOS. To use simply invoke ./build_freetype.sh in Terminal.Centurion
@l'L'l: I really appreciate the effort. Post it, and I'll choose your answer....Please post some details behind it so I get more insight since I am very new to IOS development.Frow
Sure, not a problem... It might be a bit, I'm starving! :D Let me know how the script works.Centurion
ARE YOU FREAKING KIDDING ME!!! BRO....YOU'RE OUT OF BOUNDS! GREAT JOB! I spent the last 24 hrs breaking my brain around this problem...You just showed me that I really gotta get familiar with how development is done in Unix like OS's (Damn you, Visual Studio! You spoiled me!). Please post an official answer and try to give some insight into why/how it works and this WILL be selected as the answer. Again, GREAT FREAKING JOB!Frow
@l'L'l: I think it worked (see Miguel's comment ;).Kherson
L
7

Here's an outline of the basic build process to compile the FreeType libaries for iOS:

  1. Download the latest FreeType source code
  2. Extract the archive and cd into the unarchived directory
  3. Setup toolchain and export variables for the architectures desired (arm64, arm7, i386, x86_64)
  4. Compile the source code and build the libraries

For example, the build commands for arm64 might look something like this:

$ export CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
$ iphoneos="7.0" # target version of iOS 
$ ARCH="arm64" # architecture (arm64, arm7, i386, x86_64)
$ export CFLAGS="-arch ${ARCH} -pipe -mdynamic-no-pic -Wno-trigraphs -fpascal-strings \
-O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden \
-miphoneos-version-min=$iphoneos -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/libxml2 \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk" 
$ export AR="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar"
$ export LDFLAGS="-arch ${ARCH} -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk \
-miphoneos-version-min=7.0"
$ ./configure --host="aarch64-apple-darwin" --enable-static=yes --enable-shared=no           
$ make     
$ clean

It's a bit of work to construct the commands for each arch, but fortunately there's a build script — which automatically downloads, extracts, and builds the latest FreeType (2.6.5 currently).

To run the script just use the following command in Terminal:

./build_freetype.sh

The resulting iOS libraries can be found in ~/Desktop/FreeType_iOS_Release when it completes.

Litho answered 16/7, 2016 at 16:44 Comment(6)
This answer is going to transcend time! No doubt! I'm tempted to wait until I can put a bounty on it and then give you the bounty!!Frow
Hehe. You're too kind (and very funny too!). I'm glad it helped you — that's what this place is all about :)Centurion
The build script mentioned in the answer is somewhat obsolete with respect to current versions of iOS. Forked the gist and modified accordingly for forward compatibility with iOS 8.2+ and that can be found here. Hope someone might find it helpful in future.Cult
@AyanSengupta Thanks - it built using Xcode 10 / iOS 12 SDK. I'll need to update it to compile tvOS binaries.Rajewski
hi! great answer here! this compiles into the .a file. How to create .frameworks instead?Hearthside
@iori24 a .framework is just a folder structure with the .a file, headers, and a plistPrioress

© 2022 - 2024 — McMap. All rights reserved.