Permalink
Browse files

switch to cmake

  • Loading branch information...
1 parent 57b5c4e commit 0aa7ed252d6d693807e8dc8294a8cf3012984a73 @tokuhirom committed Jul 12, 2012
Showing with 2,666 additions and 25 deletions.
  1. +81 −0 CMake/FindICU.cmake
  2. +39 −0 CMake/FindRE2C.cmake
  3. +113 −0 CMakeLists.txt
  4. +2,390 −0 Makefile
  5. +1 −0 tests/test_compiler.cc
  6. +1 −7 tora/main.cc
  7. +1 −1 tora/object/file_package.cc
  8. +5 −5 tora/value/file_package.h
  9. +12 −12 tora/vm.cc
  10. +23 −0 util/test.pl
View
@@ -0,0 +1,81 @@
+# Finds the International Components for Unicode (ICU) Library
+#
+# ICU_FOUND - True if ICU found.
+# ICU_I18N_FOUND - True if ICU's internationalization library found.
+# ICU_INCLUDE_DIRS - Directory to include to get ICU headers
+# Note: always include ICU headers as, e.g.,
+# unicode/utypes.h
+# ICU_LIBRARIES - Libraries to link against for the common ICU
+# ICU_I18N_LIBRARIES - Libraries to link against for ICU internationaliation
+# (note: in addition to ICU_LIBRARIES)
+
+# Look for the header file.
+find_path(
+ ICU_INCLUDE_DIR
+ NAMES unicode/utypes.h
+ DOC "Include directory for the ICU library")
+mark_as_advanced(ICU_INCLUDE_DIR)
+
+# Look for the library.
+find_library(
+ ICU_LIBRARY
+ NAMES icuuc cygicuuc cygicuuc32
+ DOC "Libraries to link against for the common parts of ICU")
+mark_as_advanced(ICU_LIBRARY)
+
+# Copy the results to the output variables.
+if(ICU_INCLUDE_DIR AND ICU_LIBRARY)
+ set(ICU_FOUND 1)
+ set(ICU_LIBRARIES ${ICU_LIBRARY})
+ set(ICU_INCLUDE_DIRS ${ICU_INCLUDE_DIR})
+
+ set(ICU_VERSION 0)
+ set(ICU_MAJOR_VERSION 0)
+ set(ICU_MINOR_VERSION 0)
+ if (EXISTS "${ICU_INCLUDE_DIR}/unicode/uvernum.h")
+ FILE(READ "${ICU_INCLUDE_DIR}/unicode/uvernum.h" _ICU_VERSION_CONENTS)
+ else()
+ FILE(READ "${ICU_INCLUDE_DIR}/unicode/uversion.h" _ICU_VERSION_CONENTS)
+ endif()
+
+ STRING(REGEX REPLACE ".*#define U_ICU_VERSION_MAJOR_NUM ([0-9]+).*" "\\1" ICU_MAJOR_VERSION "${_ICU_VERSION_CONENTS}")
+ STRING(REGEX REPLACE ".*#define U_ICU_VERSION_MINOR_NUM ([0-9]+).*" "\\1" ICU_MINOR_VERSION "${_ICU_VERSION_CONENTS}")
+
+ set(ICU_VERSION "${ICU_MAJOR_VERSION}.${ICU_MINOR_VERSION}")
+
+ # Look for the ICU internationalization libraries
+ find_library(
+ ICU_I18N_LIBRARY
+ NAMES icuin icui18n cygicuin cygicuin32
+ DOC "Libraries to link against for ICU internationalization")
+ mark_as_advanced(ICU_I18N_LIBRARY)
+ if (ICU_I18N_LIBRARY)
+ set(ICU_I18N_FOUND 1)
+ set(ICU_I18N_LIBRARIES ${ICU_I18N_LIBRARY})
+ else (ICU_I18N_LIBRARY)
+ set(ICU_I18N_FOUND 0)
+ set(ICU_I18N_LIBRARIES)
+ endif (ICU_I18N_LIBRARY)
+else(ICU_INCLUDE_DIR AND ICU_LIBRARY)
+ set(ICU_FOUND 0)
+ set(ICU_I18N_FOUND 0)
+ set(ICU_LIBRARIES)
+ set(ICU_I18N_LIBRARIES)
+ set(ICU_INCLUDE_DIRS)
+ set(ICU_VERSION)
+ set(ICU_MAJOR_VERSION)
+ set(ICU_MINOR_VERSION)
+endif(ICU_INCLUDE_DIR AND ICU_LIBRARY)
+
+IF(ICU_FOUND)
+ IF( NOT ICU_FIND_QUIETLY )
+ MESSAGE( STATUS "Found ICU header files in ${ICU_INCLUDE_DIRS}")
+ MESSAGE( STATUS "Found ICU libraries: ${ICU_LIBRARIES}")
+ ENDIF( NOT ICU_FIND_QUIETLY )
+ELSE(ICU_FOUND)
+ IF(ICU_FIND_REQUIRED)
+ MESSAGE( FATAL_ERROR "Could not find ICU" )
+ ELSE(ICU_FIND_REQUIRED)
+ MESSAGE( STATUS "Optional package ICU was not found" )
+ ENDIF(ICU_FIND_REQUIRED)
+ENDIF(ICU_FOUND)
View
@@ -0,0 +1,39 @@
+# - Find re2c executable and provides macros to generate custom build rules
+# The module defines the following variables:
+#
+# RE2C_EXECUTABLE - path to the bison program
+# RE2C_VERSION - version of bison
+# RE2C_FOUND - true if the program was found
+#
+FIND_PROGRAM(RE2C_EXECUTABLE NAMES re2c DOC "path to re2c executable")
+MARK_AS_ADVANCED(RE2C_EXECUTABLE)
+
+IF(RE2C_EXECUTABLE)
+
+ EXECUTE_PROCESS(COMMAND ${RE2C_EXECUTABLE} --vernum
+ RESULT_VARIABLE RE2C_version_result
+ OUTPUT_VARIABLE RE2C_version_output
+ ERROR_VARIABLE RE2C_version_error
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ IF(RE2C_version_result EQUAL 0)
+ message(SEND_ERROR "Command \"${RE2C_EXECUTABLE} --vernum\" failed with output:\n${RE2C_version_error}")
+ ELSE()
+ set(RE2C_VERSION ${RE2C_version_output})
+ ENDIF()
+
+ MACRO(RE2C_TARGET Re2cInput Re2cOutput Args)
+ set(RE2C_EXECUTABLE_opts ${Args})
+
+ ADD_CUSTOM_COMMAND(OUTPUT ${Re2cOutput}
+ COMMAND ${RE2C_EXECUTABLE}
+ ARGS ${RE2C_EXECUTABLE_opts} -o ${Re2cOutput} ${Re2cInput}
+ DEPENDS ${Re2cInput}
+ COMMENT "[RE2C] Building re2c scanner with re2c ${RE2C_VERSION}"
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+
+ ENDMACRO(RE2C_TARGET)
+endif(RE2C_EXECUTABLE)
+
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(RE2C DEFAULT_MSG RE2C_EXECUTABLE)
View
@@ -0,0 +1,113 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8.3)
+SET(CMAKE_CXX_COMPILER "clang++")
+SET(CMAKE_C_COMPILER "clang")
+SET(CMAKE_CXX_FLAGS "-std=c++0x -L.")
+SET(CMAKE_CXX_FLAGS_RELEASE "-Wall -Wno-sign-compare -fstack-protector -fPIC -O2")
+SET(CMAKE_CXX_FLAGS_DEBUG "-g")
+SET(CMAKE_LINK_FLAGS_DEBUG "-Wl,-E' '-Wl,-Bsymbolic' '-rdynamic")
+SET(CMAKE_BUILD_TYPE Release)
+
+PROJECT(tora CXX C)
+
+SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
+
+message(STATUS "module path: ${CMAKE_MODULE_PATH} ${CMAKE_ROOT} ${PROJECT_SOURCE_DIR}")
+
+find_package(ICU REQUIRED)
+if (ICU_VERSION VERSION_LESS "4.2")
+ unset(ICU_FOUND CACHE)
+ unset(ICU_INCLUDE_DIRS CACHE)
+ unset(ICU_LIBRARIES CACHE)
+ message(FATAL_ERROR "ICU is too old, found ${ICU_VERSION} and we need 4.2")
+endif ()
+
+find_package(RE2C REQUIRED)
+
+SET(serial "0.0.0")
+SET(soserial "1")
+
+RE2C_TARGET(
+ tora/lexer.re
+ tora/lexer.gen.cc
+ ""
+)
+# generate files
+ADD_CUSTOM_COMMAND(
+ OUTPUT tora/vm.gen.cc tora/ops.gen.h tora/ops.gen.cc
+ COMMAND perl -I misc/Text-MicroTemplate/ tora/vm.gen.pl
+ DEPENDS tora/vm.gen.pl vm.inc
+)
+ADD_CUSTOM_COMMAND(
+ OUTPUT tora/nodes.gen.h tora/nodes.gen.cc
+ DEPENDS tora/nodes.gen.pl
+ COMMAND perl tora/nodes.gen.pl > tora/nodes.gen.h
+)
+ADD_CUSTOM_COMMAND(
+ OUTPUT tora/symbols.gen.cc tora/symbols.gen.h
+ DEPENDS tora/symbols.gen.pl
+ COMMAND perl -I misc/Text-MicroTemplate/ tora/symbols.gen.pl
+)
+ADD_EXECUTABLE(lemon tools/lemon/lemon.c)
+ADD_CUSTOM_COMMAND(
+ OUTPUT tora/parser.cc tora/parser.h
+ DEPENDS lemon
+ COMMAND ./lemon tora/parser.yy
+)
+ADD_CUSTOM_COMMAND(
+ OUTPUT tora/token.gen.cc tora/token.gen.h
+ DEPENDS tora/token.gen.pl tora/parser.h
+ COMMAND perl tora/token.gen.pl
+)
+SET(TORA_SRCS
+ tora/builtin.cc tora/lexer.gen.cc tora/op.cc tora/peek.cc tora/util.cc
+ tora/compiler.cc tora/operator.cc tora/printf.cc tora/value.cc
+ tora/disasm.cc tora/node.cc tora/ops.gen.cc tora/symbol_table.cc tora/vm.cc
+ tora/frame.cc tora/nodes.gen.cc tora/pad_list.cc tora/symbols.gen.cc tora/vm.gen.cc
+ tora/inspector.cc tora/object.cc tora/parser.cc tora/token.gen.cc
+
+ tora/object/array.cc tora/object/file.cc tora/object/stat.cc tora/value/exception.cc
+ tora/object/bytes.cc tora/object/file_package.cc tora/object/str.cc tora/value/hash.cc
+ tora/object/caller.cc tora/object/hash.cc tora/object/symbol.cc tora/value/int.cc
+ tora/object/class.cc tora/object/int.cc tora/object/time.cc tora/value/object.cc
+ tora/object/code.cc tora/object/internals.cc tora/value/array.cc tora/value/range.cc
+ tora/object/dir.cc tora/object/metaclass.cc tora/value/bool.cc tora/value/regexp.cc
+ tora/object/double.cc tora/object/object.cc tora/value/bytes.cc tora/value/str.cc
+ tora/object/dynaloader.cc tora/object/re2_regexp_matched.cc tora/value/class.cc
+ tora/object/env.cc tora/object/regexp.cc tora/value/code.cc
+)
+
+set(libs re2 pthread dl icudata icuuc boost_system)
+ADD_EXECUTABLE(toraexe ${TORA_SRCS} tora/main.cc)
+ADD_LIBRARY(libtora ${TORA_SRCS})
+SET_TARGET_PROPERTIES(libtora PROPERTIES OUTPUT_NAME "tora")
+TARGET_LINK_LIBRARIES(libtora ${libs})
+TARGET_LINK_LIBRARIES(toraexe "tora" ${libs})
+SET_TARGET_PROPERTIES(toraexe PROPERTIES OUTPUT_NAME "bin/tora")
+
+#############################################################################
+# test settings
+#############################################################################
+FILE(GLOB TEST_CC_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_*.cc")
+set(test_files)
+# ADD_EXECUTABLE(tests/test_lexer.t tests/test_lexer.cc ${TORA_SRCS})
+foreach(f ${TEST_CC_FILES})
+ string(REPLACE ".cc" ".t" _output "${f}")
+ message("test file: ${_output} ${f}")
+ ADD_EXECUTABLE(
+ "${_output}"
+ "${f}"
+ )
+ TARGET_LINK_LIBRARIES("${_output}" "tora" ${libs} dl)
+endforeach(f)
+
+# for src in glob("tests/test_*.cc"):
+# programs.append(env.NoClean(env.Program(src.rstrip(".cc") + '.t' + exe_suffix, [
+# libfiles,
+# src,
+# ])))
+
+# test settings
+ADD_CUSTOM_TARGET(test COMMAND "${PERL_EXECUTABLE}" util/test.pl DEPENDS tora)
+
+# TODO: install
+
Oops, something went wrong.

0 comments on commit 0aa7ed2

Please sign in to comment.