Reputation: 15756
When I do this:
add_custom_target(
mystuff
COMMAND ${CMAKE_COMMAND} -E tar "cvf" "${CMAKE_CURRENT_BINARY_DIR}/mystuff.zip" --format=zip -- ${CMAKE_CURRENT_SOURCE_DIR}/stuff/
)
against a directory organized like this:
stuff/
file1.txt
file2.txt
file3.txt
The resulting zip file contains:
stuff/
file1.txt
file2.txt
file3.txt
but I want: (no parent directory)
file1.txt
file2.txt
file3.txt
If I were doing this outside of cmake, I would use the -C
argument (change directory)
How to do this with cmake?
Upvotes: 1
Views: 1271
Reputation: 91
You could make the whole thing simpler by removing the nested call to CMake, and calling zip directly:
add_custom_target(
mystuff
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/stuff"
COMMAND zip -r "${CMAKE_CURRENT_BINARY_DIR}/mystuff.zip" .
)
(Note: original didn't work, see comment below) Tell tar to include only the contents of the directory (it will do so recursively, but will leave off the top level).
tar "cvf" "${CMAKE_CURRENT_BINARY_DIR}/mystuff.zip" --format=zip \
-- ${CMAKE_CURRENT_SOURCE_DIR}/stuff/*
Upvotes: 0
Reputation: 1924
You could change the working directory of the tar command, something like this:
add_custom_target(
mystuff
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/stuff"
COMMAND ${CMAKE_COMMAND} -E tar "cvf" "${CMAKE_CURRENT_BINARY_DIR}/mystuff.zip" --format=zip .
)
Upvotes: 1