From: Nathan Moinvaziri Date: Sun, 20 Sep 2020 23:01:03 +0000 (-0700) Subject: Added option to normalize line-endings in CMake run-and-compare script. X-Git-Tag: 1.9.9-b1~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e342c0c96c9fe00b1a1feb1cfad4502fee9f49c9;p=thirdparty%2Fzlib-ng.git Added option to normalize line-endings in CMake run-and-compare script. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bdf9c7d..ce103f6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1089,6 +1089,7 @@ if(ZLIB_ENABLE_TESTS) "-DCOMMAND=${MAKEFIXED_COMMAND}" -DOUTPUT=${CMAKE_CURRENT_SOURCE_DIR}/inffixed_tbl._h -DCOMPARE=${CMAKE_CURRENT_SOURCE_DIR}/inffixed_tbl.h + -DIGNORE_LINE_ENDINGS=ON -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/run-and-compare.cmake) add_executable(maketrees tools/maketrees.c trees.c zutil.c) @@ -1100,6 +1101,7 @@ if(ZLIB_ENABLE_TESTS) "-DCOMMAND=${MAKETREES_COMMAND}" -DOUTPUT=${CMAKE_CURRENT_SOURCE_DIR}/trees_tbl._h -DCOMPARE=${CMAKE_CURRENT_SOURCE_DIR}/trees_tbl.h + -DIGNORE_LINE_ENDINGS=ON -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/run-and-compare.cmake) add_executable(makecrct tools/makecrct.c) @@ -1111,6 +1113,7 @@ if(ZLIB_ENABLE_TESTS) "-DCOMMAND=${MAKECRCT_COMMAND}" -DOUTPUT=${CMAKE_CURRENT_SOURCE_DIR}/crc32_tbl._h -DCOMPARE=${CMAKE_CURRENT_SOURCE_DIR}/crc32_tbl.h + -DIGNORE_LINE_ENDINGS=ON -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/run-and-compare.cmake) if(WITH_FUZZERS) diff --git a/cmake/run-and-compare.cmake b/cmake/run-and-compare.cmake index 62657992..0e934337 100644 --- a/cmake/run-and-compare.cmake +++ b/cmake/run-and-compare.cmake @@ -25,11 +25,24 @@ if(CMD_RESULT) message(FATAL_ERROR "Run before compare failed: ${CMD_RESULT}") endif() +# Use configure_file to normalize line-endings +if(IGNORE_LINE_ENDINGS) + configure_file(${COMPARE} ${COMPARE}.cmp NEWLINE_STYLE LF) + set(COMPARE ${COMPARE}.cmp) + configure_file(${OUTPUT} ${OUTPUT}.cmp NEWLINE_STYLE LF) + set(OUTPUT ${OUTPUT}.cmp) +endif() + # Compare that output is equal to specified file execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files ${COMPARE} ${OUTPUT} RESULT_VARIABLE CMD_RESULT) +# Delete temporary files used to normalize line-endings +if(IGNORE_LINE_ENDINGS) + file(REMOVE ${COMPARE} ${OUTPUT}) +endif() + if(CMD_RESULT) message(FATAL_ERROR "Run compare failed: ${CMD_RESULT}") endif() \ No newline at end of file