[cmake-developers] Depends for Qt .qrc files.

Brad King brad.king at kitware.com
Wed Aug 29 11:58:52 EDT 2012


On 08/27/2012 03:53 PM, Rolf Eike Beer wrote:
> Stephen Kelly wrote:
>> Hi,
>>
>> I was looking at 4be6783711b2ff510c3449c5de22d35663d8bfc1 and
>> 3553001bcc425dfb5d84a2dc8d657fe92c007962 with a view to forward porting them
>> to Qt 5, but I think they are still buggy.
>>
>> As xml is not line-based, the parsing should be able to handle legal content
>> like this:
>>
>>   <file
>>     alias="foo">images/star.png</file>
>>
>> The current code does not handle the above, but after reverting the patch
>> (ie, to it's CMake 2.8.9 form), it is handled correctly.
> 
> Because it concatenates everything and does the regex matching then. So, yes, 
> both should be dropped. But, hm, no, that's the wrong way.
> 
> Stephen, I don't believe a single word you are writing. If you could come up 
> with a unit test that you can commit then maybe I could be convinced to trust 
> you and let you revert all that stuff ;)

The net change from those two commits is shown below.  In Stephen's
example the file(STRINGS) will fail to read the line starting in "alias"
because it does not match the regex.  The original read-the-whole-file
approach should be restored unless a better method can be designed.

-Brad


$ git diff 3553001b~2 3553001b -- Modules/Qt4Macros.cmake |cat
diff --git a/Modules/Qt4Macros.cmake b/Modules/Qt4Macros.cmake
index 4324347..6cf16fd 100644
--- a/Modules/Qt4Macros.cmake
+++ b/Modules/Qt4Macros.cmake
@@ -187,7 +187,7 @@ macro (QT4_ADD_RESOURCES outfiles )
     if(EXISTS "${infile}")
       #  parse file for dependencies
       #  all files are absolute paths or relative to the location of the qrc file
-      file(READ "${infile}" _RC_FILE_CONTENTS)
+      file(STRINGS "${infile}" _RC_FILE_CONTENTS REGEX "<file[^>]*>[^<]+")
       string(REGEX MATCHALL "<file[^<]+" _RC_FILES "${_RC_FILE_CONTENTS}")
       foreach(_RC_FILE ${_RC_FILES})
         string(REGEX REPLACE "^<file[^>]*>" "" _RC_FILE "${_RC_FILE}")
@@ -196,6 +196,8 @@ macro (QT4_ADD_RESOURCES outfiles )
         endif()
         set(_RC_DEPENDS ${_RC_DEPENDS} "${_RC_FILE}")
       endforeach()
+      unset(_RC_FILES)
+      unset(_RC_FILE_CONTENTS)
       # Since this cmake macro is doing the dependency scanning for these files,
       # let's make a configured file and add it as a dependency so cmake is run
       # again when dependencies need to be recomputed.



More information about the cmake-developers mailing list