[cmake-developers] [PATCH] Qt4Macros generate resources with same file name

Joseph Shen joseph.smeng at gmail.com
Mon Nov 23 22:01:27 EST 2015


Dear CMake developers:

Please view attached small patch that try to fix Qt4Macros generate
resources with same file name error.

Right now, in the CMake main branch, using cmake with Qt4 library
add resources project can be done like this:

     qt4_add_resources(app_source_res res_a.qrc)
     qt4_add_resources(app_source_res res_b.qrc)

and above two line added two resource file, but if we try to add resource
file with same name, a very subtle error will happen: only one file will
be compile the as resources, and the other was totally ignored.

In some big projects, using the same file name as resource file name
can be very common, especially when we using multi cmake files try
to make the whole project into small ones, in each cmake files someone
maybe just using the same resources file name like res.qrc which is
located in the sub module resources folder.

       qt4_add_resources(app_source_res res.qrc)

so, if they try to do this, and in the last add ${app_source_res} to the
dependency list using:

      add_executable(project_name ${app_source_res} ...)

but in reality they just add one resources file, but CMake do not report
any error or warning.

>From the source of Qt4Macros we can see:

line 211:   get_filename_component(outfilename ${it} NAME_WE)
line 244:   ARGS ${rcc_options} -name ${outfilename} -o ${outfile} ${infile}


became we just using NAME_WE as the output file, if two files with same
file name, one will overwrite the other, and this is the reason why the
error
will happen.

To fix this, I view the whole Qt4Macros source file, find a function
QT4_MAKE_OUTPUT_FILE already exist to do something just what we
need. so I work out a patch add two line code and remove two, and it works
good to me, and I think this might fix the problem.

Please view this patch, thanks :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20151124/ffd2673b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-fix-qt4-generater-resource-file-with-same-name-bug.patch
Type: application/octet-stream
Size: 1007 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20151124/ffd2673b/attachment.obj>


More information about the cmake-developers mailing list