Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cmake 从集合中删除文件_Cmake - Fatal编程技术网

Cmake 从集合中删除文件

Cmake 从集合中删除文件,cmake,Cmake,我有一个目录,其中包含属于组成Qt项目的集合的文件,以及其他不属于该集合的文件。也就是说,文件A.cxx、ADriver.cxx和A.ui都属于需要使用Qt选项编译的集合。然后我有一个非qt的文件B.cxx。然后C.cxx、CDriver和C.ui是另一个Qt集。有几十种,所以我想使用globs,而不是手动编写每个add_可执行文件。我在考虑做类似的事情 for(all ui files) create an executable from the ui and its matching

我有一个目录,其中包含属于组成Qt项目的集合的文件,以及其他不属于该集合的文件。也就是说,文件A.cxx、ADriver.cxx和A.ui都属于需要使用Qt选项编译的集合。然后我有一个非qt的文件B.cxx。然后C.cxx、CDriver和C.ui是另一个Qt集。有几十种,所以我想使用globs,而不是手动编写每个add_可执行文件。我在考虑做类似的事情

for(all ui files) 
  create an executable from the ui and its matching .cxx and *Driver.cxx"
end

那么所有“保留”(在上述循环中未使用)的cxx文件都是非Qt文件,需要自己编译。我的问题是如何从“集合”中“减去”文件。也就是说,要使用上述方法,我必须拥有一组所有cxx文件,并删除在.ui文件循环中使用的文件。这可能吗?有没有更好的方法来执行类似操作?

首先,使用glob收集所有文件:

file(GLOB ALL_SRCS *)
然后选择ui文件并为它们创建Qt目标,同时从
所有\u SRCS
列表中删除它们:

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()

在此之后,您将在
所有SRCS

@arrowsdodget-Ah中拥有所有非qt源,我认为删除项目正是我要寻找的。一旦我尝试一下,我就会接受答案——谢谢!