[CMake] CPack change file extension
Eric Noulard
eric.noulard at gmail.com
Fri Aug 26 14:55:59 EDT 2016
HI all,
package is a builtin target unless things have changed you cannot depend on
a builtin target.
https://gitlab.kitware.com/cmake/cmake/issues/8438
https://cmake.org/Bug/view.php?id=8438
Personnally I would explicitely call CPack in my custom target in order to
be sure that the zip is up-to-date.
e.g.:
# find a way to get path to cpack command in a portable way
get_filename_component(CPACK_COMMAND ${CMAKE_COMMAND} PATH)
set(CPACK_COMMAND ${CPACK_COMMAND}/cpack)
add_custom_target(package_docx
COMMAND $(CPACK_COMMAND} -G ZIP
COMMAND ${CMAKE_COMMAND} -E rename ${CPACK_PACKAGE_FILE_NAME}.zip
${CPACK_PACKAGE_FILE_NAME}.docx
WORKING_DIRECTORY ${CMAKE_BUILD_DIR})
cmake -E rename will work on the same volume, copy will work accross volume.
note that your custom target should run in build dir in order to make cpack
work as expected.
2016-08-26 20:22 GMT+02:00 Kristian <kristianonline28 at gmail.com>:
> > Do you have any special reason why your rename target depends on
> PACKAGE, is this the target which cpack is using?
>
> I think so ...
>
> 2016-08-26 20:01 GMT+02:00 tonka3100 at gmail.com <tonka3100 at gmail.com>:
>
>> Hey Kristian,
>>
>> Thx for your answer. Iv've already done this like in your solution. I
>> have a seperated target which depends on my create zip target and use
>> ${CMAKE_COMMAND} -e copy to copy the file to my target directory (so the
>> solution is platform independent), and leaf the original zip in the binary
>> directory.
>>
>> Do you have any special reason why your rename target depends on PACKAGE,
>> is this the target which cpack is using?
>>
>> Am 26.08.2016 um 19:05 schrieb Kristian <kristianonline28 at gmail.com>:
>>
>> Hey,
>>
>> you're working on Windows, right?
>>
>> I think you can do that if you create an additional target and call that
>> target. So let's say, you have this 'hello.cpp', and you generate with
>> CMake a solution. This is an example of a CMakeLists.txt
>>
>> > cmake_minimum_required(VERSION 3.4)
>> > project(cpack_zip_test)
>>
>> > set(SOURCES hello.cpp)
>>
>> > add_executable(${PROJECT_NAME} ${SOURCES})
>>
>> > set(CPACK_GENERATOR "ZIP")
>> > set(CPACK_PACKAGE_EXECUTABLE ${PROJECT_NAME})
>> > set(CPACK_PACKAGE_FILE_NAME ${PROJECT_NAME}-package)
>>
>> > add_custom_target(rename_zip
>> > COMMAND rename ${CPACK_PACKAGE_FILE_NAME}.zip
>> ${CPACK_PACKAGE_FILE_NAME}.docx
>> > WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
>>
>> > include(CPack)
>>
>> When I call now something like this on the command line (Visual Studio 12
>> 2013)
>>
>> > devenv cpack_zip_test.sln /Rebuild Debug /project PACKAGE.vcxproj
>>
>> and afterwards some like this
>>
>> > devenv cpack_zip_test.sln /Rebuild Debug /project rename_zip.vcxproj
>>
>> then this is some way of renaming your zip into a docx file. But I do not
>> know, if there is a more automatic way to do this. I tried it with an
>> additional parameter in the 'add_custom_target'-command (see at the DEPENDS
>> part):
>>
>> > add_custom_target(rename_zip
>> > COMMAND rename ${CPACK_PACKAGE_FILE_NAME}.zip
>> ${CPACK_PACKAGE_FILE_NAME}.docx
>> > DEPENDS PACKAGE
>> > WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
>>
>> But when I call 'devenv cpack_zip_test.sln /Rebuild Debug /project
>> rename_zip.vcxproj', I would assume, that first the PACKAGE target is
>> called, and afterwards the 'rename_zip' target is called. But that's not
>> the case. Maybe some other person can tell me, if this is a bug or this is
>> intention...
>>
>> 2016-08-24 21:53 GMT+02:00 tonka3100 at gmail.com <tonka3100 at gmail.com>:
>>
>>> Hey everybody,
>>>
>>> I try to rename the fileextension of my cpack zip file. So i use cpack
>>> -G ZIP to create the package and get my zip file. Now i need to rename
>>> these fileextension to another name, like microsoft did it with with docx
>>> word format, where the file is a zip file, but has the docx extension.
>>>
>>> Does anybody know how i can do that?
>>>
>>> Greetings
>>> Tonka
>>> --
>>>
>>> Powered by www.kitware.com
>>>
>>> Please keep messages on-topic and check the CMake FAQ at:
>>> http://www.cmake.org/Wiki/CMake_FAQ
>>>
>>> Kitware offers various services to support the CMake community. For more
>>> information on each offering, please visit:
>>>
>>> CMake Support: http://cmake.org/cmake/help/support.html
>>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://public.kitware.com/mailman/listinfo/cmake
>>>
>>
>>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
--
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160826/c8c6ab18/attachment.html>
More information about the CMake
mailing list