Česky
Kamil Dudka

Flex/Bison based compiler and interpreter written in C++ (using Boost)

File detail

Name:DownloadCMakeLists.txt [Download]
Location: vyp08 > vyp08-1.0pre1 > src
Size:6.3 KB
Last modification:2009-07-04 19:51

Source code

# Copyright (C) 2008 Kamil Dudka <xdudka00@stud.fit.vutbr.cz>
#
# This file is part of vyp08 (compiler and interpreter of VYP08 language).
#
# vyp08 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 3 of the License, or
# any later version.
#
# vyp08 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 vyp08.  If not, see <http://www.gnu.org/licenses/>.
 
# project metadata
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
PROJECT(vyp08 CXX C)
if(COMMAND cmake_policy)
    cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)  
ENABLE_TESTING()
SET(CMAKE_INCLUDE_PATH, ${CMAKE_INCLUDE_PATH} ${vyp08_SOURCE_DIR})
 
# check for dependencies
FIND_PROGRAM(FLEX flex)
IF(NOT EXISTS ${FLEX})
    MESSAGE(FATAL_ERROR "flex executable not found")
ENDIF(NOT EXISTS ${FLEX})
 
FIND_PROGRAM(BISON bison)
IF(NOT EXISTS ${BISON})
    MESSAGE(FATAL_ERROR "bison executable not found")
ENDIF(NOT EXISTS ${BISON})
 
# Check for C++ compiler flags
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG(-std=c++98 HAVE_STD)
IF(HAVE_STD)
    SET(STD_FLAG "-std=c++98")
ENDIF(HAVE_STD)
CHECK_CXX_COMPILER_FLAG("-W -Wall" HAVE_PEDANTIC)
IF(HAVE_PEDANTIC)
    SET(PEDANTIC_FLAG "-W -Wall")
ENDIF(HAVE_PEDANTIC)
 
# Set C++ compiler flags
SET(CMAKE_CXX_FLAGS
    "${STD_FLAG} ${PEDANTIC_FLAG} ${DEBUG_FLAG} -I${vyp08_SOURCE_DIR} -I${vyp08_BINARY_DIR} -g"
    CACHE STRING "C++ compiler flags" FORCE)
 
# Check Boost availability
INCLUDE(FindBoost)
FIND_PACKAGE(Boost 1.34.1 COMPONENTS regex)
IF(NOT Boost_FOUND)
	MESSAGE(FATAL_ERROR "Cannot find Boost")
ENDIF(NOT Boost_FOUND)
 
# scanner
ADD_LIBRARY(scanner STATIC scanner.cc ${vyp08_BINARY_DIR}/scanner.yy.cc vypIO.cc)
ADD_CUSTOM_COMMAND(OUTPUT ${vyp08_BINARY_DIR}/scanner.yy.cc
    COMMAND ${FLEX}
    ARGS -o${vyp08_BINARY_DIR}/scanner.yy.cc ${vyp08_SOURCE_DIR}/scanner.lex
    DEPENDS scanner.lex)
TARGET_LINK_LIBRARIES(scanner boost_regex)
 
# unit test - scanner
ADD_EXECUTABLE(test-scanner test-scanner.cc)
TARGET_LINK_LIBRARIES(test-scanner scanner)
ADD_TEST(unit_test-scanner test-scanner)
 
# parser
ADD_LIBRARY(parser STATIC parser.cc ${vyp08_BINARY_DIR}/parser.tab.cc)
ADD_CUSTOM_COMMAND(
    OUTPUT ${vyp08_BINARY_DIR}/parser.tab.cc ${vyp08_BINARY_DIR}/parser.tab.hh
    COMMAND ${BISON}
    ARGS -o${vyp08_BINARY_DIR}/parser.tab.cc ${vyp08_SOURCE_DIR}/parser.yy
    DEPENDS parser.yy)
 
# unit test - parser
ADD_EXECUTABLE(test-parser test-parser.cc)
TARGET_LINK_LIBRARIES(test-parser scanner parser)
ADD_TEST(unit_test-parser test-parser)
 
# vyp08 executable
ADD_EXECUTABLE(vyp08 vyp08.cc builder.cc vm.cc cmd.cc)
TARGET_LINK_LIBRARIES(vyp08 scanner parser)
 
# vyp08 tests
ADD_TEST(test-000-err-no_arg            bash -c "if ./vyp08; then false; else true; fi")
ADD_TEST(test-001-err-two_args          bash -c "if ./vyp08 arg1 arg2; then false; else true; fi")
ADD_TEST(test-002-err-invalid_input     bash -c "if ./vyp08 invalid_input; then false; else true; fi")
ADD_TEST(test-003-err-empty_input       ${vyp08_SOURCE_DIR}/test.sh test-003-err-empty_input)
ADD_TEST(test-004-ok-empty_main         ${vyp08_SOURCE_DIR}/test.sh test-004-ok-empty_main)
ADD_TEST(test-005-ok-literals           ${vyp08_SOURCE_DIR}/test.sh test-005-ok-literals)
ADD_TEST(test-006-err-main_decl         ${vyp08_SOURCE_DIR}/test.sh test-006-err-main_decl)
ADD_TEST(test-007-err-main_decl         ${vyp08_SOURCE_DIR}/test.sh test-007-err-main_decl)
ADD_TEST(test-008-err-main_decl         ${vyp08_SOURCE_DIR}/test.sh test-008-err-main_decl)
ADD_TEST(test-009-ok-fnc                ${vyp08_SOURCE_DIR}/test.sh test-009-ok-fnc)
ADD_TEST(test-010-ok-scope              ${vyp08_SOURCE_DIR}/test.sh test-010-ok-scope)
ADD_TEST(test-011-err-C_fnc_arg         ${vyp08_SOURCE_DIR}/test.sh test-011-err-C_fnc_arg)
ADD_TEST(test-012-err-C_fnc_var         ${vyp08_SOURCE_DIR}/test.sh test-012-err-C_fnc_var)
ADD_TEST(test-013-err-C_arg_arg         ${vyp08_SOURCE_DIR}/test.sh test-013-err-C_arg_arg)
ADD_TEST(test-014-err-C_arg_var         ${vyp08_SOURCE_DIR}/test.sh test-014-err-C_arg_var)
ADD_TEST(test-015-err-C_var_var         ${vyp08_SOURCE_DIR}/test.sh test-015-err-C_var_var)
ADD_TEST(test-016-err-C_fnc_print       ${vyp08_SOURCE_DIR}/test.sh test-016-err-C_fnc_print)
ADD_TEST(test-017-ok-decl_inputint      ${vyp08_SOURCE_DIR}/test.sh test-017-ok-decl_inputint)
ADD_TEST(test-018-err-decl_inputint     ${vyp08_SOURCE_DIR}/test.sh test-018-err-decl_inputint)
ADD_TEST(test-019-err-def_inputint      ${vyp08_SOURCE_DIR}/test.sh test-019-err-def_inputint)
ADD_TEST(test-020-ok-input_print        ${vyp08_SOURCE_DIR}/test.sh test-020-ok-input_print)
ADD_TEST(test-021-err-inputint          ${vyp08_SOURCE_DIR}/test.sh test-021-err-inputint)
ADD_TEST(test-022-ok-fact_direct        ${vyp08_SOURCE_DIR}/test.sh test-022-ok-fact_direct)
ADD_TEST(test-023-ok-fact_indirect      ${vyp08_SOURCE_DIR}/test.sh test-023-ok-fact_indirect)
ADD_TEST(test-024-ok-expr               ${vyp08_SOURCE_DIR}/test.sh test-024-ok-expr)
ADD_TEST(test-025-err-type_mm_live      ${vyp08_SOURCE_DIR}/test.sh test-025-err-type_mm_live)
ADD_TEST(test-026-err-type_mm_dead      ${vyp08_SOURCE_DIR}/test.sh test-026-err-type_mm_dead)
ADD_TEST(test-027-err-type_mm_unop      ${vyp08_SOURCE_DIR}/test.sh test-027-err-type_mm_unop)
ADD_TEST(test-028-err-type_mm_binop     ${vyp08_SOURCE_DIR}/test.sh test-028-err-type_mm_binop)
ADD_TEST(test-029-err-type_mm_call      ${vyp08_SOURCE_DIR}/test.sh test-029-err-type_mm_call)
ADD_TEST(test-030-err-init_gl           ${vyp08_SOURCE_DIR}/test.sh test-030-err-init_gl)
ADD_TEST(test-031-err-init_lc           ${vyp08_SOURCE_DIR}/test.sh test-031-err-init_lc)
ADD_TEST(test-032-err-init_ret          ${vyp08_SOURCE_DIR}/test.sh test-032-err-init_ret)
ADD_TEST(test-033-err-init_ret          ${vyp08_SOURCE_DIR}/test.sh test-033-err-init_ret)
ADD_TEST(test-034-err-void              ${vyp08_SOURCE_DIR}/test.sh test-034-err-void)
ADD_TEST(test-035-err-n_args            ${vyp08_SOURCE_DIR}/test.sh test-035-err-n_args)
ADD_TEST(test-036-err-invalid_ret       ${vyp08_SOURCE_DIR}/test.sh test-036-err-invalid_ret)
ADD_TEST(test-037-err-inf_loop          ${vyp08_SOURCE_DIR}/test.sh test-037-err-inf_loop)