LoginSignup
0
0

More than 1 year has passed since last update.

hermes(JavaScript engine)を C++14 アプリに組み込むメモ

Last updated at Posted at 2021-05-10

C++ アプリに JavaScript エンジン組み込みたい(JS で制御とか).
Duktape もいいけど,

グラフィックス処理などでパフォーマンスがほしいときもある.

hermes を考えます.

C++14 + cmake で依存ライブラリも一緒に入っている + MIT ライセンスで, 自前 C++ アプリに組み込みやすくなっています.

基本 add_subdirectory() でいけます.
ただ, hermes の CMakeLists.ext では global な add_definition とかしているので, 自前アプリや他の submodule となにかかち合うかもしれませんので注意しておきましょう.

また, hermes ライブラリは add_target_libraries に追加しても, うまくパスとおしてくれないようです. 自前でインクルードパス指定必要です.

binary(build)ディレクトリに hermes/Support/Config.h が生成されるのでこれへのパスも通しておきます.

  # 必要に応じて hermes の cmake オプション設定を上書き(override)
  # ...

  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/hermes hermes)


  set(EXT_LIBRARIES
    hermesVMRuntime
    hermesCompilerDriver
    hermesConsoleHost
    hermesAST
    hermesHBCBackend
    hermesBackend
    hermesOptimizer
    hermesFrontend
    hermesParser
    hermesSourceMap
    hermesSupport
    dtoa
    hermesInstrumentation
  )

  # hermes/Support/Config.h
  target_include_directories(${TARGET} PUBLIC ${CMAKE_BINARY_DIR}/hermes/include)

  target_include_directories(${TARGET} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/third_party/hermes/include)

とりあえずはこんな感じでしょうか.

あとは $hermes/tools/hermes/ あたりの repl サンプルを参考にすればいけるはず... です!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0