CMakeLists.txt 8.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
# =========================================================================
# Freetype GL - A C OpenGL Freetype engine
# Platform:    Any
# WWW:         http://code.google.com/p/freetype-gl/
# -------------------------------------------------------------------------
# Copyright 2011,2012 Nicolas P. Rougier. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#  1. Redistributions of source code must retain the above copyright notice,
#     this list of conditions and the following disclaimer.
#
#  2. Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are
# those of the authors and should not be interpreted as representing official
# policies, either expressed or implied, of Nicolas P. Rougier.
# =========================================================================
33
CMAKE_MINIMUM_REQUIRED( VERSION 2.8.5 )
34 35 36
SET( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules"
                       "${CMAKE_MODULE_PATH}" )

Nicolas.Rougier's avatar
Nicolas.Rougier committed
37 38
OPTION(freetype-gl_BUILD_DEMOS "Build the freetype-gl example programs" ON)

39 40
# Get required and optional library
FIND_PACKAGE( OpenGL REQUIRED )
41 42 43
IF( WIN32 OR WIN64 )
	SET( WINDOWS_DIR
         ${CMAKE_CURRENT_SOURCE_DIR}/windows )
44 45
	SET( GLUT_INCLUDE_DIR
         ${CMAKE_CURRENT_SOURCE_DIR}/windows/glut )
46
	SET( GLUT_LIBRARY
47
         ${CMAKE_CURRENT_SOURCE_DIR}/windows/glut/glut32.lib )
48 49 50 51
    SET( GLEW_INCLUDE_DIR
         ${CMAKE_CURRENT_SOURCE_DIR}/windows/glew/include )
    SET( GLEW_LIBRARY
         ${CMAKE_CURRENT_SOURCE_DIR}/windows/glew/lib/glew32.lib )
52 53
	SET( FREETYPE_INCLUDE_DIRS
         ${CMAKE_CURRENT_SOURCE_DIR}/windows/freetype )
54 55 56 57 58 59 60 61 62 63
	SET( FREETYPE_INCLUDE_DIR_ft2build
         ${CMAKE_CURRENT_SOURCE_DIR}/windows/freetype )
	SET( FREETYPE_INCLUDE_DIR_freetype2
         ${CMAKE_CURRENT_SOURCE_DIR}/windows/freetype/freetype )
	SET( FREETYPE_LIBRARY
         ${CMAKE_CURRENT_SOURCE_DIR}/windows/freetype/freetype.lib )
	SET( ANT_TWEAK_BAR_INCLUDE_PATH
         ${CMAKE_CURRENT_SOURCE_DIR}/windows/AntTweakBar/include )
	SET( ANT_TWEAK_BAR_LIBRARY
         ${CMAKE_CURRENT_SOURCE_DIR}/windows/AntTweakBar/lib/AntTweakBar.lib )
64 65
    SET( VS789FIX_INCLUDE_DIR
         ${CMAKE_CURRENT_SOURCE_DIR}/windows/include )
66
    SET( ANT_TWEAK_BAR_FOUND "YES" )
67
ELSE( WIN32 OR WIN64 )
68 69
    FIND_PACKAGE( GLUT REQUIRED )
    FIND_PACKAGE( Freetype REQUIRED )
70
    FIND_PACKAGE( GLEW REQUIRED )
71
    FIND_PACKAGE( FontConfig )
72
    FIND_LIBRARY( MATH_LIBRARY m )
73
    #FIND_LIBRARY( STDC_LIBRARY stdc++) #Buggy Cmake can't find libstdc++
74
    SET( ANT_TWEAK_BAR_INCLUDE_PATH "")
75
    FIND_PACKAGE( AntTweakBar )
76
ENDIF( WIN32 OR WIN64 )
77

78
INCLUDE_DIRECTORIES( ${GLUT_INCLUDE_DIR}
79 80
                     ${OPENGL_INCLUDE_DIRS}
                     ${FREETYPE_INCLUDE_DIRS}
81
                     ${GLEW_INCLUDE_DIRS}
82
                     ${CMAKE_CURRENT_SOURCE_DIR}
83 84 85 86 87 88
                     ${VS789FIX_INCLUDE_DIR}
                     ${GLEW_INCLUDE_DIR})
					 
IF(MSVC)
	ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ENDIF(MSVC)
89

90 91 92 93 94 95 96 97 98 99 100 101 102 103
SET( FREETYPE_GL_SRC freetype-gl.h
                     vec234.h
                     opengl.h
                     markup.h
                     mat4.c             mat4.h
                     texture-atlas.c    texture-atlas.h
                     texture-font.c     texture-font.h
                     vertex-buffer.c    vertex-buffer.h
                     vertex-attribute.c vertex-attribute.h
                     font-manager.c     font-manager.h
                     text-buffer.c      text-buffer.h
                     shader.c           shader.h
                     vector.c           vector.h
                     platform.c         platform.h)
Nicolas.Rougier's avatar
Nicolas.Rougier committed
104 105

ADD_LIBRARY( freetype-gl STATIC ${FREETYPE_GL_SRC} )
106

107 108
LINK_DIRECTORIES(${PROJECT_SOURCE_DIR})

109 110
MACRO( DEMO _target _sources)
     add_executable(${_target} ${_sources})
111
     include_directories(${WINDOWS_DIR} ${GLUT_INCLUDE_DIR} ${GLEW_INCLUDE_DIR} ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2} ${ANT_TWEAK_BAR_INCLUDE_PATH})
112
     target_link_libraries(${_target} ${GLEW_LIBRARY})
Nicolas.Rougier's avatar
Nicolas.Rougier committed
113
     target_link_libraries(${_target} freetype-gl)
114
     target_link_libraries(${_target} ${OPENGL_LIBRARY})
115
     target_link_libraries(${_target} ${GLUT_LIBRARY})
116
     target_link_libraries(${_target} ${GLEW_LIBRARY})
117
     target_link_libraries(${_target} ${FREETYPE_LIBRARY})
118 119 120
     IF( MATH_LIBRARY )
         target_link_libraries(${_target} ${MATH_LIBRARY})
     ENDIF( MATH_LIBRARY )
121 122 123 124
    if(MSVC)
      # Compile demos as C++
      set_source_files_properties(${_sources} PROPERTIES LANGUAGE CXX)
    endif()
125 126
ENDMACRO( DEMO )

Nicolas.Rougier's avatar
Nicolas.Rougier committed
127 128
IF (freetype-gl_BUILD_DEMOS)

129 130 131 132 133 134 135 136 137 138 139 140
DEMO( demo-texture          "demo-texture.c" )
DEMO( demo-font             "demo-font.c" )
DEMO( demo-benchmark        "demo-benchmark.c" )
DEMO( demo-console          "demo-console.c" )
DEMO( demo-cube             "demo-cube.c" )
DEMO( demo-glyph            "demo-glyph.c" )
DEMO( demo-cartoon          "demo-cartoon.c" )
DEMO( demo-outline          "demo-outline.c" )
DEMO( demo-lcd              "demo-lcd.c" )
DEMO( demo-gamma            "demo-gamma.c" )
DEMO( demo-ansi             "demo-ansi.c" )
DEMO( demo-subpixel         "demo-subpixel.c" )
Nicolas.Rougier's avatar
Nicolas.Rougier committed
141
DEMO( demo-make             "demo-makefont.c" )
142 143
DEMO( makefont              "makefont.c" )
DEMO( demo-distance-field   "demo-distance-field.c;edtaa3func.c")
144
DEMO( demo-distance-field-2 "demo-distance-field-2.c;edtaa3func.c")
145
DEMO( demo-distance-field-3 "demo-distance-field-3.c;edtaa3func.c")
Nicolas.Rougier's avatar
Nicolas.Rougier committed
146

147 148
IF (FONTCONFIG_FOUND)
   INCLUDE_DIRECTORIES( ${FONTCONFIG_INCLUDE_DIR} )
Nicolas.Rougier's avatar
Nicolas.Rougier committed
149
   DEMO( demo-markup      "demo-markup.c" )
150 151 152
   target_link_libraries(demo-markup ${FONTCONFIG_LIBRARY})
ENDIF (FONTCONFIG_FOUND)

153
IF (ANT_TWEAK_BAR_FOUND AND (NOT (WIN32 OR WIN64)) )  
Nicolas.Rougier's avatar
Nicolas.Rougier committed
154
 #DEMO( demo-atb-agg     "demo-atb-agg.c;markup.h;")
155 156 157 158 159 160 161
 FILE(WRITE ${CMAKE_SOURCE_DIR}/stdc_test.c
  "int main(void){return 0;}\n")
  EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -lstdc++ OUTPUT_VARIABLE out_res ERROR_VARIABLE err_res)
  string(FIND VAL"${err_res}" "main" substr_index ) 
  if(${substr_index} STRGREATER "0")
      message (STATUS "Found Libstdc++ needed by demo-atb-agg.c ." )

Nicolas.Rougier's avatar
Nicolas.Rougier committed
162
      add_executable(demo-atb-agg  demo-atb-agg.c) 
163
      target_link_libraries( demo-atb-agg freetype-gl)
164
      target_link_libraries( demo-atb-agg ${GLUT_LIBRARY})
165
      target_link_libraries( demo-atb-agg ${GLEW_LIBRARY})
166 167 168 169 170 171 172 173 174 175 176 177
      target_link_libraries( demo-atb-agg ${FREETYPE_LIBRARY})
      target_link_libraries( demo-atb-agg ${ANT_TWEAK_BAR_LIBRARY})
      # target_link_libraries( demo-atb-agg ${STDC_LIBRARY}) # Buggy Cmake can't find libstdc++
      # quirk: because of link order libstdc++ must be linked before libGLU
      target_link_libraries( demo-atb-agg "-lstdc++")
      target_link_libraries( demo-atb-agg ${OPENGL_LIBRARY})
      IF(MATH_LIBRARY)
        target_link_libraries( demo-atb-agg ${MATH_LIBRARY})
      ENDIF(MATH_LIBRARY) 
  else()
      message (STATUS "NOT FOUND: Libstdc++ is not installed. It is needed by demo-atb-agg.c" )
  endif()
178
  FILE(REMOVE ${CMAKE_SOURCE_DIR}/stdc_test.c)
179
ENDIF (ANT_TWEAK_BAR_FOUND AND (NOT (WIN32 OR WIN64)) )  
180

181
# Copy font and shaders into build directory for in-place testing
182 183 184 185
FILE(GLOB Fonts   "fonts/Vera.ttf"
                  "fonts/VeraMoBI.ttf"
                  "fonts/VeraMoBd.ttf"
                  "fonts/VeraMoIt.ttf"
186 187
                  "fonts/VeraMono.ttf"
                  "fonts/ObelixPro.ttf")
188 189 190 191 192
file(COPY ${Fonts}   DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/fonts)

FILE(GLOB Data   "data/256colors.txt")
file(COPY ${Data}   DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data)

Nicolas.Rougier's avatar
Nicolas.Rougier committed
193 194 195 196
FILE(GLOB Shaders "shaders/*.vert" "shaders/*.frag")
file(COPY ${Shaders} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/shaders)

ENDIF (freetype-gl_BUILD_DEMOS)