#******************************************************************************
#
#       Copyright:      2006-2016 Paul Obermeier (obermeier@tcl3d.org)
#
#                       See the file "Tcl3D_License.txt" for information on
#                       usage and redistribution of this file, and for a
#                       DISCLAIMER OF ALL WARRANTIES.
#
#       Module:         Tcl3D -> tcl3dFTGL
#       Filename:       CMakeLists.txt
#
#       Author:         Paul Obermeier
#
#       Description:    Makefile for the tcl3dFTGL subpackage.
#
#******************************************************************************

IF( TCL3D_BUILD_FTGL )

    SET( TARGET tcl3dFTGL )

    SET( TARGET_DEF "-DUSE_FTGL_IF" )

    ADD_DEFINITIONS( ${TARGET_DEF} )
    INCLUDE_DIRECTORIES( 
        ${FTGL_INCLUDE_DIR} 
        ${FTGL_INCLUDE_DIR}/FTGL
        ${FREETYPE_INCLUDE_DIR_freetype2}
        ${FREETYPE_INCLUDE_DIR_ft2build}
    )

    # Build wrapper with SWIG.
    SET( INTERFACE_FILE swigfiles/${TARGET}.i )

    FIND_PACKAGE( Freetype REQUIRED )
    FIND_PACKAGE( FTGL     REQUIRED )

    INCLUDE( ${SWIG_USE_FILE} )
  
    SET( CMAKE_SWIG_FLAGS
        ${TARGET_DEF}
        ${COMMON_SWIG_FLAGS}
        -I${CMAKE_CURRENT_SOURCE_DIR}
        -I${CMAKE_CURRENT_SOURCE_DIR}/swigfiles
        -I${FTGL_INCLUDE_DIR}
        -I${FTGL_INCLUDE_DIR}/FTGL
        -I${FREETYPE_INCLUDE_DIR_freetype2}
        -I${FREETYPE_INCLUDE_DIR_ft2build}
    )

    SET_SOURCE_FILES_PROPERTIES( ${INTERFACE_FILE} PROPERTIES CPLUSPLUS ON )

    MY_SWIG_ADD_MODULE( ${TARGET} tcl ${INTERFACE_FILE} )
    SWIG_LINK_LIBRARIES( ${TARGET} ${FTGL_LIBRARY} ${TCL_STUB_LIBRARY} ${TK_STUB_LIBRARY} ${SYS_LIBS} )
    SET_TARGET_PROPERTIES( ${TARGET} PROPERTIES PREFIX "" )

    # Install the configuration specific Tcl package index file and all other Tcl files.
    INSTALL_TCL_PACKAGE( ${TARGET} "tclfiles/pkgIndex.tcl.in" "tclfiles/" "tcl3d*.tcl" )

    # Install the shared library containing the SWIG generated wrapper.
    INSTALL(
        TARGETS     ${TARGET}
        DESTINATION ${TCL3D_INST_DIR}/${TARGET}
    )
ENDIF( TCL3D_BUILD_FTGL )
