# Fontmatrix ./CMakeLists.txt v1

PROJECT(fontmatrix) # the name of your project
CMAKE_MINIMUM_REQUIRED(VERSION 2.4.0)

SET (VERSION_MAJOR "0")
SET (VERSION_MINOR "4")
SET (VERSION_PATCH "2")
SET (VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
ADD_DEFINITIONS(-DFONTMATRIX_VERSION_MAJOR=${VERSION_MAJOR} -DFONTMATRIX_VERSION_MINOR=${VERSION_MINOR} -DFONTMATRIX_VERSION_PATCH=${VERSION_PATCH})
MESSAGE(STATUS "Building Fontmatrix ${VERSION}")

SET(OWN_SHAPER 1)

IF(OWN_SHAPER)
    ADD_DEFINITIONS( -DFM_OWNSHAPER )
    MESSAGE(STATUS "Use own shaper rather than HB")
ENDIF(OWN_SHAPER)

SET(HARFBUZZ_DIR harfbuzz/src)
ADD_SUBDIRECTORY(${HARFBUZZ_DIR})
SET(HARFBUZZ_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/harfbuzz/src)


#>> IF(HIGH_PERF)
    ADD_DEFINITIONS( -DHIGH_PERF )
    MESSAGE(STATUS "High performance required :-)")
#<< ENDIF(HIGH_PERF)



IF(NO_ASSERT)
	ADD_DEFINITIONS(-DNDEBUG )
ENDIF(NO_ASSERT)

SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
# A lot from Scribus
#<< Qt 
SET (QT_MT_REQUIRED TRUE)
SET (QT_MIN_VERSION "4.3.0")
SET (QT_USE_QTXML TRUE )
SET (QT_USE_QTSVG TRUE )
SET (QT_USE_QTNETWORK TRUE )
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE( ${QT_USE_FILE} )
IF (QT_FOUND)
  MESSAGE(STATUS "Qt4 Found OK")
#Add our Qt definitions
#   ADD_DEFINITIONS(
#     ${QT_DEFINITIONS}
#     -DQT_CORE_LIB
#     -DQT_GUI_LIB
#     -DQT_THREAD_LIB
#     -DQT_XML_LIB
#   )
ELSE(QT_FOUND)
  MESSAGE(FATAL_ERROR "No Qt4 found")
ENDIF(QT_FOUND)
#>> Qt

#<< FreeType2
SET(FREETYPE_DIR ${CMAKE_MODULE_PATH})
FIND_PACKAGE(FREETYPE REQUIRED)
IF (FREETYPE_FOUND)
  MESSAGE(STATUS "FreeType2 Library Found OK")
  INCLUDE(CheckLibraryExists)
  SET(CMAKE_REQUIRED_LIBRARIES z)
  CHECK_LIBRARY_EXISTS(libfreetype.so FT_Get_First_Char ${FREETYPE_LIBRARY_DIR} HAVE_FREETYPE_FIRST)
  CHECK_LIBRARY_EXISTS(libfreetype.so FT_Get_Next_Char  ${FREETYPE_LIBRARY_DIR} HAVE_FREETYPE_NEXT)
ELSE (FREETYPE_FOUND)
  MESSAGE(STATUS "No Freetype found")  
ENDIF(FREETYPE_FOUND)
#FIXME: if cflags empty add, otherwise replace as now
SET(CFLAGS "${LIBFREETYPE_CFLAGS}")
#>> FreeType2

SET(FONTCONFIG_DIR ${CMAKE_MODULE_PATH})
  FIND_PACKAGE(FONTCONFIG)
IF(FONTCONFIG_FOUND)
        MESSAGE(STATUS "FontConfig Found OK")
        ADD_DEFINITIONS( -DHAVE_FONTCONFIG )
ENDIF(FONTCONFIG_FOUND)


# tell cmake to process CMakeLists.txt in that subdirectory


ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(src/langs)

######## Installation ##################

IF (CMAKE_INSTALL_PREFIX) 
	SET (INSTALLDIR ${CMAKE_INSTALL_PREFIX})
ELSE (CMAKE_INSTALL_PREFIX)
	SET (INSTALLDIR "/usr/local")
ENDIF (CMAKE_INSTALL_PREFIX) 

MESSAGE(STATUS "")
MESSAGE(STATUS "Fontmatrix will be installed under ${CMAKE_INSTALL_PREFIX}")
MESSAGE(STATUS "")

SET(DESKTOPDIR "share/applications/")
# ADD_DEFINITIONS("-DDESKTOPDIR=\\\"${CMAKE_INSTALL_PREFIX}/${DESKTOPDIR}\\\"")
INSTALL(FILES
  fontmatrix.desktop
  DESTINATION ${DESKTOPDIR}
)

SET(ICONDIR "share/icons/hicolor/48x48/apps/")
# ADD_DEFINITIONS("-DICONDIR=\\\"${CMAKE_INSTALL_PREFIX}/${ICONDIR}\\\"")
INSTALL(FILES
  fontmatrix.png
  DESTINATION ${ICONDIR}
)

SET(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
SET(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
SET(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})

INCLUDE(CPack)
