Skip to content

Commit 344f189

Browse files
authored
Merge pull request #54 from picoruby/fix_compiling_ruby_files_in_cmake
Modified to ensure Ruby files are reliably compiled within CMakeLists…
2 parents f2fdc91 + ef7cd77 commit 344f189

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

CMakeLists.txt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,23 @@ add_custom_target(
8282
add_dependencies(${COMPONENT_LIB} picoruby)
8383

8484
# Compile Ruby files
85-
add_custom_target(
86-
mrbdir ALL
87-
COMMAND ${CMAKE_COMMAND} -E make_directory ${COMPONENT_DIR}/mrb
88-
)
89-
add_dependencies(mrbdir picoruby)
90-
9185
set(RUBY_FILES main_task)
9286
set(PICORBC ${COMPONENT_DIR}/picoruby/bin/picorbc)
87+
set(GENERATED_C_FILES "")
9388

9489
foreach(rb ${RUBY_FILES})
95-
add_custom_target(${rb}
96-
COMMAND echo "Compile Ruby files." && ${PICORBC} -B${rb} -o${COMPONENT_DIR}/mrb/${rb}.c ${COMPONENT_DIR}/mrblib/${rb}.rb && ls ${COMPONENT_DIR}/mrb
97-
DEPENDS mrbdir
98-
)
99-
add_dependencies(${rb} picoruby)
90+
set(C_FILE ${COMPONENT_DIR}/mrb/${rb}.c)
91+
set(RB_FILE ${COMPONENT_DIR}/mrblib/${rb}.rb)
92+
add_custom_command(
93+
OUTPUT ${C_FILE}
94+
COMMAND ${CMAKE_COMMAND} -E echo "Compiling ${RB_FILE}..."
95+
COMMAND ${CMAKE_COMMAND} -E make_directory ${COMPONENT_DIR}/mrb
96+
COMMAND ${PICORBC} -B${rb} -o${C_FILE} ${RB_FILE}
97+
DEPENDS picoruby ${RB_FILE}
98+
COMMENT "Compiling ${RB_FILE}"
99+
VERBATIM
100+
)
101+
list(APPEND GENERATED_C_FILES ${C_FILE})
100102
endforeach(rb)
101103

102-
add_custom_target(generate_files ALL DEPENDS mrbdir ${RUBY_FILES})
103-
add_dependencies(generate_files picoruby)
104+
target_sources(${COMPONENT_LIB} PRIVATE ${GENERATED_C_FILES})

0 commit comments

Comments
 (0)