[CMake] Diff output from CMake?

David Cole david.cole at kitware.com
Tue Sep 13 13:58:09 EDT 2011


On Tue, Sep 13, 2011 at 1:39 PM, Alexander Neundorf
<a.neundorf-work at gmx.net> wrote:
> On Tuesday, September 13, 2011 05:07:00 AM Clifford Yapp wrote:
>> I am trying to compare two large lists of file paths (about 14,000 lines
>> each) to identify which entries in each list are missing from the other,
>> and while I can get CMake to do it I must be doing it the wrong way
>> because the results are hideously slow.
>>
>> I currently generate two files with the paths and then read them in as
>> lists, using LIST() commands to peform STREQUAL tests.  I was hoping to
>
> How do you do that ?
> Do you iterate over one list using foreach() and then list(FIND) to check
> whether it exists in the other list ?
>
> Internally, every cmake variable is stored as a plain std::string.
> When using a list() command, this string is converted to a
> std::vector<std::string>, and then cmake operates on this vector.
> So if you do this 14000 times, each time a 14000 std::strings are created,
> which makes this O(n^2) I think.
>
> Maybe something like this works ?
>
> set(uniqueItems ${list1} ${list2})
> list(REMOVE_DUPLICATES uniqueItems )
>
> Or maybe you can do something with sorting both lists first.
>
> Alex
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>

I don't know if this will help at all, but "diff" is available within
the msysGit installation. (Don't know if your project uses git or not,
but if it does, you could use the diff installed with git...)

And another point of interest: there's a test in the CMake test suite
that does use "diff" if it's available. In case it's not available,
the easy fall-back in that test is to emit the full output when
"compare_files" returns that there are diffs, so that a human
inspecting it later can see the diffs by eye, or with a diff tool on a
machine where it *is* available... The script
"Tests/CMakeTestMultipleConfigures/RunCMake.cmake" contains the cmake
script code described here.

I realize this same technique will not be very useful with files
14,000 lines long... but thought I'd mention it so you could look at
it and perhaps draw inspiration from it.

If you could pass along the code that you're using, we might be able
to suggest a better way to achieve the same thing within the CMake
language if that's absolutely necessary.


HTH,
David


More information about the CMake mailing list