mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-09 17:18:18 +00:00
Use `cmake -E create_symlink` or `file(CREATE_LINK)` as appropriate instead of `ln -sf` on UNIX only to extend cases of (a) symlinks inside archives and (b) archive extraction to a directory symlink to non-UNIX platforms where either of these modes may be supported. The latter relies on the NEW behavior of CMP0205 as it uses `COPY_ON_ERROR` for platforms where directory symlinks aren't supported. Issue: #27756
92 lines
2.5 KiB
CMake
92 lines
2.5 KiB
CMake
foreach(parameter OUTPUT_NAME ARCHIVE_FORMAT)
|
|
if(NOT DEFINED ${parameter})
|
|
message(FATAL_ERROR "missing required parameter ${parameter}")
|
|
endif()
|
|
endforeach()
|
|
|
|
set(COMPRESS_DIR compress_dir)
|
|
set(FULL_COMPRESS_DIR ${CMAKE_CURRENT_BINARY_DIR}/${COMPRESS_DIR})
|
|
|
|
set(DECOMPRESS_DIR decompress_dir)
|
|
set(FULL_DECOMPRESS_DIR ${CMAKE_CURRENT_BINARY_DIR}/${DECOMPRESS_DIR})
|
|
|
|
set(FULL_OUTPUT_NAME ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME})
|
|
|
|
set(CHECK_FILES
|
|
"f1.txt"
|
|
"d1/f1.txt"
|
|
"d 2/f1.txt"
|
|
"d + 3/f1.txt"
|
|
"d_4/f1.txt"
|
|
"d-4/f1.txt"
|
|
"My Special Directory/f1.txt"
|
|
)
|
|
|
|
function(check_compression_level COMPRESSION_LEVEL)
|
|
foreach(file ${CHECK_FILES})
|
|
configure_file(${CMAKE_CURRENT_LIST_FILE} ${FULL_COMPRESS_DIR}/${file} COPYONLY)
|
|
endforeach()
|
|
|
|
# Test a (file) symlink inside the archive on platforms which support it.
|
|
execute_process(
|
|
COMMAND ${CMAKE_COMMAND} -E create_symlink f1.txt ${FULL_COMPRESS_DIR}/d1/f2.txt
|
|
OUTPUT_VARIABLE create_symlink_stdout
|
|
ERROR_VARIABLE create_symlink_stderr
|
|
RESULT_VARIABLE create_symlink_result
|
|
)
|
|
if(create_symlink_result EQUAL 0 AND EXISTS "${FULL_COMPRESS_DIR}/d1/f2.txt")
|
|
list(APPEND CHECK_FILES "d1/f2.txt")
|
|
endif()
|
|
|
|
file(REMOVE ${FULL_OUTPUT_NAME})
|
|
file(REMOVE_RECURSE ${FULL_DECOMPRESS_DIR})
|
|
file(MAKE_DIRECTORY ${FULL_DECOMPRESS_DIR})
|
|
|
|
file(ARCHIVE_CREATE
|
|
OUTPUT ${FULL_OUTPUT_NAME}
|
|
FORMAT "${ARCHIVE_FORMAT}"
|
|
COMPRESSION "${COMPRESSION_TYPE}"
|
|
COMPRESSION_LEVEL ${COMPRESSION_LEVEL}
|
|
VERBOSE
|
|
PATHS ${COMPRESS_DIR})
|
|
|
|
file(ARCHIVE_EXTRACT
|
|
INPUT ${FULL_OUTPUT_NAME}
|
|
${DECOMPRESSION_OPTIONS}
|
|
DESTINATION ${FULL_DECOMPRESS_DIR}
|
|
VERBOSE)
|
|
|
|
if(CUSTOM_CHECK_FILES)
|
|
set(CHECK_FILES ${CUSTOM_CHECK_FILES})
|
|
endif()
|
|
|
|
foreach(file ${CHECK_FILES})
|
|
set(input ${FULL_COMPRESS_DIR}/${file})
|
|
set(output ${FULL_DECOMPRESS_DIR}/${COMPRESS_DIR}/${file})
|
|
|
|
if(NOT EXISTS ${input})
|
|
message(SEND_ERROR "Cannot find input file ${output}")
|
|
endif()
|
|
|
|
if(NOT EXISTS ${output})
|
|
message(SEND_ERROR "Cannot find output file ${output}")
|
|
endif()
|
|
|
|
file(MD5 ${input} input_md5)
|
|
file(MD5 ${output} output_md5)
|
|
|
|
if(NOT input_md5 STREQUAL output_md5)
|
|
message(SEND_ERROR "Files \"${input}\" and \"${output}\" are different")
|
|
endif()
|
|
endforeach()
|
|
|
|
foreach(file ${NOT_EXISTING_FILES_CHECK})
|
|
set(output ${FULL_DECOMPRESS_DIR}/${COMPRESS_DIR}/${file})
|
|
|
|
if(EXISTS ${output})
|
|
message(SEND_ERROR "File ${output} exists but it shouldn't")
|
|
endif()
|
|
endforeach()
|
|
|
|
endfunction()
|