2017-02-16 63 views
0

我想在cmake中使用mustache作爲簡單的模板引擎來生成代碼。在cmake中執行小鬍子(作爲ruby腳本)execute_process

我試着用execute_process執行它如下:

execute_process(COMMAND "/path/to/mustache" "<data> <template>") 

但它表示,它不是有效的Win32應用程序。事實上,鬍子是一個Ruby腳本:

#!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 Ruby腳本execute_process?

+0

'但它不工作,要麼...' - 它說,紅寶石是不是WIN32應用程序呢?或者是什麼? – Tsyvarev

+0

沒有這樣的文件或目錄 - D:/ programs/Ruby23/bin/mustache --help(LoadError) – jvtrudel

+0

ok。這些提示必須作爲列表傳遞......''''execute_process(COMMAMD「/ path/to/ruby​​」「/ path/to/mustache」「--help」)''''謝謝你的提示。 – jvtrudel

回答

1

execute_process(COMMAND < CMD1> [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字符...