Search code examples
cmakeline-endings

Using cmake to compare_files with different line endings


I'm using cmake to compare two files like this:

cmake -E compare_files file1 file2

The trouble is that file1 and file2 have different line endings. I'm using cmake because I already use that for my build; the above command is in my testing.

I don't need anything special at this point. Just a way to tell the user that the files are different. (Hopefully there are no differences.) If there are differences, I'll just report it at this point and manually inspect more closely.

If there is a convenient way of reporting (e.g., print to screen or write to a file) then I'm open to suggestions on how to make that happen. But I'm really just interested in knowing if there are differences and different line endings are unimportant.

Is there a flag or an option that I'm missing that will ignore the difference in line endings?


Solution

  • Update

    As pointed out by nocnokneo, as of CMake 3.14 there is an --ignore-eol option, see merge request

    Original answer

    This was an unsupported feature (issue was tracked here).

    But there's a workaround: you can use configure_file to create a copy of the files with a uniform row endings before starting the comparison. For example:

    configure_file(<input> <output> NEWLINE_STYLE CRLF)
    

    Note that the option COPYONLY is not compatible with NEWLINE_STYLE, so you'll have to take care configure_file doesn't make any unintended variable substitution.