Delete files from a set

I have a directory with files that either belong to the set that makes up the Qt project, and to other files that don't. That is, the files A.cxx, ADriver.cxx and A.ui belong to the set that must be compiled with the Qt parameters. Then I have a B.cxx file which is not qt. Then C.cxx, CDriver, and C.ui are another set of Qt. There are dozens of them, so I want to use globs, and not 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 must be compiled on their own. My question is how to β€œsubtract” files from a β€œset”. That is, to use the method described above, I will have to have a set of all cxx files and delete those that are used in the loop of the .ui file. Is it possible? Is there a better way to do something like this?

+7
source share
1 answer

First, collect all the files using glob:

 file(GLOB ALL_SRCS *) 

Then select the ui files and create Qt targets for them by subtracting 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 that, you will have all sources without qt in ALL_SRCS .

+8
source

All Articles