CMakeLists.txt 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. PROJECT(TestTar)
  2. # this is macro that we will be running
  3. MACRO(EXEC_TAR_COMMAND DIR ARGS)
  4. EXEC_PROGRAM("${CMAKE_COMMAND}" "${DIR}" ARGS "-E tar ${ARGS}" RETURN_VALUE RET)
  5. IF(${RET})
  6. MESSAGE(FATAL_ERROR "CMake tar command failed with arguments \"${ARGS}\"")
  7. ENDIF(${RET})
  8. ENDMACRO(EXEC_TAR_COMMAND)
  9. # Create a directory structure
  10. SET(CHECK_FILES)
  11. MACRO(COPY F1 F2)
  12. CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/${F1}" "${CMAKE_CURRENT_BINARY_DIR}/tar_dir/${F2}" COPYONLY)
  13. SET(CHECK_FILES ${CHECK_FILES} "${F2}")
  14. ENDMACRO(COPY)
  15. COPY("CMakeLists.txt" "f1.txt")
  16. COPY("CMakeLists.txt" "d1/f1.txt")
  17. COPY("CMakeLists.txt" "d 2/f1.txt")
  18. COPY("CMakeLists.txt" "d + 3/f1.txt")
  19. COPY("CMakeLists.txt" "d_4/f1.txt")
  20. COPY("CMakeLists.txt" "d-4/f1.txt")
  21. COPY("CMakeLists.txt" "My Special Directory/f1.txt")
  22. IF(UNIX)
  23. EXEC_PROGRAM("ln" ARGS "-sf f1.txt \"${CMAKE_CURRENT_BINARY_DIR}/tar_dir/d1/f2.txt\"")
  24. SET(CHECK_FILES ${CHECK_FILES} "d1/f2.txt")
  25. ENDIF(UNIX)
  26. MAKE_DIRECTORY("${CMAKE_CURRENT_BINARY_DIR}/test_output_tar")
  27. MAKE_DIRECTORY("${CMAKE_CURRENT_BINARY_DIR}/test_output_tgz")
  28. # Run tests
  29. EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}" "cvf \"${CMAKE_CURRENT_BINARY_DIR}/test_tar.tar\" tar_dir")
  30. EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}" "cvfz \"${CMAKE_CURRENT_BINARY_DIR}/test_tgz.tgz\" tar_dir")
  31. EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}/test_output_tar" "xvf \"${CMAKE_CURRENT_BINARY_DIR}/test_tar.tar\"")
  32. EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}/test_output_tgz" "xvfz \"${CMAKE_CURRENT_BINARY_DIR}/test_tgz.tgz\"")
  33. MACRO(CHECK_DIR_STRUCTURE DIR)
  34. FOREACH(file ${CHECK_FILES})
  35. SET(sfile "${DIR}/${file}")
  36. SET(rfile "${CMAKE_CURRENT_BINARY_DIR}/tar_dir/${file}")
  37. IF(NOT EXISTS "${sfile}")
  38. MESSAGE(SEND_ERROR "Cannot find file ${sfile}")
  39. ELSE(NOT EXISTS "${sfile}")
  40. EXEC_PROGRAM("${CMAKE_COMMAND}" ARGS "-E compare_files \"${sfile}\" \"${rfile}\"" RETURN_VALUE ret)
  41. IF(${ret})
  42. MESSAGE(SEND_ERROR "Files \"${sfile}\" \"${rfile}\" are different")
  43. ENDIF(${ret})
  44. ENDIF(NOT EXISTS "${sfile}")
  45. ENDFOREACH(file)
  46. ENDMACRO(CHECK_DIR_STRUCTURE)
  47. CHECK_DIR_STRUCTURE("${CMAKE_CURRENT_BINARY_DIR}/test_output_tar/tar_dir")
  48. ADD_EXECUTABLE(TestTarExec TestTarExec.cxx)