[CMake] How can I unzip a file?

Michael Wild themiwi at gmail.com
Mon Jul 6 07:32:50 EDT 2009


That depends on when you want to run the extraction. At CMake-time or  
build-time? If the former, you can use:

execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xzf path/to/file.tar.gz
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/path/to/where/you/want/to/unpack
)

There are many more options for the execute_process command, so you  
might want to have a look at its documentation.

If you want to run it at build-time:

# list of files in the tar archive
set( TAR_SRCS file1.c file2.c file3.c )
set( TAR_HDRS file1.h file2.h file3.h )

# add a custom command to unpack the tar. specify the "output" files,
# such that CMake knows that they are "generated" and how to "create"  
them
# (i.e. set up the dependencies)
add_custom_command(
OUTPUT ${TAR_SRCS} ${TAR_HDRS}
COMMAND ${CMAKE_COMMAND} -E tar xzf path/to/file.tar.gz
DEPENDS path/to/file.tar.gz
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/path/to/where/you/want/to/unpack
COMMENT "Unpacking path/to/file.tar.gz"
VERBATIM
)

# for example create a library using those sources
add_library( superThing ${TAR_SRCS} ${TAR_HDRS} )


Again, there are more, possibly useful options to add_custom_command...

HTH

Michael



On 6. Jul, 2009, at 12:10, Peter wrote:

> I could probably live with .gz files.
> What would I have to type inside the CMakeLists.txt file to expand  
> the archive?
>
> Am 03.07.2009 20:07, schrieb David Cole:
>> cmake -E tar
>>
>> can untar .tar files and .tar.gz files... But you have to use an  
>> external tool for .zip files.
>>
>> We are considering adding libarchive support to be able to handle  
>> more zip formats, but it has not been tackled yet. (See http://code.google.com/p/libarchive/ 
>>  for more info.)
>>
>>
>> HTH,
>> David
>>
>>
>> On Fri, Jul 3, 2009 at 1:44 PM, Peter <p.schregle at impuls- 
>> imaging.com <mailto:p.schregle at impuls-imaging.com>> wrote:
>>
>>  I can't figure out how I can unzip a set of files with CMake.
>>
>>  I have a bunch of files in a zip archive, which need to be
>>  expanded during the build process and I would like to know how
>>  this can be done in a portable way with CMake?
>>
>>  Thanks.
>>  Peter
>>
>>  _______________________________________________
>>  Powered by www.kitware.com <http://www.kitware.com>
>>
>>  Visit other Kitware open-source projects at
>>  http://www.kitware.com/opensource/opensource.html
>>
>>  Please keep messages on-topic and check the CMake FAQ at:
>>  http://www.cmake.org/Wiki/CMake_FAQ
>>
>>  Follow this link to subscribe/unsubscribe:
>>  http://www.cmake.org/mailman/listinfo/cmake
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 194 bytes
Desc: This is a digitally signed message part
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090706/e3915873/attachment.pgp>


More information about the CMake mailing list