Skip to content
This repository
tree: 70916d030c
Fetching contributors…

Cannot retrieve contributors at this time

file 60 lines (51 sloc) 2.174 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
# transform mruby's standard lib into a C library

file(GLOB MRBLIB_SRC_RB "*.rb")

if(CMAKE_CROSSCOMPILING)
  # create native tools and `mrblib.ctmp` required to build `mrblib.c`
  include(ExternalProject)
  ExternalProject_Add(mruby-native
    DOWNLOAD_COMMAND ""
    SOURCE_DIR "${CMAKE_SOURCE_DIR}"
    CONFIGURE_COMMAND "${CMAKE_COMMAND}" "${CMAKE_SOURCE_DIR}"
    INSTALL_COMMAND ""
    BINARY_DIR "${CMAKE_BINARY_DIR}/native"
    )

  # aggregate mruby's standard library as a single C file
  add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mrblib.c"
    DEPENDS mruby-native init_mrblib.c "${CMAKE_BINARY_DIR}/native/mrblib/mrblib.ctmp"
    COMMAND "${CMAKE_BINARY_DIR}/native/tools/xpcat/xpcat"
            -o "${CMAKE_CURRENT_BINARY_DIR}/mrblib.c"
            "${CMAKE_CURRENT_SOURCE_DIR}/init_mrblib.c"
            "${CMAKE_BINARY_DIR}/native/mrblib/mrblib.ctmp"
    )
else()
  # generate a single rb file from all existing ones
  add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mrblib.rbtmp"
    DEPENDS xpcat
    COMMAND xpcat -o "${CMAKE_CURRENT_BINARY_DIR}/mrblib.rbtmp" ${MRBLIB_SRC_RB}
    )

  # mruby compile and generate C byte array representation
  add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mrblib.ctmp"
    DEPENDS mrbc "${CMAKE_CURRENT_BINARY_DIR}/mrblib.rbtmp"
    COMMAND mrbc -Bmrblib_irep -o"${CMAKE_CURRENT_BINARY_DIR}/mrblib.ctmp"
                 "${CMAKE_CURRENT_BINARY_DIR}/mrblib.rbtmp"
    )

  # aggregate mruby's standard library as a single C file
  add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mrblib.c"
    DEPENDS xpcat init_mrblib.c "${CMAKE_CURRENT_BINARY_DIR}/mrblib.ctmp"
    COMMAND xpcat -o "${CMAKE_CURRENT_BINARY_DIR}/mrblib.c"
                     "${CMAKE_CURRENT_SOURCE_DIR}/init_mrblib.c"
                     "${CMAKE_CURRENT_BINARY_DIR}/mrblib.ctmp"
    )
endif()


# generate final static libmruby archive library
add_library(libmruby_static STATIC
  mrblib.c
  $<TARGET_OBJECTS:mruby_object>
  )
set_target_properties(libmruby_static PROPERTIES OUTPUT_NAME mruby)

install(TARGETS libmruby_static
  LIBRARY DESTINATION lib
  ARCHIVE DESTINATION lib
  )

# vim: ts=2 sts=2 sw=2 et
Something went wrong with that request. Please try again.