From e5294eef9da145e006b214cd94f52173bd0a0dff Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 9 Feb 2016 15:57:30 +0000 Subject: [PATCH] Add freetype dependency. We are going to use freetype instead of the old custom TTF parser, since the old parser has many annoying bugs when handling non-Latin fonts and fixing it is not really worth the time. On Windows, Freetype is built from a submodule. On Linux and OS X, Freetype is provided together with the desktop, though development files have to be installed separately. --- .gitmodules | 3 +++ .travis.yml | 2 +- CMakeLists.txt | 28 ++++++++++++++++++++++++++++ README.md | 10 +++++----- extlib/libfreetype | 1 + src/CMakeLists.txt | 13 +++++-------- 6 files changed, 43 insertions(+), 14 deletions(-) create mode 160000 extlib/libfreetype diff --git a/.gitmodules b/.gitmodules index 517de0a4..342149aa 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,3 +5,6 @@ [submodule "extlib/libpng"] path = extlib/libpng url = https://github.com/glennrp/libpng +[submodule "extlib/libfreetype"] + path = extlib/libfreetype + url = http://git.sv.nongnu.org/r/freetype/freetype2.git diff --git a/.travis.yml b/.travis.yml index 16c5b0da..88dd16e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ os: - linux - osx install: - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo add-apt-repository -y ppa:smspillaz/cmake-master; sudo add-apt-repository -y ppa:ondrej/php5; sudo apt-get update -qq; sudo apt-get install -q -y cmake cmake-data libpng12-dev zlib1g-dev libjson0-dev libfontconfig1-dev libgtkmm-2.4-dev libpangomm-1.4-dev libgl1-mesa-dev libglu-dev libglew-dev dpkg-dev; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo add-apt-repository -y ppa:smspillaz/cmake-master; sudo add-apt-repository -y ppa:ondrej/php5; sudo apt-get update -qq; sudo apt-get install -q -y cmake cmake-data libpng12-dev zlib1g-dev libjson0-dev libfontconfig1-dev libgtkmm-2.4-dev libpangomm-1.4-dev libgl1-mesa-dev libglu-dev libglew-dev libfreetype6-dev dpkg-dev; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew upgrade cmake libpng; fi script: - mkdir cbuild diff --git a/CMakeLists.txt b/CMakeLists.txt index 055b96b6..f67998e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,32 @@ CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H) find_package(OpenGL REQUIRED) if(WIN32) + # We don't want any of the subprojects to install anything. + # We don't actually install anything on Windows (so overriding + # this is OK), but the combination of freetype's and png/zlib's + # CMakeLists.txt produces harmless but annoying CMake errors. + macro(install) + endmacro() + + # Configure Freetype first. If done later, it will notice that + # zlib is available, try to use it and promptly break on MSVC + # in a very obscure way. Given that the only use of zlib, bzip2 + # and png support is in support for extremely obsolete Unix fonts, + # we don't care. + find_package(Freetype) + + if(NOT FREETYPE_FOUND) + message(STATUS "Using in-tree libfreetype") + + add_subdirectory(extlib/libfreetype) + + set(FREETYPE_LIBRARY + freetype) + set(FREETYPE_INCLUDE_DIRS + "${CMAKE_SOURCE_DIR}/extlib/libfreetype/include") + find_package(Freetype REQUIRED) + endif() + find_package(ZLIB) if(NOT ZLIB_FOUND) @@ -109,6 +135,7 @@ if(WIN32) endif() elseif(APPLE) find_package(PNG REQUIRED) + find_package(Freetype REQUIRED) find_library(APPKIT_LIBRARY AppKit REQUIRED) else() # Linux and compatible systems find_package(SpaceWare) @@ -120,6 +147,7 @@ else() # Linux and compatible systems pkg_check_modules(FONTCONFIG REQUIRED fontconfig) pkg_check_modules(JSONC REQUIRED json-c) pkg_check_modules(GLEW REQUIRED glew) + pkg_check_modules(FREETYPE REQUIRED freetype2) set(HAVE_GTK TRUE) if(GUI STREQUAL "gtk3") diff --git a/README.md b/README.md index b24a2f45..592bcc2f 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,13 @@ Building on Linux ### Building for Linux -You will need CMake, libpng, zlib, json-c, fontconfig, gtkmm 2.4, pangomm 1.4, -OpenGL and OpenGL GLU. +You will need CMake, libpng, zlib, json-c, fontconfig, freetype, gtkmm 2.4, +pangomm 1.4, OpenGL and OpenGL GLU. On a Debian derivative (e.g. Ubuntu) these can be installed with: - apt-get install libpng12-dev libjson-c-dev libfontconfig1-dev \ - libgtkmm-2.4-dev libpangomm-1.4-dev libgl-dev libglu-dev \ - libglew-dev cmake + apt-get install libpng12-dev libjson-c-dev libfreetype6-dev \ + libfontconfig1-dev libgtkmm-2.4-dev libpangomm-1.4-dev \ + libgl-dev libglu-dev libglew-dev cmake After that, build SolveSpace as following: diff --git a/extlib/libfreetype b/extlib/libfreetype new file mode 160000 index 00000000..44accb9e --- /dev/null +++ b/extlib/libfreetype @@ -0,0 +1 @@ +Subproject commit 44accb9e2e5b00696cf50a869b68afa2ce3dd389 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f0545eb5..95b3a7ca 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,16 +2,12 @@ include_directories( ${OPENGL_INCLUDE_DIR} - ${PNG_INCLUDE_DIRS}) + ${PNG_INCLUDE_DIRS} + ${FREETYPE_INCLUDE_DIRS}) link_directories( - ${PNG_LIBRARY_DIRS}) - -add_definitions( - ${PNG_CFLAGS_OTHER}) - -link_directories( - ${PNG_LIBRARY_DIRS}) + ${PNG_LIBRARY_DIRS} + ${FREETYPE_LIBRARY_DIRS}) add_definitions( ${PNG_CFLAGS_OTHER}) @@ -307,6 +303,7 @@ target_link_libraries(solvespace "${OPENGL_LIBRARIES}" "${PNG_LIBRARIES}" "${ZLIB_LIBRARIES}" + "${FREETYPE_LIBRARIES}" "${platform_LIBRARIES}") if(WIN32 AND NOT MINGW)