Freetype provides a Makefile with a configure utility that makes it fairly easy to cross-compile for other platforms, however there are a lot of examples on the web (as well as some solutions) of people having difficulty in it.
My intention is to cross-compile FreeType using the Android NDK into a static library that can ultimately be used by libRocket for font rendering in HTML+CSS based UIs in OpenGL applications. I’m using the CMake build system for cross-platform builds and the android-cmake project to create a CMake toolchain for the NDK. This requires creating a CMakeLists.txt for FreeType as it doesn’t currently provide one.
The CMakeLists.txt file included below is based on the FreeType-2.4.8 release and is a result of converting the Jamfile and Makefile to CMake. Its intention is simply to allow compilation with CMake. For standard build and installs I would recommend following the instructions in the docs/INSTALL file from the FreeType directory. Note: This file will try and build *all* of FreeType2′s modules as defined in include/freetype/config/ftmodule.h. If you don’t want to build some of these modules please edit that file and remove the macro calls.This is a rather brute force method that will compile all the files and modules that are in the default build settings for FreeType. I spent some time trying to add proper CMake style options for each module that also checks their dependencies but didn’t get too far. You will need to remove files from compilation as needed.
cmake_minimum_required(VERSION 2.6)
project(FreeType2)
# First, compiler definitions for building the library
add_definitions(-DFT2_BUILD_LIBRARY)
add_definitions("-DFT_CONFIG_MODULES_H=<ftmodule.h>")
# Specify library include directories
include_directories("${PROJECT_SOURCE_DIR}/builds/ansi")
include_directories("${PROJECT_SOURCE_DIR}/include")
include_directories("${PROJECT_SOURCE_DIR}/include/freetype")
#include_directories("${PROJECT_SOURCE_DIR}/include/freetype/config")
# For the auto-generated ftmodule.h file
include_directories("${PROJECT_BINARY_DIR}/include")
include_directories("${PROJECT_SOURCE_DIR}/objs")
#file(GLOB BASE_SRCS "src/base/*.c")
set(BASE_SRCS
src/base/ftsystem.c
src/base/ftdebug.c
src/base/ftinit.c
src/base/ftbbox.c
src/base/ftbitmap.c
src/base/ftcid.c
src/base/ftadvanc.c
src/base/ftcalc.c
src/base/ftdbgmem.c
src/base/ftgloadr.c
src/base/ftobjs.c
src/base/ftoutln.c
src/base/ftrfork.c
src/base/ftsnames.c
src/base/ftstream.c
src/base/fttrigon.c
src/base/ftutil.c
src/base/ftfstype.c
src/base/ftgasp.c
src/base/ftglyph.c
src/base/ftgxval.c
src/base/ftlcdfil.c
src/base/ftmm.c
src/base/ftotval.c
src/base/ftpatent.c
src/base/ftpfr.c
src/base/ftstroke.c
src/base/ftsynth.c
src/base/fttype1.c
src/base/ftwinfnt.c
src/base/ftxf86.c
src/truetype/truetype.c
src/type1/type1.c
src/cff/cff.c
src/cid/type1cid.c
src/pfr/pfr.c
src/type42/type42.c
src/winfonts/winfnt.c
src/pcf/pcf.c
src/bdf/bdf.c
src/sfnt/sfnt.c
src/autofit/autofit.c
src/pshinter/pshinter.c
src/raster/raster.c
src/smooth/smooth.c
src/cache/ftcache.c
src/gzip/ftgzip.c
src/lzw/ftlzw.c
src/bzip2/ftbzip2.c
src/psaux/psaux.c
src/psnames/psmodule.c)
include_directories("src/truetype")
include_directories("src/sfnt")
include_directories("src/autofit")
include_directories("src/smooth")
include_directories("src/raster")
include_directories("src/psaux")
include_directories("src/psnames")
add_library(freetype SHARED ${BASE_SRCS})
set(FREETYPE_LIBRARY freetype CACHE STRING "The FreeType library name")
set(FREETYPE_FOUND TRUE CACHE BOOL "Whether freetype has been found or not")
set(FREETYPE_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include/
${PROJECT_SOURCE_DIR}/include/freetype CACHE STRING "FreeType include
directories")
set(FREETYPE_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include/
${PROJECT_SOURCE_DIR}/include/freetype CACHE STRING "FreeType include
directories")
The file sets the variables that FindFreeType.cmake sets, so any dependent sub-projects should use this first. Just remember to use:
# Build FreeType add_subdirectory(lib/freetype-2.4.8) include_directories(lib/freetype-2.4.8/include)
… before building the dependent projects.
Did not work for me:
numbersix.cary$ cmake ..
– The C compiler identification is GNU
– The CXX compiler identification is GNU
– Checking whether C compiler has -isysroot
– Checking whether C compiler has -isysroot – yes
– Checking whether C compiler supports OSX deployment target flag
– Checking whether C compiler supports OSX deployment target flag – yes
– Check for working C compiler: /usr/bin/gcc
– Check for working C compiler: /usr/bin/gcc — works
– Detecting C compiler ABI info
– Detecting C compiler ABI info – done
– Checking whether CXX compiler has -isysroot
– Checking whether CXX compiler has -isysroot – yes
– Checking whether CXX compiler supports OSX deployment target flag
– Checking whether CXX compiler supports OSX deployment target flag – yes
– Check for working CXX compiler: /usr/bin/c++
– Check for working CXX compiler: /usr/bin/c++ — works
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info – done
– Configuring done
– Generating done
– Build files have been written to: /Users/cary/projects/vorpalall/builds/freetype-2.4.8/ser
numbersix.cary$ make
Scanning dependencies of target freetype
[ 1%] Building C object CMakeFiles/freetype.dir/src/base/ftsystem.c.o
[ 3%] Building C object CMakeFiles/freetype.dir/src/base/ftdebug.c.o
[ 5%] Building C object CMakeFiles/freetype.dir/src/base/ftinit.c.o
/Users/cary/projects/vorpalall/builds/freetype-2.4.8/src/base/ftinit.c:67:29: error: #include expects “FILENAME” or
/Users/cary/projects/vorpalall/builds/freetype-2.4.8/src/base/ftinit.c:76:29: error: #include expects “FILENAME” or
make[2]: *** [CMakeFiles/freetype.dir/src/base/ftinit.c.o] Error 1
make[1]: *** [CMakeFiles/freetype.dir/all] Error 2
make: *** [all] Error
Hey, the line specified by the compiler output points to your FT_CONFIG_MODULES_H define not being defined. It looks like wordpress stripped out the code I pasted inside the < and > symbols, please modify that line in the CMake file with this:
add_definitions("-DFT_CONFIG_MODULES_H=<ftmodule.h>")