-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
77 lines (68 loc) · 2.27 KB
/
CMakeLists.txt
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
cmake_minimum_required(VERSION 3.20)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(CMakeDependentOption)
include(FeatureSummary)
# fetch mruby from source
include(ExternalProject)
ExternalProject_Add(
mruby
URL https://github.com/mruby/mruby/archive/3.2.0.tar.gz
URL_HASH SHA512=bb46fa0eda6507cabe775e3f9cceec6da64d5a96c20e704e7ada94f5b4906989553c363cfd85789c4adcb030a6cfd36b8a99d8247f32687c913bbe06edb9bbca
CONFIGURE_COMMAND
""
BUILD_COMMAND
rake MRUBY_CONFIG=${CMAKE_CURRENT_SOURCE_DIR}/mruby_config.rb INSTALL_DIR=<INSTALL_DIR> MRUBY_BUILD_DIR=<INSTALL_DIR>/build
BUILD_IN_SOURCE true
INSTALL_COMMAND
""
)
ExternalProject_Get_Property(mruby SOURCE_DIR INSTALL_DIR)
ExternalProject_Get_Property(mruby INSTALL_DIR)
set(MRUBY_SOURCE_DIR ${SOURCE_DIR})
set(MRUBY_INSTALL_DIR ${INSTALL_DIR})
set(MRUBY_BUILD_DIR ${MRUBY_INSTALL_DIR}/build/host)
set(MRUBY_LIBS
${MRUBY_BUILD_DIR}/lib/libmruby.a
)
set(MRUBY_INCLUDE_DIRS
${MRUBY_SOURCE_DIR}/include
${MRUBY_BUILD_DIR}/include
)
include_directories(${MRUBY_INCLUDE_DIRS})
add_compile_definitions(
MRB_USE_CXX_ABI
MRB_USE_CXX_EXCEPTION
)
# not using `find_program` for this one as mrbc might not yet exist
set(MRBC_EXECUTABLE "${MRUBY_INSTALL_DIR}/mrbc")
# precompiles .rb files using the freshly built mrbc
function(add_mrbc out_var)
set(result)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mrbc")
foreach(in_f ${ARGN})
get_filename_component(basename ${in_f} NAME_WE)
set(out_f "${CMAKE_CURRENT_BINARY_DIR}/mrbc/${in_f}.cpp")
set(in_f "${CMAKE_CURRENT_SOURCE_DIR}/${in_f}")
file(RELATIVE_PATH out_f_comment ${CMAKE_BINARY_DIR} ${out_f})
add_custom_command(OUTPUT ${out_f}
COMMAND ${MRBC_EXECUTABLE} -B mrbc_${basename} -o ${out_f} ${in_f}
DEPENDS mruby ${in_f}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating mruby bytecode ${out_f_comment}"
VERBATIM
)
list(APPEND result ${out_f})
endforeach()
set(${out_var} "${result}" PARENT_SCOPE)
endfunction()
# configure the rest of our project
project(rj VERSION 0.4.0 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
enable_testing()
add_subdirectory(src)
feature_summary(
FATAL_ON_MISSING_REQUIRED_PACKAGES
WHAT ALL
)