0

I am using the following cmake command to extract a zip file

 ${CMAKE_COMMAND} -E tar xkf 

This unzip the file as it is.

I'd like to AVOID unzipping when the file has been already unzipped. How can I do that? It seems that there is no option for that purpose.

Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
  • Test for a file or a directory that comes from the archive. If it exists, skip your `tar` command. – nega Apr 30 '18 at 16:57

1 Answers1

0

Add an dependency.

The result of the unzip operation has to be used within a later build step. Add the dependency between the unzip and that build step.

  1. Use add_custom_command to unzip files and copy them to the expected folder
  2. Extend your target by a dependency to the extracted files

The following example shows this for the target TTNLIB.

Example:

add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/src/ttnbitvector.cpp
COMMAND ${CMAKE_COMMAND} -E tar xkf ${CMAKE_SOURCE_DIR}/external/ttnbitvector.cpp.zip -C ${CMAKE_SOURCE_DIR}/external
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/external/ttnbitvector.cpp ${CMAKE_SOURCE_DIR}/src/ttnbitvector.cpp
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/external
COMMENT Extract ${CMAKE_SOURCE_DIR}/src/ttnbitvector.cpp
)

add_library(TTNLIB SHARED ${SOURCES} ${CMAKE_SOURCE_DIR}/src/ttnbitvector.cpp)

Note: Read the documentation of add_custom_command

See cmake solutions for further information.

Th. Thielemann
  • 2,592
  • 1
  • 23
  • 38