从集合中删除文件 [英] Removing files from a set
问题描述
我有一个目录包含属于一个组成一个Qt项目的文件,而其他文件没有。也就是说,文件A.cxx,ADriver.cxx和A.ui都属于需要使用Qt选项编译的集合。然后我有一个文件B.cxx是非qt。然后C.cxx,CDriver和C.ui是另一个Qt集。有几十个,所以我想使用globs而不是手动写每个add_executable。我正在想像做
for(所有ui文件)
从ui创建一个可执行文件, .cxx和* Driver.cxx
end
(不在上面的循环中使用)是非Qt,需要自己编译我的问题是如何减文件从一个集合。也就是说,使用上面描述的方法,有一个所有的cxx文件的集合,并删除那些在.ui文件循环中使用这是可能的。有更好的方法来做这样的事情吗?
文件(GLOB ALL_SRCS * )
然后选择ui文件并为它们创建Qt目标,从 ALL_SRCS
列表:
文件(GLOB UIS * .ui)
pre>
foreach(ui $ {UIS})
get_filename_component(f $ {ui} NAME_WE)
#Do Qt stuff
qt4_wrap_ui($ {f} uis $ {ui})
qt4_wrap_cpp($ {f} srcs $ {f} .cpp $ {f} Driver.cpp)
add_executable($ {f} $ {f} uis $ {f} srcs)
list(REMOVE_ITEM ALL_SRCS $ {ui} $ {f} .cpp $ {f} Driver.cpp)
endforeach()
之后,您将拥有
ALL_SRCS
中的所有非qt源。I have a directory with files that either belong to a set that makes up a Qt project, and other files that do not. That is, files A.cxx, ADriver.cxx and A.ui all belong to a set that needs to be compiled with Qt options. I then have a file B.cxx that is non-qt. Then C.cxx, CDriver, and C.ui are another Qt set. There are tens of these, so I want to use globs rather than write each add_executable manually. I was thinking of doing something like
for(all ui files) create an executable from the ui and its matching .cxx and *Driver.cxx" end
Then all cxx files that "remain" (not used in the above loop) are non-Qt, and need to be compiled by themselves. My question is how to "subtract" files from a "set". That is, to use the method described above I'd have to have a set of all cxx files, and remove the ones that get used in the .ui file loop. Is this possible? Is there a better way to do something like this?
解决方案First, gather all files with a glob:
file(GLOB ALL_SRCS *)
Then select ui files and create Qt targets for them, substracting them from the
ALL_SRCS
list at the same time:file(GLOB UIS *.ui) foreach(ui ${UIS}) get_filename_component(f ${ui} NAME_WE) # Do Qt stuff qt4_wrap_ui( ${f}uis ${ui} ) qt4_wrap_cpp( ${f}srcs ${f}.cpp ${f}Driver.cpp ) add_executable( ${f} ${f}uis ${f}srcs ) list(REMOVE_ITEM ALL_SRCS ${ui} ${f}.cpp ${f}Driver.cpp) endforeach()
After this you'll have all non-qt sources in
ALL_SRCS
.这篇关于从集合中删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!