我想添加一个运行perl单行脚本并生成文件的目标。 perl命令如下所示:
perl -MFoo -MBar -E 'perl code inside'
我打印了cmake脚本生成的代码。没关系,虽然有一些额外的空间:
'$obj=ExtUtils::Typemaps->new; $obj->merge(typemap => "ExtUtils::Typemap::STL::String"); $obj->merge(typemap => "ExtUtils::Typemap::ObjectMap"); $obj->write(file => "/home/yangxi/projects/cmake-perlxs/test/build/module_compiled_typemap");'
但是,当我生成项目并运行make(详细)时,我注意到代码中的特定字符已被转换:
'bj=ExtUtils::Typemaps->new \ \ bj->merge(typemap\ =>\ "ExtUtils::Typemap::STL::String") \ bj->merge(typemap\ =>\ "ExtUtils::Typemap::ObjectMap") \ bj->write(file\ =>\ "/home/yangxi/projects/cmake-perlxs/test/build/module_compiled_typemap") '
似乎:
那么如何禁用此功能呢?
这是完整的cmake函数:
function(perlxs_add_typemap_modules typemap_file)
set(typemap_file_global ${CMAKE_CURRENT_BINARY_DIR}/${typemap_file})
message("global typemap file: ${typemap_file_global}")
foreach(curr ${ARGN})
list(APPEND typemap_module_args "-M${curr}")
list(APPEND typemap_script "" "$obj->merge(typemap=>${curr}->new)")
endforeach(curr)
message("module args: ${typemap_module_args}")
message("module script: ${typemap_script}")
set(whole_script "'$obj=ExtUtils::Typemaps->new;${typemap_script};$obj->write(file=>${typemap_file_global})'")
# add typemap compile command
add_custom_command(
OUTPUT ${typemap_file_global}
COMMAND ${PERL_EXECUTABLE} -MExtUtils::Typemaps ${typemap_module_args} -E ${whole_script}
)
# add to typemap file list
set(_XSUBPP_TYPEMAP_FILES ${_XSUBPP_TYPEMAP_FILES};${typemap_file_global} PARENT_SCOPE)
endfunction(perlxs_add_typemap_modules)
使用详细的makefile,这是输出:
/usr/bin/perl -MExtUtils::Typemaps -MExtUtils::Typemap::STL::String -MExtUtils::Typemap::ObjectMap -E 'bj=ExtUtils::Typemaps->new bj->merge(typemap=>ExtUtils::Typemap::STL::String->new) bj->merge(typemap=>ExtUtils::Typemap::ObjectMap->new) bj->write(file=>/home/yangxi/projects/cmake-perlxs/test/build/module_compiled_typemap)'
如果我添加" VERBATIM"在add_custom_command的末尾,输出如下:
/usr/bin/perl -MExtUtils::Typemaps -MExtUtils::Typemap::STL::String -MExtUtils::Typemap::ObjectMap -E "'\$obj=ExtUtils::Typemaps->new" "\$obj->merge(typemap=>ExtUtils::Typemap::STL::String->new)" "\$obj->merge(typemap=>ExtUtils::Typemap::ObjectMap->new)" "\$obj->write(file=>/home/yangxi/projects/cmake-perlxs/test/build/module_compiled_typemap)'"