CMakeLists.txt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. cmake_minimum_required (VERSION 2.6)
  2. project(TarTest)
  3. # this is macro that we will be running
  4. macro(EXEC_TAR_COMMAND DIR ARGS)
  5. exec_program("${CMAKE_COMMAND}" "${DIR}" ARGS "-E tar ${ARGS}" RETURN_VALUE RET)
  6. if(${RET})
  7. message(FATAL_ERROR "CMake tar command failed with arguments \"${ARGS}\"")
  8. endif()
  9. endmacro()
  10. # Create a directory structure
  11. set(CHECK_FILES)
  12. macro(COPY F1 F2)
  13. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${F1}" "${CMAKE_CURRENT_BINARY_DIR}/tar_dir/${F2}" COPYONLY)
  14. set(CHECK_FILES ${CHECK_FILES} "${F2}")
  15. endmacro()
  16. COPY("CMakeLists.txt" "f1.txt")
  17. COPY("CMakeLists.txt" "d1/f1.txt")
  18. COPY("CMakeLists.txt" "d 2/f1.txt")
  19. COPY("CMakeLists.txt" "d + 3/f1.txt")
  20. COPY("CMakeLists.txt" "d_4/f1.txt")
  21. COPY("CMakeLists.txt" "d-4/f1.txt")
  22. COPY("CMakeLists.txt" "My Special Directory/f1.txt")
  23. if(UNIX)
  24. exec_program("ln" ARGS "-sf f1.txt \"${CMAKE_CURRENT_BINARY_DIR}/tar_dir/d1/f2.txt\"")
  25. set(CHECK_FILES ${CHECK_FILES} "d1/f2.txt")
  26. endif()
  27. # cleanup first in case there are files left from previous runs
  28. # if the umask is odd on the machine it might create files that
  29. # are not automatically over written. These tests are run
  30. # each time the configure step is run.
  31. file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/test_tar.tar")
  32. file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/test_tgz.tgz")
  33. file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/test_output_tar")
  34. file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/test_output_tgz")
  35. make_directory("${CMAKE_CURRENT_BINARY_DIR}/test_output_tar")
  36. make_directory("${CMAKE_CURRENT_BINARY_DIR}/test_output_tgz")
  37. # Run tests
  38. EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}" "cvf \"${CMAKE_CURRENT_BINARY_DIR}/test_tar.tar\" tar_dir")
  39. EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}" "cvfz \"${CMAKE_CURRENT_BINARY_DIR}/test_tgz.tgz\" tar_dir")
  40. EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}/test_output_tar" "xvf \"${CMAKE_CURRENT_BINARY_DIR}/test_tar.tar\"")
  41. EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}/test_output_tgz" "xvfz \"${CMAKE_CURRENT_BINARY_DIR}/test_tgz.tgz\"")
  42. macro(CHECK_DIR_STRUCTURE DIR)
  43. foreach(file ${CHECK_FILES})
  44. set(sfile "${DIR}/${file}")
  45. set(rfile "${CMAKE_CURRENT_BINARY_DIR}/tar_dir/${file}")
  46. if(NOT EXISTS "${sfile}")
  47. message(SEND_ERROR "Cannot find file ${sfile}")
  48. else()
  49. exec_program("${CMAKE_COMMAND}" ARGS "-E compare_files \"${sfile}\" \"${rfile}\"" RETURN_VALUE ret)
  50. if(${ret})
  51. message(SEND_ERROR "Files \"${sfile}\" \"${rfile}\" are different")
  52. endif()
  53. endif()
  54. endforeach()
  55. endmacro()
  56. CHECK_DIR_STRUCTURE("${CMAKE_CURRENT_BINARY_DIR}/test_output_tar/tar_dir")
  57. add_executable(TarTest TestTarExec.cxx)