On Tuesday, November 24, 2015 11:01:27 AM Joseph Shen wrote: > 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 :)
Back on list with a more concrete example, and also to prevent others from merging this patch, because I don't think this patch should be accepted. The random string breaks using the Q_INIT_RESOURCE() macro. For example: ======= project(qrc) find_package(Qt4) include(${QT_USE_FILE}) qt4_add_resources(qrc_srcs ${CMAKE_CURRENT_SOURCE_DIR}/my.qrc) add_library(qrc STATIC ${qrc_srcs}) add_executable(main main.cpp) target_link_libraries(main qrc) ======== main.cpp has: int main() { Q_INIT_RESOURCE(my); } With the patch applied, I now get the link error: main.cpp:(.text+0x5): undefined reference to `qInitResources_my()' "my" comes from the basename of my.qrc, and is the name used for the resource. With CMake generating a random name, there would be no way to reference that name when calling Q_INIT_RESOURCE. I would prefer allowing the caller to pass in an alternate -name option for rcc, as I said in my first review. With that, the caller would be able to pass a random string. Clint -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers