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