Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To include a font in your Xcode project through CMake, follow these steps:

  1. Create a new directory in your project called Fonts and place your font file (.ttf, .otf, etc.) in that directory.

  2. In your CMakeLists.txt, create a variable that holds the path to your Fonts directory:

set(FONT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Fonts")
  1. Add the following lines of code to your CMakeLists.txt to copy the font file to your app bundle:
# Copy font to app bundle
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND
                    ${CMAKE_COMMAND} -E copy_directory ${FONT_DIR} ${APP_BUNDLE}/Contents/Resources)
  1. In your Xcode project, go to your app target and add the font file to the project by selecting "Add Files to [App Name]" from the File menu.

  2. Select the font file and set the target membership to your app target.

  3. In your app's Info.plist, add a new entry for the font file with the name of the file and the relative path to the Fonts directory:

<key>UIAppFonts</key>
<array>
    <string>MyFont.ttf</string>
</array>
  1. Build and run your app to see the font in action!