Created
May 26, 2021 16:50
-
-
Save a7ul/4b4ccda7781658f97f00d064de8dfb25 to your computer and use it in GitHub Desktop.
Compile QuickJs binaries using cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Instructions | |
# ============ | |
# 1. mkdir qjs && cd qjs | |
# 2. git clone https://github.com/bellard/quickjs.git quickjs | |
# 3. Copy this file as CMakeLists.txt | |
# 4. mkdir build && cd build | |
# 5. cmake .. && make | |
# 6. You can now find the binaries qjs and qjsc in the build folder. | |
cmake_minimum_required(VERSION 3.9...3.20) | |
project(QuickJS | |
VERSION 1.0 | |
DESCRIPTION "QuickJS" | |
) | |
# QJS LIB | |
file(STRINGS | |
"${CMAKE_SOURCE_DIR}/quickjs/VERSION" | |
QUICK_JS_VERSION | |
) | |
add_library(quickjs STATIC | |
"${CMAKE_SOURCE_DIR}/quickjs/quickjs.c" | |
"${CMAKE_SOURCE_DIR}/quickjs/libregexp.c" | |
"${CMAKE_SOURCE_DIR}/quickjs/libunicode.c" | |
"${CMAKE_SOURCE_DIR}/quickjs/cutils.c" | |
"${CMAKE_SOURCE_DIR}/quickjs/libbf.c" | |
"${CMAKE_SOURCE_DIR}/quickjs/quickjs-libc.c" | |
) | |
target_compile_definitions(quickjs PUBLIC | |
CONFIG_VERSION="${QUICK_JS_VERSION}" | |
CONFIG_BIGNUM=1 | |
) | |
# QJSC | |
add_executable(qjsc | |
"${CMAKE_SOURCE_DIR}/quickjs/qjsc.c" | |
) | |
target_link_libraries(qjsc | |
quickjs | |
) | |
# QJS | |
add_custom_command( | |
OUTPUT qjscalc.c qjsrepl.c | |
DEPENDS qjsc | |
COMMAND ./qjsc -fbignum -c -o qjscalc.c ../quickjs/qjscalc.js | |
COMMAND ./qjsc -c -o qjsrepl.c -m ../quickjs/repl.js | |
COMMENT "Preprocessing qjscalc.c and qjsrepl.c from js files" | |
VERBATIM | |
) | |
add_library(qjscalc | |
"${CMAKE_CURRENT_BINARY_DIR}/qjscalc.c" | |
) | |
add_library(qjsrepl | |
"${CMAKE_CURRENT_BINARY_DIR}/qjsrepl.c" | |
) | |
add_executable(qjs | |
"${CMAKE_SOURCE_DIR}/quickjs/qjs.c" | |
) | |
target_link_libraries(qjs | |
quickjs | |
qjscalc | |
qjsrepl | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment