cmd - How do I run commands longer than 8K symbols using CMake on Windows? -


in ms windows cmd.exe command line length restricted 8192 characters. when calling tool accepts multiple files arguments, easy end lengthy command line, like

git update-index --assume-unchanged file1 file2 file3 ... 

what if case when calling cmake's add_custom_target()/add_custom_command() functions?

we @ kde stumbled upon problem breeze-icons project. used symbolic links extensively, , on windows had resolve them real files somehow. done in ecmwinresolvesymlinks.cmake module.

while implementing had solve long command line problem. split long list of files "list of lists", each sublist shorter 8192. since lists in cmake plain strings delimited ;, can't create such thing "list of lists". had use delimeter, :, differentiate between levels of indirection. after called git in loop each sublist. splitting code looks like:

# in functions _checkout_symlinks() command line can become lengthy windows. # partition it, in hacky way due cmake doesn't have list of lists. function(_portioned_list outvar)   list(length argn arglen)    if(arglen equal 0)     set(${outvar} "" parent_scope)     return()   endif()    set(init)   set(tail)   math(expr range "${arglen} - 1")   foreach(i range ${range})     list(get argn ${i} v)     string(length "${init}" initlen)     string(length ${v} vlen)     math(expr sumlen "${initlen} + ${vlen}")     if(sumlen less 8192)       list(append init ${v})     else()       list(append tail ${v})     endif()   endforeach()    _portioned_list(tail_portioned ${tail})   string(replace ";" ":" init "${init}") # not safe, because filepath can contain ':' character. not on windows. phew.   set(${outvar} ${init} ${tail_portioned} parent_scope) endfunction() 

it can used like:

file(glob ${dir}/* files) _portioned_list(portioned_files ${files}) foreach(fs in lists portioned_files)   # convert cmake list   string(replace ":" ";" fs ${fs})   execute_process(command ${somecommand} ${fs} endforeach() 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -