| 1 |
foreach(parameter OUTPUT_NAME ARCHIVE_FORMAT) |
| 2 |
if(NOT DEFINED ${parameter}) |
| 3 |
message(FATAL_ERROR "missing required parameter ${parameter}") |
| 4 |
endif() |
| 5 |
endforeach() |
| 6 |
|
| 7 |
set(COMPRESS_DIR compress_dir) |
| 8 |
set(FULL_COMPRESS_DIR ${CMAKE_CURRENT_BINARY_DIR}/${COMPRESS_DIR}) |
| 9 |
|
| 10 |
set(DECOMPRESS_DIR decompress_dir) |
| 11 |
set(FULL_DECOMPRESS_DIR ${CMAKE_CURRENT_BINARY_DIR}/${DECOMPRESS_DIR}) |
| 12 |
|
| 13 |
set(FULL_OUTPUT_NAME ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}) |
| 14 |
|
| 15 |
set(CHECK_FILES |
| 16 |
"f1.txt" |
| 17 |
"d1/f1.txt" |
| 18 |
"d 2/f1.txt" |
| 19 |
"d + 3/f1.txt" |
| 20 |
"d_4/f1.txt" |
| 21 |
"d-4/f1.txt" |
| 22 |
"My Special Directory/f1.txt" |
| 23 |
) |
| 24 |
|
| 25 |
function(check_threads THREADS) |
| 26 |
foreach(file ${CHECK_FILES}) |
| 27 |
configure_file(${CMAKE_CURRENT_LIST_FILE} ${FULL_COMPRESS_DIR}/${file} COPYONLY) |
| 28 |
endforeach() |
| 29 |
|
| 30 |
# Test a (file) symlink inside the archive on platforms which support it. |
| 31 |
execute_process( |
| 32 |
COMMAND ${CMAKE_COMMAND} -E create_symlink f1.txt ${FULL_COMPRESS_DIR}/d1/f2.txt |
| 33 |
OUTPUT_VARIABLE create_symlink_stdout |
| 34 |
ERROR_VARIABLE create_symlink_stderr |
| 35 |
RESULT_VARIABLE create_symlink_result |
| 36 |
) |
| 37 |
if(create_symlink_result EQUAL 0 AND EXISTS "${FULL_COMPRESS_DIR}/d1/f2.txt") |
| 38 |
list(APPEND CHECK_FILES "d1/f2.txt") |
| 39 |
endif() |
| 40 |
|
| 41 |
file(REMOVE ${FULL_OUTPUT_NAME}) |
| 42 |
file(REMOVE_RECURSE ${FULL_DECOMPRESS_DIR}) |
| 43 |
file(MAKE_DIRECTORY ${FULL_DECOMPRESS_DIR}) |
| 44 |
|
| 45 |
file(ARCHIVE_CREATE |
| 46 |
OUTPUT ${FULL_OUTPUT_NAME} |
| 47 |
FORMAT "${ARCHIVE_FORMAT}" |
| 48 |
COMPRESSION "${COMPRESSION_TYPE}" |
| 49 |
THREADS ${THREADS} |
| 50 |
VERBOSE |
| 51 |
PATHS ${COMPRESS_DIR}) |
| 52 |
|
| 53 |
file(ARCHIVE_EXTRACT |
| 54 |
INPUT ${FULL_OUTPUT_NAME} |
| 55 |
${DECOMPRESSION_OPTIONS} |
| 56 |
DESTINATION ${FULL_DECOMPRESS_DIR} |
| 57 |
VERBOSE) |
| 58 |
|
| 59 |
if(CUSTOM_CHECK_FILES) |
| 60 |
set(CHECK_FILES ${CUSTOM_CHECK_FILES}) |
| 61 |
endif() |
| 62 |
|
| 63 |
foreach(file ${CHECK_FILES}) |
| 64 |
set(input ${FULL_COMPRESS_DIR}/${file}) |
| 65 |
set(output ${FULL_DECOMPRESS_DIR}/${COMPRESS_DIR}/${file}) |
| 66 |
|
| 67 |
if(NOT EXISTS ${input}) |
| 68 |
message(SEND_ERROR "Cannot find input file ${output}") |
| 69 |
endif() |
| 70 |
|
| 71 |
if(NOT EXISTS ${output}) |
| 72 |
message(SEND_ERROR "Cannot find output file ${output}") |
| 73 |
endif() |
| 74 |
|
| 75 |
file(MD5 ${input} input_md5) |
| 76 |
file(MD5 ${output} output_md5) |
| 77 |
|
| 78 |
if(NOT input_md5 STREQUAL output_md5) |
| 79 |
message(SEND_ERROR "Files \"${input}\" and \"${output}\" are different") |
| 80 |
endif() |
| 81 |
endforeach() |
| 82 |
|
| 83 |
foreach(file ${NOT_EXISTING_FILES_CHECK}) |
| 84 |
set(output ${FULL_DECOMPRESS_DIR}/${COMPRESS_DIR}/${file}) |
| 85 |
|
| 86 |
if(EXISTS ${output}) |
| 87 |
message(SEND_ERROR "File ${output} exists but it shouldn't") |
| 88 |
endif() |
| 89 |
endforeach() |
| 90 |
|
| 91 |
endfunction() |