我想在cmake中使用mustache作为简单的模板引擎来生成代码。
我尝试使用execute_process
执行它,如下所示:
execute_process( COMMAND "/path/to/mustache" "<data> <template>" )
但它说它不是一个有效的WIN32应用程序。事实上,小胡子是一个红宝石剧本:
#!D:/programs/Ruby23/bin/ruby.exe
#
# This file was generated by RubyGems.
#
# The application 'mustache' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0.a"
if ARGV.first
...
所以我试过了:
execute_process( COMMAMD "/path/to/ruby" "/path/to/mustache --help" )
但它不起作用...... No such file or directory -- D:/programs/Ruby23/bin/mustache --help (LoadError)
如何在cmake execute_process中执行ruby脚本?
答案 0 :(得分:1)
execute_process(COMMAND&lt; cmd1&gt; [args1 ...]] ...)
参数必须作为列表传递,而不是作为字符串传递。
# path to executables
set(RUBY_EXECUTABLE D:/programs/Ruby23/bin/ruby.exe CACHE STRING "ruby executable")
set(MUSTACHE_SCRIPT D:/programs/Ruby23/bin/mustache CACHE STRING "mustache ruby script")
# function that call mustache
function(apply_mustache data template result)
execute_process(
COMMAND ${RUBY_EXECUTABLE} -E UTF-8 ${MUSTACHE_SCRIPT} ${data} ${template}
OUTPUT_VARIABLE result_t
)
set(${result} ${result_t} PARENT_SCOPE)
endfunction()
奖励:-E UTF-8
防止红宝石乱用utf-8字符......