#
# SuperTux - miniswig build script
# Copyright (C) 2007 Timothy Goya <tuxdev103@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

## Project name to use as command prefix

PROJECT(MINISWIG)

## add additional compiler switches

ADD_DEFINITIONS(-include ${CMAKE_BINARY_DIR}/config.h)
# the autogenerated bison/flex is not warning free usually
REMOVE_DEFINITIONS(-Wall -W)

## Include paths to make generated files work

INCLUDE_DIRECTORIES (${MINISWIG_SOURCE_DIR})

## build list of source files

FILE(GLOB MINISWIG_SOURCES RELATIVE ${MINISWIG_SOURCE_DIR} create_docu.cpp create_wrapper.cpp main.cpp tree.cpp xmlwriter.cpp)

## Add target for bison parser generation

MARK_AS_ADVANCED(BISON_EXECUTABLE)
FIND_PROGRAM(BISON_EXECUTABLE bison)
IF (NOT BISON_EXECUTABLE)
  MESSAGE(FATAL_ERROR "bison not found - aborting")
ENDIF (NOT BISON_EXECUTABLE)
ADD_CUSTOM_COMMAND(
  OUTPUT ${MINISWIG_BINARY_DIR}/parser.cpp ${MINISWIG_BINARY_DIR}/parser.hpp
  COMMAND ${BISON_EXECUTABLE}
  ARGS -d -o ${MINISWIG_BINARY_DIR}/parser.cpp ${MINISWIG_SOURCE_DIR}/parser.yy
  DEPENDS parser.yy
)

## Add target for flex lexical analyzer generation

MARK_AS_ADVANCED(FLEX_EXECUTABLE)
FIND_PROGRAM(FLEX_EXECUTABLE flex)
IF (NOT FLEX_EXECUTABLE)
  MESSAGE(FATAL_ERROR "flex not found - aborting")
ENDIF (NOT FLEX_EXECUTABLE)
ADD_CUSTOM_COMMAND(
  OUTPUT ${MINISWIG_BINARY_DIR}/lexer.cpp
  COMMAND ${FLEX_EXECUTABLE}
  ARGS -o ${MINISWIG_BINARY_DIR}/lexer.cpp ${MINISWIG_SOURCE_DIR}/lexer.ll
  DEPENDS lexer.ll ${MINISWIG_BINARY_DIR}/parser.hpp
)

## Add target for miniswig binary

ADD_EXECUTABLE(miniswig ${MINISWIG_SOURCES} ${MINISWIG_BINARY_DIR}/parser.cpp ${MINISWIG_BINARY_DIR}/lexer.cpp)
