MantisBT - CMake
View Issue Details
0015962CMakeCMakepublic2016-02-09 15:002016-06-10 14:21
nitroamos 
 
lowminoralways
closedno change required 
Windows8
CMake 3.4.3 
 
0015962: can't unzip jar file on windows
I'd like to use cmake to unpack a .jar file. To do this, I use the following command in my CMakeLists.txt:

execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf ${MY_JAR} --format=zip ${CMAKE_CURRENT_BINARY_DIR}/ )


Which I run through the CMake GUI. This command works as intended on OSX. On Windows, I get the following error when configuring:


COMMAND C:/Program Files (x86)/CMake/bin/cmake.exe -E tar xf my.jar --format=zip build
CMake Error: Problem with archive_write_header(): Can't create '\\?\C:\Program Files (x86)\CMake\META-INF\MANIFEST.MF'

CMake Error: Current file: META-INF/MANIFEST.MF

CMake Error: Problem extracting tar: my.jar

cmake_minimum_required(VERSION 2.8.9)
project(extractjar)

message("COMMAND ${CMAKE_COMMAND} -E tar xf ${CMAKE_SOURCE_DIR}/my.jar --format=zip ${CMAKE_CURRENT_BINARY_DIR}/")
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf ${CMAKE_SOURCE_DIR}/my.jar --format=zip ${CMAKE_CURRENT_BINARY_DIR}/ )
No tags attached.
Issue History
2016-02-09 15:00nitroamosNew Issue
2016-02-09 16:05Brad KingNote Added: 0040452
2016-02-09 16:07Brad KingNote Added: 0040453
2016-02-09 16:25Chuck AtkinsNote Added: 0040454
2016-02-09 16:29Brad KingNote Added: 0040455
2016-02-15 12:57nitroamosNote Added: 0040491
2016-02-16 09:21Brad KingStatusnew => resolved
2016-02-16 09:21Brad KingResolutionopen => no change required
2016-06-10 14:21Kitware RobotNote Added: 0041253
2016-06-10 14:21Kitware RobotStatusresolved => closed

Notes
(0040452)
Brad King   
2016-02-09 16:05   
Your command line appears to assume that the last argument is an output directory. It is not (and is not in POSIX tar command lines either). The current working directory of the process is always the output directory unless the tarball contains absolute paths. Paths listed at the end of the command line specify input files for tar creation and are currently ignored for extraction.

Use `cmake -E chdir ... cmake -E tar xf ...` to set the working directory.
(0040453)
Brad King   
2016-02-09 16:07   
Normally we've used `cmake -E tar` in an add_custom_command. In that case the working directory will be in the build tree when the command is executed by the generated build system.
(0040454)
Chuck Atkins   
2016-02-09 16:25   
You could also try passing the WORKING_DIRECTORY argument to execute_process:

execute_process(
  COMMAND ${CMAKE_COMMAND} -E tar xf ${CMAKE_SOURCE_DIR}/my.jar --format=zip
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

See https://cmake.org/cmake/help/v3.4/command/execute_process.html [^]
(0040455)
Brad King   
2016-02-09 16:29   
Re 0015962:0040454: [smacks forehead] Yes, that is much better than -E chdir.
(0040491)
nitroamos   
2016-02-15 12:57   
I copied the line I used from elsewhere and only checked to see if it was correct by running it (and it worked as expected on OSX). Sorry for the bug report. Adding WORKING_DIRECTORY resolved it.

Thanks!

I don't see a way for me to mark the issue as resolved...
(0041253)
Kitware Robot   
2016-06-10 14:21   
This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.