Reputation: 1804
To decrease library size, used cmake -E tar "zcvf" "lib.tar.gz" out.lib
in cmake to automatically create .tar.gz
then lib.tar.gz
is moved to folder f
, ie. f/lib.tar.gz
.
However, to use this library in another project, it's needed to extract to specific folder. The command without cmake is clear: tar -xzf f/lib.tar.gz -C target-folder
.
The problem is that, in cmake, how to combine cmake -E tar "xzf" f/lib.tar.gz
with -C
option? Commands such as cmake -E tar "xzf" f/lib.tar.gz -C f/
will result error.
Ideal script would be sth. like
add_custom_target(PrepareLib
COMMAND ${CMAKE_COMMAND} -E tar "xzf" command....
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} ## note, this line must not be modified
)
Tools version: Visual Studio 2017, Windows 10 and CMake 3.17.1.
Upvotes: 0
Views: 2627
Reputation: 452
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar x
"file_to_extract.7z"
WORKING_DIRECTORY "directory_you_want_to_extract_to"
)
If you don't know whether the directory_you_want_to_extract_to exists or not then run this comand before the tar.
execute_process(
COMMAND ${CMAKE_COMMAND} -E make_directory
"directory_you_want_to_extract_to"
)
Upvotes: 0