Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing files from a set

Tags:

cmake

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?

like image 951
David Doria Avatar asked Oct 29 '12 00:10

David Doria


People also ask

How do I delete files from a directory?

Locate the item you want to delete, highlight it by left-clicking the file or folder with your mouse once, and press the Delete key.

What command is used to remove files?

Use the rm command to remove files you no longer need. The rm command removes the entries for a specified file, group of files, or certain select files from a list within a directory. User confirmation, read permission, and write permission are not required before a file is removed when you use the rm command.

How do you remove a file that Cannot be removed?

One is simply using the delete option, and the other one is deleting files permanently. When you can't delete a file normally, you can delete undeletable files Windows 10 by selecting the target file or folder and then press Shift + Delete keys on the keyboard for a try.


1 Answers

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.

like image 113
arrowd Avatar answered Sep 20 '22 14:09

arrowd