2008-03-25 18:27:18 +03:00
|
|
|
cmake_minimum_required (VERSION 2.6)
|
2012-08-13 21:47:32 +04:00
|
|
|
project(TarTest)
|
2005-12-30 23:27:17 +03:00
|
|
|
|
|
|
|
# this is macro that we will be running
|
2012-08-13 21:47:32 +04:00
|
|
|
macro(EXEC_TAR_COMMAND DIR ARGS)
|
|
|
|
exec_program("${CMAKE_COMMAND}" "${DIR}" ARGS "-E tar ${ARGS}" RETURN_VALUE RET)
|
|
|
|
if(${RET})
|
|
|
|
message(FATAL_ERROR "CMake tar command failed with arguments \"${ARGS}\"")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
|
|
|
endmacro()
|
2005-12-30 23:27:17 +03:00
|
|
|
|
|
|
|
# Create a directory structure
|
2012-08-13 21:47:32 +04:00
|
|
|
set(CHECK_FILES)
|
|
|
|
macro(COPY F1 F2)
|
|
|
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${F1}" "${CMAKE_CURRENT_BINARY_DIR}/tar_dir/${F2}" COPYONLY)
|
|
|
|
set(CHECK_FILES ${CHECK_FILES} "${F2}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endmacro()
|
2005-12-30 23:27:17 +03:00
|
|
|
COPY("CMakeLists.txt" "f1.txt")
|
|
|
|
COPY("CMakeLists.txt" "d1/f1.txt")
|
|
|
|
COPY("CMakeLists.txt" "d 2/f1.txt")
|
|
|
|
COPY("CMakeLists.txt" "d + 3/f1.txt")
|
|
|
|
COPY("CMakeLists.txt" "d_4/f1.txt")
|
|
|
|
COPY("CMakeLists.txt" "d-4/f1.txt")
|
|
|
|
COPY("CMakeLists.txt" "My Special Directory/f1.txt")
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(UNIX)
|
|
|
|
exec_program("ln" ARGS "-sf f1.txt \"${CMAKE_CURRENT_BINARY_DIR}/tar_dir/d1/f2.txt\"")
|
|
|
|
set(CHECK_FILES ${CHECK_FILES} "d1/f2.txt")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2005-12-30 23:27:17 +03:00
|
|
|
|
2009-11-09 20:48:31 +03:00
|
|
|
# cleanup first in case there are files left from previous runs
|
|
|
|
# if the umask is odd on the machine it might create files that
|
|
|
|
# are not automatically over written. These tests are run
|
|
|
|
# each time the configure step is run.
|
2012-08-13 21:47:32 +04:00
|
|
|
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/test_tar.tar")
|
|
|
|
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/test_tgz.tgz")
|
|
|
|
file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/test_output_tar")
|
|
|
|
file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/test_output_tgz")
|
2009-11-09 20:48:31 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
make_directory("${CMAKE_CURRENT_BINARY_DIR}/test_output_tar")
|
|
|
|
make_directory("${CMAKE_CURRENT_BINARY_DIR}/test_output_tgz")
|
2005-12-30 23:27:17 +03:00
|
|
|
|
2009-11-09 20:48:31 +03:00
|
|
|
|
2005-12-30 23:27:17 +03:00
|
|
|
# Run tests
|
|
|
|
EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}" "cvf \"${CMAKE_CURRENT_BINARY_DIR}/test_tar.tar\" tar_dir")
|
|
|
|
EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}" "cvfz \"${CMAKE_CURRENT_BINARY_DIR}/test_tgz.tgz\" tar_dir")
|
|
|
|
|
|
|
|
EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}/test_output_tar" "xvf \"${CMAKE_CURRENT_BINARY_DIR}/test_tar.tar\"")
|
|
|
|
EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}/test_output_tgz" "xvfz \"${CMAKE_CURRENT_BINARY_DIR}/test_tgz.tgz\"")
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
macro(CHECK_DIR_STRUCTURE DIR)
|
|
|
|
foreach(file ${CHECK_FILES})
|
|
|
|
set(sfile "${DIR}/${file}")
|
|
|
|
set(rfile "${CMAKE_CURRENT_BINARY_DIR}/tar_dir/${file}")
|
|
|
|
if(NOT EXISTS "${sfile}")
|
|
|
|
message(SEND_ERROR "Cannot find file ${sfile}")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2012-08-13 21:47:32 +04:00
|
|
|
exec_program("${CMAKE_COMMAND}" ARGS "-E compare_files \"${sfile}\" \"${rfile}\"" RETURN_VALUE ret)
|
|
|
|
if(${ret})
|
|
|
|
message(SEND_ERROR "Files \"${sfile}\" \"${rfile}\" are different")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endmacro()
|
2005-12-30 23:27:17 +03:00
|
|
|
|
|
|
|
CHECK_DIR_STRUCTURE("${CMAKE_CURRENT_BINARY_DIR}/test_output_tar/tar_dir")
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
add_executable(TarTest TestTarExec.cxx)
|
2005-12-30 23:27:17 +03:00
|
|
|
|